【问题标题】:Push notification is not coming when the app clean(remove) from the task manager ?当应用程序从任务管理器中清理(删除)时,推送通知不会到来?
【发布时间】: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


【解决方案1】:

将此行替换为

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);

这个

intent.addFlags(FLAG_INCLUDE_STOPPED_PACKAGES|Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);

已编辑:

根据 Android 指南,一旦应用程序被强制关闭,所有服务、接收器和警报都会被销毁,因此在这种情况下您将不会收到任何通知

【讨论】:

  • 不!这是行不通的。当应用程序从任务管理器中清除时。
  • 请告诉我问题出在哪里?当应用程序处于运行状态或后台状态时,我会收到通知。但是当应用程序从任务管理器中清理时,我没有收到通知。
  • @Mohit Trivedi 根据您编辑的答案。当应用程序从任务管理器中终止时,没有机会收到通知。那么whatsapp 怎么能工作。在whatsapp中,当我们从任务管理器中清理应用程序时,通知将会到来。
  • 哦,亲爱的刚刚检查过,如果您在设置中强制停止 whatsup 应用程序,whatsup 甚至不会显示任何通知 -> 应用程序
  • 我不是在谈论强制停止。我 jss 说应用程序从选项卡管理器滑动。当我滑动应用程序并进入设置时:>> 应用程序不会强制停止。强制停止按钮已启用。
【解决方案2】:

推送通知是从服务器推送到客户端的消息。它们必须是您的应用程序中在后台运行的一些服务,以便您可以随时娱乐您的消息。

在我看来,请使用 Firebase 云消息传递。完整的教程和代码参考如下:

https://firebase.google.com/docs/notifications/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-30
    相关资源
    最近更新 更多