【问题标题】:setFullScreenIntent does not work second timesetFullScreenIntent 第二次不起作用
【发布时间】:2013-07-12 13:58:01
【问题描述】:

我在 android 中有一个应用程序,我想在某些情况下将活动带到前台。我为此使用 NotificationManager。这是我的代码。问题是,活动第一次成功地被带到了前面,但后来却没有。此外,此代码是从服务运行的。

Intent notificationIntent = new Intent(context, MainActivity.class);
            PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

            NotificationCompat.Builder mBuilder =
                        new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.ic_launcher)
                        .setContentIntent(contentIntent)
                        .setContentTitle("Bring me front!")
                        .setContentText("Bring me!!! BRING!!!")
                        .setFullScreenIntent(contentIntent, true);

            NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(0, mBuilder.build());

【问题讨论】:

    标签: android android-activity notifications android-notifications


    【解决方案1】:

    NotificationManager 具有(未记录的)行为,如果您发布与已激活通知的 ID 匹配的新通知,它将忽略 fullScreenIntent 字段。

    【讨论】:

    • 这正是我们一直在经历的问题 - 尽管仅在某些设备上,而不是在所有设备上。谢谢!
    【解决方案2】:

    我遇到了类似的问题。就我而言,我错过了两件事:

    1. 在 Manifest 中使用 USE_FULL_SCREEN_INTENT 权限。
    2. 必须在手机设置中设置密码或图形。按下解锁按钮后,用户必须立即无法使用 UI。然后显示全屏活动。

    【讨论】:

      【解决方案3】:

      需要检查的几件事:

      1. 您的意图可能需要FLAG_ACTIVITY_NEW_TASK(也可能需要FLAG_ACTIVITY_CLEAR_TOP)来确保将活动置于最前面。
      2. 确保您没有多次尝试重复使用同一个 PendingIntent;每次发布此通知时,您都需要构造一个新的 PendingIntent 以用于fullScreenIntent

      【讨论】:

      • 谢谢,我已经解决了这个问题和你提到的在解决方案中使用的标志: Intent intent = new Intent("android.intent.category.LAUNCHER"); intent.setClassName("co.simplytech.bulova_time", "co.simplytech.bulova_time.MainActivity");意图.setFlags(意图.FLAG_ACTIVITY_NEW_TASK);开始活动(意图);
      • 建议的解决方案都不适合我。我没有任何错误,它仍然是正常的通知。
      猜你喜欢
      • 1970-01-01
      • 2021-01-13
      • 2014-01-31
      • 2015-06-21
      • 2011-10-04
      • 1970-01-01
      • 2020-04-16
      • 2011-11-10
      • 2019-11-25
      相关资源
      最近更新 更多