简体   繁体   English

单击通知时,应用程序不启动或调用onNewIntent

[英]Application not launching or calling onNewIntent when notification clicked

I'm successfully sending notifications using GCM, but when I click on them, nothing happens. 我使用GCM成功发送通知,但是当我点击它们时,没有任何反应。 Here is the code in my listener, I can verify that it is executing, but when I put breakpoints on the onCreate and onNewIntent methods in my HomeActivity they are never hit. 这里是我的监听器的代码,我可以确认它正在运行,但是当我把断点onCreateonNewIntent方法在我HomeActivity他们从来没有击中。 In addition, if that application is not running, I still receive the notification, but the application is not launched. 此外,如果该应用程序未运行,我仍然会收到通知,但该应用程序未启动。 I have tried suggestions from here and here as well as several different combinations of Intent flags. 我已尝试过此处此处的建议以及Intent标志的几种不同组合。 Am I missing something? 我错过了什么吗? Please ask if you need me to post more code. 请问您是否需要我发布更多代码。

Code from my GcmListenerService 来自我的GcmListenerService代码

    notificationBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(getString(appNameID))
            .setContentText(payload)
            .setSmallIcon(iconID)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), bigIconID));

    Intent resultIntent = new Intent(this, HomeActivity.class);
    resultIntent.putExtra(HomeActivity.NOTIFICATION_ID_KEY, notificationID);
    resultIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
    resultIntent.setAction(HomeActivity.NOTIFICATION_ACTION);
    PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    notificationBuilder.setContentIntent(resultPendingIntent);

    // Set Vibrate, Sound and Light
    int defaults = 0;
    defaults = defaults | Notification.DEFAULT_LIGHTS;
    defaults = defaults | Notification.DEFAULT_VIBRATE;
    defaults = defaults | Notification.DEFAULT_SOUND;
    notificationBuilder.setDefaults(defaults);
    notificationBuilder.setAutoCancel(true);


    // Post a notification
    notificationManager.notify(NOTIFY_ID, notificationBuilder.build());

have you added android:launchMode="singleTop" in your manifest. 你在清单中添加了android:launchMode =“singleTop”吗 and also add intent.FLAG_ACTIVITY_SINGLE_TOP 并添加intent.FLAG_ACTIVITY_SINGLE_TOP

UPDATED 更新

Aadd android:exported="true" to your manifest, That might solve your problem. Aadd android:exported =“true”到您的清单,这可能会解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从通知中调用onNewIntent() - Calling onNewIntent() from a notification 从锁定屏幕点击通知时不会调用 OnNewIntent。 当通知点击锁屏时,意图未通过 - OnNewIntent not called when notification is hit from lock screen. And intent not passed when notification clicked on lockscreen Xamarin- MainActivity.OnNewIntent 在单击时应用程序处于后台时使用错误的参数调用推送通知 - Xamarin- MainActivity.OnNewIntent called with wrong parameters for Push Notification when App is in Background when Clicked 单击通知时打开应用程序 - Open application when notification is clicked NFC标签检测未调用onNewIntent,而是从主活动启动 - NFC tag detection is not calling onNewIntent and it's Launching From Main Activity 单击状态栏上的通知图标时是否启动活动? - Launching an activity when a notification icon is clicked on the status bar? 单击通知时启动/继续应用程序 - Start/Resume application when a notification is clicked 当我单击默认Firebase通知Android 6.0.1时,应用程序未启动 - Application is not launching when i click on default firebase notification, Android 6.0.1 当我单击状态栏中的通知时,应用程序未启动 - When I click on notification in status bar, application is not launching 当应用程序被终止时从通知启动活动时,应用程序退出 - App exits while launching activity from notification when application is killed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM