Android 屏幕锁定时挂起的内容don´;t启动所需的活动

Android 屏幕锁定时挂起的内容don´;t启动所需的活动,android,android-notifications,android-pendingintent,Android,Android Notifications,Android Pendingintent,我遵循了和 当设备处于唤醒状态时,一切工作正常,通知声音、振动和所需的活动按预期工作,但当设备锁定时,所有这些都无法正常工作 即使应用程序处于打开状态或处于后台,通知也会打开主活动,而不是所需的活动。 这是我的密码: JSONObject request=messageContent.getJSONObject("request"); intent = new Intent(getApplicationContext(), NewRequest.class); intent.addFlags(I

我遵循了和
当设备处于唤醒状态时,一切工作正常,通知声音、振动和所需的活动按预期工作,但当设备锁定时,所有这些都无法正常工作

即使应用程序处于打开状态或处于后台,通知也会打开主活动,而不是所需的活动。 这是我的密码:

JSONObject request=messageContent.getJSONObject("request");
intent = new Intent(getApplicationContext(), NewRequest.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
intent.putExtra(NewRequest.REQUEST, String.valueOf(request));

Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);


PendingIntent pendingIntent = PendingIntent.getActivity(this, id, intent,
       PendingIntent.FLAG_UPDATE_CURRENT);

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.mipmap.ic_launcher)
        .setContentText(body)
        .setContentTitle(title)
        .setAutoCancel(true)
        .setColor(ContextCompat.getColor(this, R.color.colorPrimary))
        .setVibrate(new long[] { 1000, 1000 })
        .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
        .setSound(defaultSoundUri)
        .setContentIntent(pendingIntent);

Notification notification = notificationBuilder.build();
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_SOUND;

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

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "My Tag");
wl.acquire(10000);

notificationManager.notify(id, notification);
还试图为挂起的意图保留导航流,但结果是一样的

TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(NewRequest.class);
stackBuilder.addNextIntent(intent);

PendingIntent pendingIntent =
        stackBuilder.getPendingIntent(id, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
我不知道为什么只有在屏幕未锁定的情况下才起作用