Notification using setFullScreenIntent() for BigTextStyle opening Activity automatically

别来无恙 提交于 2019-12-23 06:15:10

问题


I have a very strange issue, I am working on Push Notification and it was successfully implemented but when i have used BigTextStyle in Notification to show a long message in notification area with setFullScreenIntent() method then the issue coming up the Notification opening the Activity automatically which is set in PendingIntent.

If I don't use setFullScreenIntent() then notification won't opening Activity automatically the user has to tap or click on Notification to open the Activity set in PendingIntent.

So there are two codes

  1. Without setFullScreenIntent() working fine and not opening Activity automatically:

    notification = new NotificationCompat.Builder(context)
                            .setContentTitle("Title")
                            .setContentIntent(resultPendingIntent)
                            .setContentText(message)
                            .setStyle(
                                    new NotificationCompat.BigTextStyle()
                                            .bigText(message))
                            .setSmallIcon(R.drawable.ic_launcher)
                            .setAutoCancel(true);
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                manager.notify(1, notification.build());
    
  2. With setFullScreenIntent() also working fine but opening Activity automatically:-

    notification = new NotificationCompat.Builder(context)
                            .setContentTitle("Title")
                            .setContentIntent(resultPendingIntent)
                            .setContentText(message)
                            .setStyle(
                                    new NotificationCompat.BigTextStyle()
                                            .bigText(message))
                            .setSmallIcon(R.drawable.ic_launcher)
                            .setFullScreenIntent(resultPendingIntent, true) //Whether true or false same result
                            .setAutoCancel(true);
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                manager.notify(1, notification.build());
    

回答1:


public NotificationCompat.Builder setFullScreenIntent (PendingIntent intent, boolean highPriority)

An intent to launch instead of posting the notification to the status bar. Only for use with extremely high-priority notifications demanding the user's immediate attention, such as an incoming phone call or alarm clock that the user has explicitly set to a particular time. If this facility is used for something else, please give the user an option to turn it off and use a normal notification, as this can be extremely disruptive.

On some platforms, the system UI may choose to display a heads-up notification, instead of launching this intent, while the user is using the device.

Parameters

intent: The pending intent to launch.

highPriority: Passing true will cause this notification to be sent even if other notifications are suppressed.

Found here. As you can see it immediately launches the intent. I don't really know in what case you wanted to use setFullScreenIntent()?

A notification won't automatically expand when a static notification is displayed on top (could be custom bar with wifi, bluetooth and sound control)




回答2:


pass setFullScreenIntent and setContentIntent with different pending intents.

Worked for me. click on Notif will work and autolaunch will stop



来源:https://stackoverflow.com/questions/30659594/notification-using-setfullscreenintent-for-bigtextstyle-opening-activity-autom

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