【发布时间】:2015-06-05 06:18:43
【问题描述】:
我有一个非常奇怪的问题,我正在处理推送通知并且它已成功实现,但是当我在通知中使用 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());
【问题讨论】:
标签: android push-notification android-notifications