Android点击通知不会打开附加的活动

Android点击通知不会打开附加的活动,android,android-activity,push-notification,android-pendingintent,Android,Android Activity,Push Notification,Android Pendingintent,我想在单击状态栏中的通知时打开一个活动。我在StackOverflow上看到了答案,但这些答案都不适用于我。 此问题仅在棒棒糖设备上出现,最好的复制方法是: 1.启动应用程序。 2.回到地面的应用程序。 3.接收推送通知。 4.单击通知并尝试使用3-4个推送通知 下面是我的代码:我还尝试了以下方法: 添加Intent.ACTION\u MAIN Intent.CATEGORY_启动器到Intent PendingEvent.FLAG_更新_当前 android:exported=“true”在m

我想在单击状态栏中的通知时打开一个活动。我在StackOverflow上看到了答案,但这些答案都不适用于我。 此问题仅在棒棒糖设备上出现,最好的复制方法是: 1.启动应用程序。 2.回到地面的应用程序。 3.接收推送通知。 4.单击通知并尝试使用3-4个推送通知

下面是我的代码:我还尝试了以下方法:

  • 添加Intent.ACTION\u MAIN
  • Intent.CATEGORY_启动器到Intent
  • PendingEvent.FLAG_更新_当前
  • android:exported=“true”在my AndroidManifest.xml中
  • 但什么都不管用。我只在棒棒糖设备上看到这个问题。 请注意,我偶尔会看到这个问题。这是否与缓存而不是交付的意图有关。请帮忙

    PendingIntent pendingIntent = getPendingIntent(context, payload);
    Builder notificationBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.ic_stat)
                .setContentTitle(res.getString(R.string.app_name))
                .setContentText(payload.getMessage())
                .setTicker(payload.getMessage())
                .setContentIntent(pendingIntent)
                .setSound(soundUri);
    
    private PendingIntent getPendingIntent(Context context, NotificationPayload payload) {
        int requestID = (int) System.currentTimeMillis();
        Intent intent = new Intent(context, DeepLinkActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setPackage(BuildConfig.APPLICATION_ID);
        intent.putExtra(NotificationHelper.KEY_NOTIFICATION_PAYLOAD, payload);
        return PendingIntent.getActivity(context, requestID, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
    }
    

    您是否在notification setContentIntent方法中设置了挂起的意图

    试试这个,它适用于所有api版本

            Intent intent = new Intent(this, TestActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
    
        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.logo)
                    .setContentTitle(getResources().getString(R.string.notification_title))
                    .setContentIntent(pendingIntent);
    
      NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
      notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
    

    尝试将Intent.FLAG\活动\清除\任务标志添加到Intent中

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    

    这似乎解决了我的问题

    您是否已将PendingEvent设置为通知生成器?我也有同样的问题。。到目前为止运气都不好我在kitkat上测试过,效果很好。我只在棒棒糖设备上看到这个问题@androholic在棒棒糖上对你有用吗?我编辑了我的答案,加入了我刚刚在棒棒糖上测试的代码,效果很好。另外,删除requestId。在挂起的意图本身中,用0值代替requestId就足够了。请尝试上面的代码。我正在使用ParsePushBroadcastReceiver。我发布的所有代码都发生在接收方的重写getNotification方法中,该方法的返回类型为Notification。我找不到调用notificationManager.notify()的方法。听起来可能很傻,但请帮助我如何使用NotificationManager进行此设置。您有两个选项:1。在getNotification()方法中返回notificationBuilder.build(),并根据需要使用通知。2.使用上面的代码,在getnotification()方法中使用notification manager显示通知,并返回null。这对我不适用。您是否也为AndroidManifest.xml中的活动设置了export=“true”?