[英]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. 这里是我的监听器的代码,我可以确认它正在运行,但是当我把断点onCreate
和onNewIntent
方法在我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.