本文整理了Java中android.content.Context.checkSelfPermission()
方法的一些代码示例,展示了Context.checkSelfPermission()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.checkSelfPermission()
方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:checkSelfPermission
暂无
代码示例来源:origin: square/leakcanary
@TargetApi(M) private boolean hasStoragePermission() {
if (SDK_INT < M) {
return true;
}
// Once true, this won't change for the life of the process so we can cache it.
if (writeExternalStorageGranted) {
return true;
}
writeExternalStorageGranted =
context.checkSelfPermission(WRITE_EXTERNAL_STORAGE) == PERMISSION_GRANTED;
return writeExternalStorageGranted;
}
代码示例来源:origin: naman14/Timber
/**
* Not that needed method but if we override others it is good to keep same.
*/
public static boolean checkPermission(String permissionName) {
if (context == null) {
throw new RuntimeException("Before comparing permissions you need to call Nammu.init(context)");
}
return PackageManager.PERMISSION_GRANTED == context.checkSelfPermission(permissionName);
}
}
代码示例来源:origin: aa112901/remusic
/**
* Not that needed method but if we override others it is good to keep same.
*/
public static boolean checkPermission(String permissionName) {
if (context == null) {
throw new RuntimeException("Before comparing permissions you need to call Nammu.initCatchException(context)");
}
return PackageManager.PERMISSION_GRANTED == context.checkSelfPermission(permissionName);
}
}
代码示例来源:origin: oasisfeng/condom
@RequiresApi(M) @Override public int checkSelfPermission(String permission) {
return mBase.checkSelfPermission(permission);
}
代码示例来源:origin: ArthurHub/Android-Image-Cropper
/**
* Check if explicetly requesting camera permission is required.<br>
* It is required in Android Marshmellow and above if "CAMERA" permission is requested in the
* manifest.<br>
* See <a
* href="http://stackoverflow.com/questions/32789027/android-m-camera-intent-permission-bug">StackOverflow
* question</a>.
*/
public static boolean isExplicitCameraPermissionRequired(@NonNull Context context) {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& hasPermissionInManifest(context, "android.permission.CAMERA")
&& context.checkSelfPermission(Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED;
}
代码示例来源:origin: wangdan/AisenWeiBo
@SuppressLint("NewApi")
public static boolean checkPermission(Context context, String permission) {
boolean result = false;
if (Build.VERSION.SDK_INT >= 23) {
if (context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED) {
result = true;
}
} else {
PackageManager pm = context.getPackageManager();
if (pm.checkPermission(permission, context.getPackageName()) == PackageManager.PERMISSION_GRANTED) {
result = true;
}
}
return result;
}
代码示例来源:origin: ArthurHub/Android-Image-Cropper
/**
* Check if the given picked image URI requires READ_EXTERNAL_STORAGE permissions.<br>
* Only relevant for API version 23 and above and not required for all URI's depends on the
* implementation of the app that was used for picking the image. So we just test if we can open
* the stream or do we get an exception when we try, Android is awesome.
*
* @param context used to access Android APIs, like content resolve, it is your
* activity/fragment/widget.
* @param uri the result URI of image pick.
* @return true - required permission are not granted, false - either no need for permissions or
* they are granted
*/
public static boolean isReadExternalStoragePermissionsRequired(
@NonNull Context context, @NonNull Uri uri) {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& context.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED
&& isUriRequiresPermissions(context, uri);
}
代码示例来源:origin: naman14/Timber
if (context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED) {
permissionsGranted.add(permission);
代码示例来源:origin: aa112901/remusic
if (context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED) {
permissionsGranted.add(permission);
代码示例来源:origin: oasisfeng/condom
private static void assertPermission(final Context context, final String permission, final boolean granted) throws NameNotFoundException {
final int state = granted ? PERMISSION_GRANTED : PERMISSION_DENIED;
assertEquals(state, context.checkPermission(permission, Process.myPid(), Process.myUid()));
if (SDK_INT >= M) assertEquals(state, context.checkSelfPermission(permission));
final PackageInfo pkg_info = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
if (! granted) return;
assertNotNull(pkg_info.requestedPermissions);
for (int i = 0; i < pkg_info.requestedPermissions.length; i++)
if (permission.equals(pkg_info.requestedPermissions[i])) {
assertEquals("Not granted: " + permission, PackageInfo.REQUESTED_PERMISSION_GRANTED, pkg_info.requestedPermissionsFlags[i]);
return;
}
fail(permission + " is not in requested permissions: " + Arrays.deepToString(pkg_info.requestedPermissions));
}
代码示例来源:origin: a-voyager/AutoInstaller
private boolean permissionDenied() {
if (Build.VERSION.SDK_INT >= 23) {
String[] permissions = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
};
for (String str : permissions) {
if (mContext.checkSelfPermission(str) != PackageManager.PERMISSION_GRANTED) {
return true;
}
}
}
return false;
}
代码示例来源:origin: Neamar/KISS
public static boolean checkContactPermission(Context context) {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M || context.checkSelfPermission(Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED;
}
代码示例来源:origin: Trumeet/MiPushFramework
@RequiresApi(M) @Override public int checkSelfPermission(String permission) {
return mBase.checkSelfPermission(permission);
}
代码示例来源:origin: guolindev/giffun
/**
* Check if explicetly requesting camera permission is required.<br>
* It is required in Android Marshmellow and above if "CAMERA" permission is requested in the
* manifest.<br>
* See <a
* href="http://stackoverflow.com/questions/32789027/android-m-camera-intent-permission-bug">StackOverflow
* question</a>.
*/
public static boolean isExplicitCameraPermissionRequired(@NonNull Context context) {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& hasPermissionInManifest(context, "android.permission.CAMERA")
&& context.checkSelfPermission(Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED;
}
代码示例来源:origin: guolindev/giffun
/**
* Check if the given picked image URI requires READ_EXTERNAL_STORAGE permissions.<br>
* Only relevant for API version 23 and above and not required for all URI's depends on the
* implementation of the app that was used for picking the image. So we just test if we can open
* the stream or do we get an exception when we try, Android is awesome.
*
* @param context used to access Android APIs, like content resolve, it is your
* activity/fragment/widget.
* @param uri the result URI of image pick.
* @return true - required permission are not granted, false - either no need for permissions or
* they are granted
*/
public static boolean isReadExternalStoragePermissionsRequired(
@NonNull Context context, @NonNull Uri uri) {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& context.checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED
&& isUriRequiresPermissions(context, uri);
}
代码示例来源:origin: jingle1267/android-utils
/**
* 调用系统打电话界面
*
* @param context 上下文
* @param phoneNumber 手机号码
*/
@TargetApi(Build.VERSION_CODES.M)
public static void callPhones(Context context, String phoneNumber) {
if (phoneNumber == null || phoneNumber.length() < 1) {
return;
}
Uri uri = Uri.parse("tel:" + phoneNumber);
Intent intent = new Intent(Intent.ACTION_CALL, uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (context.checkSelfPermission(Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// Activity#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for Activity#requestPermissions for more details.
return;
}
context.startActivity(intent);
}
代码示例来源:origin: liuling07/SimpleNews
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& context.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
LogUtils.e(TAG, "location failure.");
listener.onFailure("location failure.", null);
代码示例来源:origin: Trumeet/MiPushFramework
private static void assertPermission(final Context context, final String permission, final boolean granted) {
final int state = granted ? PERMISSION_GRANTED : PERMISSION_DENIED;
assertEquals(state, context.checkPermission(permission, Process.myPid(), Process.myUid()));
if (SDK_INT >= M) assertEquals(state, context.checkSelfPermission(permission));
}
代码示例来源:origin: tyrex-team/senslogs
@Override
public boolean checkPermission(Context context) {
return !(Build.VERSION.SDK_INT >= 23 &&
context.checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED);
}
代码示例来源:origin: ZhangQinhao/MONKOVEL
public static Boolean checkPremission(Context context,String permission){
boolean result = false;
if (getTargetSdkVersion(context) >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
result = context.checkSelfPermission(permission)
== PackageManager.PERMISSION_GRANTED;
} else {
result = PermissionChecker.checkSelfPermission(context, permission)
== PermissionChecker.PERMISSION_GRANTED;
}
return result;
}
内容来源于网络,如有侵权,请联系作者删除!