单击Android中的第二个推送通知时无功能

时间:2016-03-18 10:28:48

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

我在下面的推送通知方面遇到了一些问题。 当我收到2推送通知。我点击一个推送通知,它运作良好(转到ActivityA) 但我点击休息推,我看到只是关闭第二次推,但没有功能。 这是我的代码:

Intent intent = new Intent();
    intent.setClass(getApplicationContext(), ActivityA.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
    long[] vibrate = {1000, 1000, 1000, 1000, 1000};
    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_push_notification)
            .setContentTitle(this.getString(R.string.app_name))
            .setContentText(alert)
            .setAutoCancel(true)
            .setVibrate(vibrate)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
    Log.i("gcm","gcm alert = " + alert);

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
    contentView.setImageViewResource(R.id.imagePush,R.drawable.ic_push_notification);
    contentView.setTextViewText(R.id.titlePush, this.getString(R.string.app_name));
    contentView.setTextViewText(R.id.textPush, alert);

    notificationBuilder.setContent(contentView);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(commentId, notificationBuilder.build());

如果您有任何想法可以解决此问题,请与我分享。

非常感谢

0 个答案:

没有答案