Android的点击通知不打开附件中的活动 [英] Android click on notification does not open the attached Activity

查看:188
本文介绍了Android的点击通知不打开附件中的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打开一个活动,当我点击从状态栏上的通知。我看到这个回答对计算器,但这些答案为我工作。 这个问题只看到棒棒糖设备和再现是最好的方法: 1.启动应用程序。 2.回到地面的应用程序。 3.收到一个推送通知。 4.点击通知,并尝试与3-4推送通知。

下面是我的code:我也试过如下:

  1. 添加Intent.ACTION_MAIN
  2. Intent.CATEGORY_LAUNCHER的意图
  3. PendingIntent.FLAG_UPDATE_CURRENT。
  4. 机器人:在我的Andr​​oidManifest.xml出口=真正的

但没有任何工程。我只是在棒棒糖设备看到了这个问题。 请注意,我看到这个问题间歇性。这是不是涉及到的意图越来越缓存,并没有得到发表。请大家帮帮忙。

  PendingIntent pendingIntent = getPendingIntent(背景下,有效载荷);
构建notificationBuilder =新NotificationCompat.Builder(上下文)
            .setSmallIcon(R.drawable.ic_stat)
            .setContentTitle(res.getString(R.string.app_name))
            .setContentText(payload.getMessage())
            .setTicker(payload.getMessage())
            .setContentIntent(pendingIntent)
            .setSound(soundUri);

私人PendingIntent getPendingIntent(上下文的背景下,NotificationPayload有效载荷){
    INT请求ID =(INT)System.currentTimeMillis的();
    意向意图=新的意图(背景下,DeepLinkActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setPackage(BuildConfig.APPLICATION_ID);
    intent.putExtra(NotificationHelper.KEY_NOTIFICATION_PAYLOAD,有效载荷);
    返回PendingIntent.getActivity(背景下,请求ID,意图,PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT);
}
 

解决方案

尝试加入Intent.FLAG_ACTIVITY_CLEAR_TASK标志的意图

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

这似乎解决了我的问题。

I want to open an Activity when I click on the notification from the Status bar. I have seen this answered on StackOverflow but none of these answers work for me. This issue is only seen on Lollipop devices and best way to reproduce is: 1. launch the app. 2. Back ground the app. 3. Receive a push notification. 4. Click on the notification and try with 3-4 push notifications.

Below is my code: I have also tried the following:

  1. adding Intent.ACTION_MAIN
  2. Intent.CATEGORY_LAUNCHER to the intent
  3. PendingIntent.FLAG_UPDATE_CURRENT.
  4. android:exported="true" in my AndroidManifest.xml

but nothing works. I am seeing this issue only on Lollipop devices. Please note I see this issue intermittently. Is this something related to the intent getting cached and not getting delivered. Please help.

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);
}

解决方案

try adding Intent.FLAG_ACTIVITY_CLEAR_TASK flag in the intent

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

this seems to solve my problem

这篇关于Android的点击通知不打开附件中的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆