本文整理了Java中android.content.Context.checkPermission()
方法的一些代码示例,展示了Context.checkPermission()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.checkPermission()
方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:checkPermission
暂无
代码示例来源:origin: oasisfeng/condom
@Override public int checkPermission(String permission, int pid, int uid) {
return mBase.checkPermission(permission, pid, uid);
}
代码示例来源:origin: Polidea/RxAndroidBle
/**
* Copied from android.support.v4.content.ContextCompat for backwards compatibility
* @param permission the permission to check
* @return true is granted
*/
private boolean isPermissionGranted(String permission) {
if (permission == null) {
throw new IllegalArgumentException("permission is null");
}
return context.checkPermission(permission, android.os.Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED;
}
}
代码示例来源:origin: AltBeacon/android-beacon-library
private boolean checkPermission(final String permission) {
return mContext.checkPermission(permission, android.os.Process.myPid(), android.os.Process.myUid()) == PackageManager.PERMISSION_GRANTED;
}
代码示例来源:origin: ankidroid/Anki-Android
private boolean hasReadWritePermission() {
return mContext.checkPermission(READ_WRITE_PERMISSION, Process.myPid(), Process.myUid())
== PackageManager.PERMISSION_GRANTED;
}
代码示例来源:origin: Tencent/tinker
CompatWorkEnqueuer(Context context, ComponentName cn) {
super(context, cn);
mContext = context.getApplicationContext();
if (mContext.checkPermission(Manifest.permission.WAKE_LOCK, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED) {
// Make wake locks. We need two, because the launch wake lock wants to have
// a timeout, and the system does not do the right thing if you mix timeout and
// non timeout (or even changing the timeout duration) in one wake lock.
PowerManager pm = ((PowerManager) context.getSystemService(Context.POWER_SERVICE));
mLaunchWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, cn.getClassName() + ":launch");
mLaunchWakeLock.setReferenceCounted(false);
mRunWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, cn.getClassName() + ":run");
mRunWakeLock.setReferenceCounted(false);
} else {
TinkerLog.w(TAG, "it would be better to grant WAKE_LOCK permission to your app so that tinker can use WakeLock to keep system awake.");
mLaunchWakeLock = mRunWakeLock = null;
}
}
代码示例来源:origin: robolectric/robolectric
@Test
public void some_test_with_permissions() {
Context context = getApplicationContext();
assertThat(context.checkPermission(permission.READ_CONTACTS, Process.myPid(), Process.myUid()))
.isEqualTo(PackageManager.PERMISSION_GRANTED);
assertThat(context.checkPermission(permission.WRITE_CONTACTS, Process.myPid(), Process.myUid()))
.isEqualTo(PackageManager.PERMISSION_DENIED);
}
}
代码示例来源:origin: facebook/stetho
private static void enforcePermission(Context context, LocalSocket peer)
throws IOException, PeerAuthorizationException {
Credentials credentials = peer.getPeerCredentials();
int uid = credentials.getUid();
int pid = credentials.getPid();
if (LogUtil.isLoggable(Log.VERBOSE)) {
LogUtil.v("Got request from uid=%d, pid=%d", uid, pid);
}
String requiredPermission = Manifest.permission.DUMP;
int checkResult = context.checkPermission(requiredPermission, pid, uid);
if (checkResult != PackageManager.PERMISSION_GRANTED) {
throw new PeerAuthorizationException(
"Peer pid=" + pid + ", uid=" + uid + " does not have " + requiredPermission);
}
}
}
代码示例来源: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: Trumeet/MiPushFramework
@Override public int checkPermission(String permission, int pid, int uid) {
return mBase.checkPermission(permission, pid, uid);
}
代码示例来源:origin: mattprecious/telescope
private static boolean hasVibratePermission(Context context) {
return context.checkPermission(VIBRATE, Process.myPid(), Process.myUid()) == PERMISSION_GRANTED;
}
代码示例来源: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: stackoverflow.com
public static int checkSelfPermission(@NonNull Context context, @NonNull String permission) {
if (permission == null) {
throw new IllegalArgumentException("permission is null");
}
return context.checkPermission(permission, android.os.Process.myPid(), Process.myUid());
}
代码示例来源:origin: linsir6/WebRTC-Voice
public static boolean hasPermission(Context context, String permission) {
return context.checkPermission(permission, Process.myPid(), Process.myUid())
== PackageManager.PERMISSION_GRANTED;
}
}
代码示例来源:origin: square/whorlwind
private int checkSelfPermission(String permission) {
return context.checkPermission(permission, android.os.Process.myPid(),
android.os.Process.myUid());
}
代码示例来源:origin: jksiezni/permissive
static int checkPermissionInt(Context context, String permission) {
if (permission == null) {
throw new IllegalArgumentException("permission is null");
}
return context.checkPermission(permission, Process.myPid(), Process.myUid());
}
代码示例来源:origin: xuningjack/RequestPermission
public static int checkSelfPermission(Context context, String permission) {
if(permission == null) {
throw new IllegalArgumentException("permission is null");
} else {
return context.checkPermission(permission, Process.myPid(), Process.myUid());
}
}
代码示例来源:origin: derry/delion
@CalledByNative
private static boolean checkDebugPermission(Context context, int pid, int uid) {
String debugPermissionName = context.getPackageName() + DEBUG_PERMISSION_SIFFIX;
return context.checkPermission(debugPermissionName, pid, uid)
== PackageManager.PERMISSION_GRANTED;
}
}
代码示例来源:origin: sxpl/FaceAC
/**
* 检测相机权限
*
* @return
*/
private boolean checkCameraPermission() {
int status = mContext.checkPermission(Manifest.permission.CAMERA, Process.myPid(), Process.myUid());
if (PackageManager.PERMISSION_GRANTED == status) {
return true;
}
return false;
}
代码示例来源:origin: smartdevicelink/sdl_android
@SuppressWarnings("SameParameterValue")
private boolean permissionCheck(String permissionToCheck){
if(permissionToCheck == null){
throw new IllegalArgumentException("permission is null");
}
return PackageManager.PERMISSION_GRANTED == getBaseContext().checkPermission(permissionToCheck, android.os.Process.myPid(), android.os.Process.myUid());
}
代码示例来源:origin: derry/delion
private boolean hasAndroidPermission(int contentSettingType) {
String androidPermission = PrefServiceBridge.getAndroidPermissionForContentSetting(
contentSettingType);
return androidPermission == null
|| (mContext.checkPermission(androidPermission, Process.myPid(), Process.myUid())
== PackageManager.PERMISSION_GRANTED);
}
内容来源于网络,如有侵权,请联系作者删除!