简体   繁体   中英

Notification using setFullScreenIntent() for BigTextStyle opening Activity automatically

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()); 

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)

pass setFullScreenIntent and setContentIntent with different pending intents.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM