使用 setFullScreenIntent() 通知 BigTextStyle 自动打开 Activity
Notification using setFullScreenIntent() for BigTextStyle opening Activity automatically
我有一个非常奇怪的问题,我正在处理推送通知并且它已成功实施但是当我在 Notification 中使用 BigTextStyle 通过 setFullScreenIntent() 方法在通知区域显示一条长消息时,问题出现了在 PendingIntent.
中设置的自动打开 Activity 的通知
如果我不使用 setFullScreenIntent(),则通知不会自动打开 Activity 用户必须点击或单击通知才能打开在 PendingIntent 中设置的 Activity。
所以有两个代码
没有 setFullScreenIntent() 工作正常并且不会自动打开 Activity:
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());
使用 setFullScreenIntent() 也能正常工作但会自动打开 Activity:-
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.
找到 here。如您所见,它会立即启动意图。我真的不知道你想在什么情况下使用 setFullScreenIntent()
?
当静态通知显示在顶部时,通知不会自动展开(可以是带有 wifi、蓝牙和声音控制的自定义栏)
使用不同的待定意图传递 setFullScreenIntent 和 setContentIntent。
对我有用。单击 Notif 将起作用,自动启动将停止
我有一个非常奇怪的问题,我正在处理推送通知并且它已成功实施但是当我在 Notification 中使用 BigTextStyle 通过 setFullScreenIntent() 方法在通知区域显示一条长消息时,问题出现了在 PendingIntent.
中设置的自动打开 Activity 的通知如果我不使用 setFullScreenIntent(),则通知不会自动打开 Activity 用户必须点击或单击通知才能打开在 PendingIntent 中设置的 Activity。
所以有两个代码
没有 setFullScreenIntent() 工作正常并且不会自动打开 Activity:
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());
使用 setFullScreenIntent() 也能正常工作但会自动打开 Activity:-
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.
找到 here。如您所见,它会立即启动意图。我真的不知道你想在什么情况下使用 setFullScreenIntent()
?
当静态通知显示在顶部时,通知不会自动展开(可以是带有 wifi、蓝牙和声音控制的自定义栏)
使用不同的待定意图传递 setFullScreenIntent 和 setContentIntent。
对我有用。单击 Notif 将起作用,自动启动将停止