【问题标题】:Expo Push Notifications not popping in Android phones (Floating Notifications)世博推送通知未在 Android 手机中弹出(浮动通知)
【发布时间】:2018-08-20 15:11:53
【问题描述】:

编辑:我发现这些被称为浮动通知。任何人都知道如何从 Android 设备上的应用程序(通过权限等)默认启用它们?

我目前正在Android设备上测试推送通知,并注意到虽然我收到了推送通知,但它们并没有在屏幕上弹出而是停留在后台(我需要根据图片向下拖动顶部状态栏) .我认为这没什么用,因为用户在使用电话时不会真正得到通知:

在 iPhone 上,弹出窗口正确显示,没有任何问题。

【问题讨论】:

  • 您的推送通知是由库处理还是以编程方式处理?

标签: android react-native push-notification expo


【解决方案1】:

我终于用Expo.Notifications.createChannelAsyncpriority: "max" 让它工作了,并且在发送消息时添加channelId: "mychannel"

【讨论】:

  • 嗨,我设置如下: Notifications.createChannelAndroidAsync('JOBCONFIRMATION', { name: 'JOBCONFIRMATION', `sound: true, vibrate: [0, 250, 250, 250], 优先级: '最大限度', });但是,它在世博会应用程序上运行良好,但是当我世博会:构建它;不再工作了..我转到通知设置并检查默认设置为静音。您在构建为独立应用程序后是否遇到过这种情况?
  • priority 设置为"max" 不起作用,它所说的有效值只是“正常”“默认”或“高”。
  • @Noitidart 根据docs.expo.io/versions/latest/sdk/notifications max 是优先级的有效选项。
  • @assetCorp 我刚刚测试了它我得到了错误:error: Error occured while expo.sendPushNotificationsAsync, error: Error: "value" must be an object, "value" at position 0 fails because [child "priority" fails because ["priority" must be one of [default, normal, high]]].
  • priority (optional) (min | low | default | high | max) -- Android may present notifications in this channel differently according to the priority. For example, a high priority notification will likely to be shown as a heads-up notification. Note that the Android OS gives no guarantees about the user-facing behavior these abstractions produce -- for example, on many devices, there is no noticeable difference between high and max. @Noitidart 这是来自docs.expo.io/versions/latest/sdk/notifications 的博览会文档的摘录。你用的是什么版本的expo?
【解决方案2】:

要显示所谓的浮动通知,应用必须具有SYSTEM_ALERT_WINDOW 权限。

权限是用户给予的东西。因此,默认情况下无法从应用程序启用它们。您可以做的是将用户带到设置页面。




检查你是否已经拥有权限

推荐的方法是使用Settings#canDrawOverlays(Context)。此权限仅在 API 级别 23 中引入。因此根据文档,无需检查旧设备中的权限。

但是可以看出,这在一些像小米米 2 这样的棉花糖之前的设备中不会像预期的那样工作。所以最好按照this post 所示进行。

如果没有权限,将用户带到设置页面

如果应用以 API 级别 23 或更高级别为目标,应用用户必须通过权限管理屏幕明确授予应用此权限。该应用通过发送带有操作Settings.ACTION_MANAGE_OVERLAY_PERMISSION 的意图来请求用户的批准。

Intent intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setData(Uri.parse("package:" + context.getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(intent);

【讨论】:

  • 具有讽刺意味的是,这正是我所拥有的手机,而且我一直在使用它进行测试!
  • 如果这是真的,我的 Android 上的 Yahoo Mail、Fave、Grab 和大量其他应用程序如何能够显示来自推送消息的浮动通知?我从未从权限管理屏幕授予这些应用任何明确的权限。必须能够实现他们所做的事情。
猜你喜欢
  • 2022-06-19
  • 2019-08-24
  • 2021-03-02
  • 1970-01-01
  • 2021-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多