通过刷卡/取消通知开始Android活动。

时间:2016-10-18 19:29:04

标签: android android-notifications android-pendingintent

在取消或滑动通知时,它会启动活动。如何解决这个问题? Intent resultIntent = new Intent(this,SmsThreadActivity.class);

        resultIntent.putExtra("address", address);
        resultIntent.putExtra("thread_id", threadId);
        resultIntent.putExtra("msg_type", msgType);

        Intent backIntent = new Intent(this, MainActivity.class);
        backIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

        PendingIntent pendingIntent = PendingIntent.getActivities(this,
                0, new Intent[] {backIntent, resultIntent}, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setSmallIcon(R.mipmap.ic_app_icon_9);
        builder.setContentIntent(pendingIntent);
        builder.setDeleteIntent(pendingIntent);
        builder.setContentTitle(contactName);
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(body));
        builder.setContentText(body);
        if (PreferencesUtil.Notification.getStatus(this, Constants.NotificationSettings.SOUND)) {
            builder.setSound(uri);
        }
        builder.setVibrate(vibratePattern);
        builder.setPriority(2);
        builder.setAutoCancel(true);

        NotificationManager manager =
                (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

        manager.notify(id, builder.build());

1 个答案:

答案 0 :(得分:0)

builder.setDeleteIntent(pendingIntent);

此行告知在解除通知时启动 pendingIntent