यदि किसी को उनकी आवश्यकता हो तो मेरे तरीके साझा करना:
/** Determines if the context calling has the required permission
* @param context - the IPC context
* @param permissions - The permissions to check
* @return true if the IPC has the granted permission
*/
public static boolean hasPermission(Context context, String permission) {
int res = context.checkCallingOrSelfPermission(permission);
Log.v(TAG, "permission: " + permission + " = \t\t" +
(res == PackageManager.PERMISSION_GRANTED ? "GRANTED" : "DENIED"));
return res == PackageManager.PERMISSION_GRANTED;
}
/** Determines if the context calling has the required permissions
* @param context - the IPC context
* @param permissions - The permissions to check
* @return true if the IPC has the granted permission
*/
public static boolean hasPermissions(Context context, String... permissions) {
boolean hasAllPermissions = true;
for(String permission : permissions) {
//you can return false instead of assigning, but by assigning you can log all permission values
if (! hasPermission(context, permission)) {hasAllPermissions = false; }
}
return hasAllPermissions;
}
और इसे कॉल करने के लिए:
boolean hasAndroidPermissions = SystemUtils.hasPermissions(mContext, new String[] {
android.Manifest.permission.ACCESS_WIFI_STATE,
android.Manifest.permission.READ_PHONE_STATE,
android.Manifest.permission.ACCESS_NETWORK_STATE,
android.Manifest.permission.INTERNET,
});