Android的 - 推送通知是对?通知、Android

2023-09-06 03:09:15 作者:Fate丶情途末路

如何检查编程是否用户关闭推送通知的应用程序设置? 我可以直接从应用程序打开应用程序设置意图提示用户打开它?

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?

感谢

推荐答案

假设你指的是谷歌云消息(因为你使用的是Android和推通知标记),还有用于启用无常规设置/禁用GCM服务(不像苹果推iOS设备通知服务)。

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).

当你安装一个应用程序,如果应用程序使用谷歌云消息传递,它会列在权限列表中,这个应用程序需要为了工作。通过选择要安装的应用程序,你允许它来发送推送通知给你。

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服务。你可以在你希望你的应用程序中的任何地方,你可以创建一个应用程序设置活动(或片段或其他)中,用户可以启用/禁用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.

您可以要求用户打开它,如果应用程序已经在运行(如果你有一些code,做的)。如果它没有运行,并且应用程序没有为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.