在开发中偶尔碰到需要进行某个权限的判断获取,以下几行代码即可轻松搞定。
PackageManager pm = mContext.getPackageManager();
int i = pm.checkPermission("android.permission.READ_PHONE_STATE", mContext.getPackageName());
if (i == PackageManager.PERMISSION_GRANTED){
Log.d("WL", "onCreate: get permission " );
}else {
Log.d("WL", "onCreate: no permission ");
}