如何从 Android Marshmallow 中的服务请求权限 - How to request permissions from a Service in Android Marshmallow

问题:

In Android Marshmallow, permissions should be requested at runtime when they are needed, instead of all at once when an app is installed.在 Android Marshmallow 中,应在需要时在运行时请求权限,而不是在安装应用程序时一次性请求所有权限。 However, I can only seem to request permissions from an Activity, which is a problem since my app contains only Services.但是,我似乎只能从 Activity 请求权限,这是一个问题,因为我的应用程序仅包含服务。 (Why is that, you might ask? The app has an Android Wear watch face bundled inside, and all the phone does is look up photos nearby to send to the watch - no Activity needed. But it does require location permissions.) (你可能会问这是为什么?该应用程序内置了一个 Android Wear 表盘,手机所做的就是查找附近的照片以发送到手表 - 不需要 Activity。但它确实需要位置权限。)

So, is there any way to request permissions from a Service?那么,有没有办法从服务请求权限? Or somehow force the permissions to be granted at install time as in the past?或者以某种方式强制在安装时授予权限,就像过去一样?


解决方案:

参考: https://stackoom.com/en/question/2BUnb
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章