【问题标题】:PendingIntent not always launching in androidPendingIntent 并不总是在 android 中启动
【发布时间】:2012-08-18 08:29:12
【问题描述】:

收到 GCM 推送通知消息后,我正在创建通知。这一切都完成了。但是当我点击通知时,有时它没有启动(PendingIntent)。大多数情况下,当我收到通知后立即单击时,问题就出现了。待定意图实际上是我的第一个登录页面本身。这是源代码。。

public void createNotification(Context context, String message) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.icon,
            "My notification", System.currentTimeMillis());
    // Hide the notification after its selected
    notification.flags |= Notification.FLAG_AUTO_CANCEL ;
    Intent intent;


    intent = new Intent(context, Login.class);
    intent.putExtra("pushNoti", "pushNoti");
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);


    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
            intent, PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setLatestEventInfo(context, "my Alert",
            message, pendingIntent);

    notification.defaults = Notification.DEFAULT_SOUND;
    notificationManager.notify(0, notification);

}

这里的上下文来自 GCM onMessage(Context context, Intent intent)..

谁能帮帮我?

【问题讨论】:

  • 当我这样做时,我的应用程序也在后台..

标签: android push-notification


【解决方案1】:
notificationManager.notify(0, notification);

来自文档:

public void notify(int id, Notification notification)

自:API 级别 1 发布要在状态栏中显示的通知。如果您的应用程序已经发布了具有相同 id 的通知并且尚未取消,则它将被更新的信息替换。

参数

id:此通知的标识符在您的应用程序中是唯一的。

notification:一个 Notification 对象,描述向用户展示的内容。不能为空。

尝试使用对您应用中的每个通知唯一的标识符,而不是 0。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-15
    • 1970-01-01
    • 2011-11-22
    • 1970-01-01
    • 2015-05-26
    • 1970-01-01
    • 2017-06-04
    • 1970-01-01
    相关资源
    最近更新 更多