【发布时间】:2016-10-01 07:41:30
【问题描述】:
在我的应用程序中,我正在使用推送通知。它工作正常。但是当我从任务管理器中删除(清理)应用程序时。推送通知没有到达。我不知道是什么问题。如果有人知道我该如何解决。请告诉我。
这是我发送通知的方法:-
private void sendNotification(String msg) {
mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Log.e("message.....", msg);
if (msg.equals("You Have got New Message")) {
Log.e("msg occuring..", "intent enter in message...");
intent.putExtra("KEYMESSAGE", "Message");
} else {
Log.e("notification occuring..", "notification occurs.....");
intent.putExtra("KEYNOTIFICATION", "aman");
}
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(getNotificationIcon())
.setContentTitle("Telepoh")
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setContentText(msg)
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE);
mBuilder.setContentIntent(contentIntent);
mBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
mBuilder.getNotification().flags |= Notification.FLAG_ONGOING_EVENT;
mBuilder.setOngoing(false);
mBuilder.setAutoCancel(true);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
我的问题是当应用程序处于运行状态时,通知会正常发出。但是当应用程序从任务管理器中删除(清理)时,通知没有到达。如果有人知道是什么问题,请告诉我。
【问题讨论】:
-
你是通过广播接收消息吗
-
@MujammilAhamed 是的!但是当应用程序处于运行状态或后台状态时。但是当我从任务管理器中清理应用程序时,通知没有到达。
-
@AL。我没有得到任何你建议链接的答案。这就是我问的原因。
-
@aarav 好的。但是是什么让你的帖子不重复?从我看到的地方来看,上下文是相同的。
标签: android push-notification google-cloud-messaging android-pendingintent