Android - 推送通知是否开启? [英] Android - Push Notification are ON?

查看:34
本文介绍了Android - 推送通知是否开启?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式检查用户是否在应用设置中关闭推送通知?我可以直接从应用打开应用设置 Intent 以提示用户打开它吗?

How to check programmatically if user turn off push notification in app settings? Can I open app settings intent directly from the app to prompt user to turn it on?

谢谢

推荐答案

假设您指的是 Google Cloud Messaging(因为您使用的是 android 和 push-notification 标签),则没有用于启用/禁用GCM 服务(与适用于 iOS 设备的 Apple 推送通知服务不同).

Assuming you are referring to Google Cloud Messaging (since you are using the android and push-notification tag), there are no general settings used to enable/disable the GCM service (unlike the Apple Push Notifications service for iOS devices).

当您安装应用程序时,如果该应用程序使用 Google Cloud Messaging,它将列在此应用程序运行所需的权限列表中.通过选择安装该应用,您允许它向您发送推送通知.

When you install an app, if the app uses Google Cloud Messaging, it will be listed in the list of permissions that this app requires in order to work. By choosing to install the app you allow it to send push notifications to you.

也就是说,为了让应用真正接收 GCM 消息,您的应用必须以编程方式注册到 GCM 服务.您可以在您的应用程序中的任何位置执行此操作,并且您可以创建一个 app settings 活动(或片段或其他),用户可以在其中启用/禁用 GCM(这将触发注册/取消注册到/从 GCM).您的应用可以包含一个持久存储,用于保存您在注册到 GCM 时收到的注册 ID,您可以使用该存储来确定您的应用是否已注册到 GCM.

That said, in order for the app to actually receive GCM messages, your app must programmatically register to the GCM service. You can do that in any place you wish within your app, and you can create an app settings activity (or fragment or whatever) in which the user can enable/disable GCM (which would trigger registration/unregistration to/from GCM). Your app can contain a persistent store that would hold the registration ID you receive upon registration to GCM, and you can use that store to determine if your app in registered to GCM.

如果应用程序已经在运行,您可以要求您的用户将其打开(如果您有一些代码可以这样做).如果它没有运行并且该应用程序未在该设备上注册 GCM,则您的服务器无法向它发送 GCM 消息.

You can ask your user to turn it on if the app is already running (if you have some code that does that). If it's not running and the app is not registered for GCM on that device, your server can't send GCM messages to it.

如果您想克服这个障碍,您可以自动注册到 GCM(在应用程序首次启动时).然后,您可以随时向应用程序发送消息.如果您仍然想让用户决定他们是否希望看到这些通知,您可以在应用设置中有一个标志,用于启用/禁用您作为传入 GCM 消息的结果创建的 UI 通知.GCM 服务将始终处于启用状态,但除非用户选择查看通知,否则当 GCM 消息到达时,您的应用将不会显示任何内容.

If you want to overcome that obstacle, you can register to GCM automatically (when the app is first launched). Then you can send messages to the app whenever you wish. If you still want to let the user decide whether they want to see those notifications, you can have a flag in your app settings that enables/disables the UI notification that you create as a result of an incoming GCM message. The GCM service will always be enabled, but unless the user chooses to view the notifications, you app won't display anything when a GCM message arrives.

这篇关于Android - 推送通知是否开启?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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