奇怪的Android通知行为

时间:2014-12-01 02:39:16

标签: android push-notification google-cloud-messaging

我使用以下代码发送GCM通知:

private void sendNotification2(Bundle extras) {
    mNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent intent = new Intent(this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    Bundle bundle = new Bundle();
    bundle.putString("buzz", "buzz");
    intent.putExtras(bundle);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            intent, 0);

    String appname = extras.getString("appname");
    String contenttxt = extras.getString("alert");
    String title = extras.getString("title");
    Logger.append("Notification Intent", extras.toString());

    try {
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this)
                .setSmallIcon(R.drawable.myicon)
                .setLargeIcon(
                        BitmapFactory.decodeResource(getResources(),
                                R.drawable.splash))
                .setContentTitle(title)
                .setDefaults(Notification.DEFAULT_ALL)
                .setOnlyAlertOnce(true)
                .setAutoCancel(true)
                .setStyle(
                        new NotificationCompat.BigTextStyle()
                                .bigText(title)).setContentText(contenttxt);

        mBuilder.setContentIntent(contentIntent);

        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    } catch (Exception ex) {
        Logger.append("Invalid Notificatoin msg", "");
    }
}

以下是我面临的问题。

当我收到通知时,如果我点击它,在Kitkat 4.4.4的Note 4上,该应用程序打开正常。但是在使用Kitkat 4.4.2的LG Optimus上,该应用程序无法打开。

关于要查找什么,调试的任何指针?

1 个答案:

答案 0 :(得分:0)

好的,这似乎是Stackoverflow中每个其他线程的已知Kitkat问题。

Notification Click not launch the given Activity on Nexus Phones

添加如下两个标志解决了这个问题。

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
         intent, PendingIntent.FLAG_UPDATE_CURRENT  | PendingIntent.FLAG_ONE_SHOT);