简体   繁体   English

棉花糖应用程序权限:android.location.PROVIDERS_CHANGED未触发

[英]Marshmallow app-permission: android.location.PROVIDERS_CHANGED is not fired

I have an App that listens to android.location.PROVIDERS_CHANGED broadcast to stay aware of the phone's current location capabilities. 我有一个可收听android.location.PROVIDERS_CHANGED广播的应用程序,以了解手机的当前定位功能。

With Android M and the new App-runtime permissions, it works normally when the location is changed from the system/general panel. 使用Android M和新的应用程序运行时权限,当从“系统/常规”面板更改位置时,它可以正常工作。 But if a user disables the location permission specifically for the App, the same broadcast is not fired. 但是,如果用户禁用了专门针对该应用的位置权限,则不会触发相同的广播。

So far I can test for location access with a regular AlarmManager, but it's quite odd and not very responsive. 到目前为止,我可以使用常规的AlarmManager测试位置访问权限,但是这很奇怪,而且反应也不灵敏。

Is there any other specific method, ideally a kind of BroadcastReceiver to register that keeps us informed of this location app-permission-change with Android M? 是否还有其他特定方法,最好是一种BroadcastReceiver进行注册,以使我们知道Android M的此位置应用程序许可更改?

Sorry, but you are not directly notified about permission changes, for locations or other permissions, unless there's some undocumented hack that I'm not aware of. 抱歉,除非您不知悉某些未记录的黑客,否则不会直接通知您有关位置或其他权限的权限更改。

If the user revokes a permission, your app's process will be terminated. 如果用户撤消许可,您的应用程序进程将终止。 The idea is that you will find out about the revoked permission when your app runs again and you call checkSelfPermission() . 这个想法是,当您的应用程序再次运行并调用checkSelfPermission()时,您将了解有关已撤销权限的信息。 That flow is optimized for more conventional cases, where the permission checks are being conducted in an activity opened by the user. 该流程针对常规情况进行了优化,在常规情况下,权限检查是在用户打开的活动中进行的。 It doesn't handle your case very well (though, IMHO, location permissions shouldn't affect the broadcast as you describe). 它不能很好地处理您的情况(不过,恕我直言,位置权限不会像您所描述的那样影响广播)。

In the N Developer Preview, you can now set up JobScheduler to monitor a Uri for changes and trigger your job as needed. 在N Developer Preview中,您现在可以设置JobScheduler来监视Uri的更改并根据需要触发您的作业。 This is a bit like registering a ContentObserver , except that you don't need the process running all the time — JobScheduler registers the observer and just invokes your JobService as needed. 这有点像注册ContentObserver ,除了您不需要一直运行该进程— JobScheduler注册观察者并仅在需要时调用JobService I think that the roster of enabled location sources is found in the Settings provider somewhere; 认为已启用的位置源花名册可以在“ Settings提供程序的某个位置找到; if so, for Android 6.1/7.0/Turbo System 5000/whatever N turns into, you might be able to use JobScheduler to find out about the location source changes, instead of relying on the broadcast. 如果是这样,对于Android 6.1 / 7.0 / Turbo System 5000 /无论N变成什么,您都可以使用JobScheduler来查找有关位置源更改的信息,而不必依赖广播。

That doesn't help you for Android 6.0, though. 但是,这对于Android 6.0并没有帮助。 You can use JobScheduler or AlarmManager or something to see if you lost the permission (via checkSelfPermission() ), but that's kinda wasteful of battery life (and, as a result, will not work well given Doze mode and possibly app standby). 您可以使用JobSchedulerAlarmManager或其他方法来查看是否丢失了权限(通过checkSelfPermission() ),但这有点浪费电池寿命(因此,在Doze模式和可能的应用待机状态下,它们将无法正常工作)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM