我希望检查特定的应用程序是否需要在运行时处理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;
}
这是我精心制作的表格,例如在使用Android Marshmallow运行时权限时需要向用户请求ACCESS_COARSE_LOCATION
权限。
====================
target SDK |<23| 23|
====================
|<23| X | X |
------------|
OS SDK |23 | X | V |
====================
我知道有Support库辅助工具的存在,但我希望在这种情况下避免使用它们。