android权限询问,Android:检查是否必须询问运行时权限
我想檢查一個特定的應用程序是否需要在運行時處理Android Marshmallow運行時權限.
以下假設是否正確?
/**
* Checks whether runtime permissions must be handled or not.
*
* @param context Application context.
* @return Handle runtime permissions or not.
*/
public static boolean shouldCheckRuntimePermissions(Context context) {
return
isApplicationWithMarshmallowTargetSdkVersion(context) &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
}
/**
* Checks whether the app is compiled with targetSdkVersion Marshmallow or above.
*
* @param context Application context.
* @return Application targetSdkVersion above 23 or not.
*/
public static boolean isApplicationWithMarshmallowTargetSdkVersion(Context context) {
return
context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.M;
}
這是我詳細說明的表格,例如,需要ACCESS_COARSE_LOCATION權限才能向具有Android Marshmallow運行時權限的用戶詢問.
====================
target SDK |<23| 23|
====================
|<23| X | X |
------------|
OS SDK |23 | X | V |
====================
我知道支持庫helpers的存在,但是對于這種特殊情況,我想避免使用它們.
總結
以上是生活随笔為你收集整理的android权限询问,Android:检查是否必须询问运行时权限的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pro android学习笔记,Pro
- 下一篇: html文件语言表示网页标题,HTML网