FullScreenIntent only appears if I clear the notification

泄露秘密 提交于 2021-01-28 21:42:43

问题


I'm trying to launch a FullScreenIntent from a service working in the background, but I realised that the intent would not be shown another time if I do not clear the notification from the task bar. I have tried removing the notification by removing

.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Notification")
.setContentText("A client is calling")

but that just removes my option of clearing the notification. Can somebody help?

My code is as shown:

                    NotificationCompat.Builder mBuilder =
                            new NotificationCompat.Builder(this)
                                    .setSmallIcon(R.drawable.ic_launcher)
                                    .setContentTitle("Notification")
                                    .setContentText("A client is calling")
                                    .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                                    .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
                                    .setAutoCancel(true);
                    Intent resultIntent = new Intent(this, MainActivity.class);
                    String strName = ((String) message).substring(9);
                    resultIntent.putExtra("Msg",strName);
    // Because clicking the notification opens a new ("special") activity, there's
    // no need to create an artificial back stack.
                    PendingIntent resultPendingIntent =
                            PendingIntent.getActivity(
                                    this,
                                    0,
                                    resultIntent,
                                    PendingIntent.FLAG_CANCEL_CURRENT
                            );

                    mBuilder.setFullScreenIntent(resultPendingIntent,true);
                    int mNotificationId = 001;
    // Gets an instance of the NotificationManager service
                    NotificationManager mNotifyMgr =
                            (NotificationManager)this.getSystemService(this.NOTIFICATION_SERVICE);
    // Builds the notification and issues it.
                    Notification m = mBuilder.build();
                    m.flags = Notification.FLAG_AUTO_CANCEL;
                    mNotifyMgr.notify(mNotificationId, m);

来源:https://stackoverflow.com/questions/30499577/fullscreenintent-only-appears-if-i-clear-the-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!