如何從 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章