【发布时间】:2016-04-27 13:48:28
【问题描述】:
当点击推送通知时,我正在尝试启动一项活动。 有趣的是,当应用程序关闭且后台没有活动时,我收到推送,我单击它并打开所需的活动。 但是当应用程序的任何活动被打开并且我收到推送时,点击它什么都不做。 我尝试过差异组合。还要将exported = true 放在启动活动中。
这是我的代码:
private static void showNotification(Context context,String title,String text,Intent openIntent)
{
PendingIntent pi = PendingIntent.getActivity(context, 0, openIntent, PendingIntent.FLAG_CANCEL_CURRENT|PendingIntent.FLAG_ONE_SHOT);
// Resources r = getResources();
final Notification notification = new NotificationCompat.Builder(context)
.setTicker(title)
.setSmallIcon(R.drawable.notif_icon)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
R.drawable.notif_icon))
.setContentTitle(title)
.setContentText(text)
.setContentIntent(pi)
.setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_LIGHTS|Notification.DEFAULT_VIBRATE)
.setAutoCancel(false)
.build();
// also tried .setAutoCancel(true) above instead of cancel
notification.flags |= Notification.FLAG_AUTO_CANCEL;
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
notificationManager.notify(0, notification);
}
},1000);
}
现在,我应该尝试什么组合?删除标志 CANCEL_CURRENT 或 FLAG_ONE_SHOT ?已经试过了。即使没有这两个标志,点击通知也没有结果。
我在 android 5.1 / 5.0 上运行该应用程序。我已经读到这些 android 版本的通知存在问题。所以我已经尝试过像 android:exported=true 和 FLAG_CANCEL current 这样的解决方案。但没有效果。
现在如何使通知点击工作并打开预期的活动?
感谢任何帮助。 谢谢
【问题讨论】:
标签: android notifications push-notification android-5.0-lollipop android-5.1.1-lollipop