您好,登錄后才能下訂單哦!
本文介紹了詳解Android 檢測權限的三種寫法,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
權限檢測生效條件:
三種檢測權限寫法:
public static boolean checkPermission1(Context context, String[] permissions) { PackageManager packageManager = context.getPackageManager(); String packageName = context.getPackageName(); for (String permission : permissions) { int per = packageManager.checkPermission(permission, packageName); if (PackageManager.PERMISSION_DENIED == per) { Log.w(TAG, "required permission not granted . permission = " + permission); return false; } } return true; } public static boolean checkPermission2(Context context, String[] permissions) { for (String permission : permissions) { int per =context.checkPermission(permission, Process.myPid(),Process.myUid()); if (PackageManager.PERMISSION_GRANTED != per) { Log.w(TAG, "required permission not granted . permission = " + permission); return false; } } return true; } public static boolean checkPermission3(Context context, String[] permissions) { for (String permission : permissions) { int per = ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA); if (PackageManager.PERMISSION_GRANTED != per) { Log.w(TAG, "required permission not granted . permission = " + permission); return false; } } return true; }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。