关于通知管理器,我没有显示原始通知存在问题

时间:2019-05-23 21:15:42

标签: java android notifications

我正在开发一个音乐播放器应用,它正在显示播放通知。此应用程序还支持将图像上传到服务器,并且我想在上传时也显示该通知,但该通知未显示,而是显示我的应用程序正在运行,第二行是“触摸”以获取更多信息或停止该应用程序。 / p>

我试图通过notify并启动前台来实现通知,但是没有任何作用

这是通知代码

Notification notification;
NotificationManager notificationManager;
NotificationCompat.Builder notificationBuilder;

notificationManager =(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

        String NOTIFICATION_CHANNEL_ID = "channelza";
        String channelName = "zplay";
        if (Build.VERSION.SDK_INT >= 26) {
            int importance = NotificationManager.IMPORTANCE_LOW;
            NotificationChannel mChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, importance);
            mChannel.setLightColor(Color.BLUE);
            mChannel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
            assert notificationManager != null;
            notificationManager.createNotificationChannel(mChannel);
        }
        notificationBuilder= new NotificationCompat.Builder(getApplicationContext(),NOTIFICATION_CHANNEL_ID);
        notification=notificationBuilder.setOngoing(true)
                .setContentTitle("Uploading")
                .setCategory(Notification.CATEGORY_SERVICE)
                .setProgress(100, 0, false)
                .build();
        assert notificationManager != null;

        startForeground(2,notification);

0 个答案:

没有答案