当前位置: 首页>>代码示例>>Java>>正文


Java Context.checkSelfPermission方法代码示例

本文整理汇总了Java中android.content.Context.checkSelfPermission方法的典型用法代码示例。如果您正苦于以下问题:Java Context.checkSelfPermission方法的具体用法?Java Context.checkSelfPermission怎么用?Java Context.checkSelfPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.Context的用法示例。


在下文中一共展示了Context.checkSelfPermission方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkPermission

import android.content.Context; //导入方法依赖的package包/类
public boolean checkPermission(Context context, String... permission) {

        boolean nr = true;

        for (int i = 0; i < permission.length; i++) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                // targetSdkVersion >= Android M, we can
                // use Context#checkSelfPermission
                nr = context.checkSelfPermission(permission[i])
                        == PackageManager.PERMISSION_GRANTED;
            } else {
                // targetSdkVersion < Android M, we have to use PermissionChecker
                nr = PermissionChecker.checkSelfPermission(context, permission[i])
                        == PermissionChecker.PERMISSION_GRANTED;
            }

            if (!nr) {
                break;
            }
        }
        return nr;
    }
 
开发者ID:DuanJiaNing,项目名称:Musicoco,代码行数:23,代码来源:PermissionManager.java

示例2: checkPermission

import android.content.Context; //导入方法依赖的package包/类
/**
 * SD卡存储权限检查
 */
private boolean checkPermission(Context context) {
	if (context == null) {
		Log.e(TAG, "checkMPermission context null");
		return false;
	}

	// M permission
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
		String p1 = Manifest.permission.WRITE_EXTERNAL_STORAGE;
		String p2 = Manifest.permission.READ_EXTERNAL_STORAGE;
		// M 先看看有没有读写权限
		if (context.checkSelfPermission(p1) != PackageManager.PERMISSION_GRANTED ||
				context.checkSelfPermission(p2) != PackageManager.PERMISSION_GRANTED) {
			Log.e(TAG, "without permission to access storage");
			return false;
		}
	}

	return true;
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:24,代码来源:ExternalStorage.java

示例3: hasPermission

import android.content.Context; //导入方法依赖的package包/类
/**
 * 检查是否有某项权限的试用权
 *
 * @param context    Context环境
 * @param permission 权限
 * @return true:有 false:没有
 */
public static boolean hasPermission(Context context, String permission)
{
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
        return true;

    try
    {
        if (context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED)
        {
            String op = AppOpsManagerCompat.permissionToOp(permission);
            return AppOpsManagerCompat.noteProxyOp(context, op, context.getPackageName())
                    == AppOpsManagerCompat.MODE_ALLOWED;
        } else
            return false;
        //            String op = AppOpsManagerCompat.permissionToOp(permission);
        //            int opResult = AppOpsManagerCompat.noteProxyOp(context, op, context.getPackageName());
        //            int rtResult = context.checkSelfPermission(permission);
        //            if (opResult == AppOpsManagerCompat.MODE_ALLOWED && rtResult == PackageManager.PERMISSION_GRANTED)
        //                return true;
        //            else
        //                return false;
    } catch (Exception e)
    {
        return false;
    }
}
 
开发者ID:Vanish136,项目名称:RTPermission,代码行数:34,代码来源:RTUtils.java

示例4: isExplicitCameraPermissionRequired

import android.content.Context; //导入方法依赖的package包/类
/**
 * 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) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return hasPermissionInManifest(context, "android.permission.CAMERA") &&
                context.checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED;
    }
    return false;
}
 
开发者ID:chuch0805,项目名称:Android-Demo_ImageCroper,代码行数:14,代码来源:CropImage.java

示例5: addPermission

import android.content.Context; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
private static boolean addPermission(Context context, List<String> permissionsList, String permission)
{
    if (context.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED)
    {
        permissionsList.add(permission);

        return false;
    }
    return true;
}
 
开发者ID:yash786agg,项目名称:GPS,代码行数:12,代码来源:AcessLocation.java

示例6: hasPermission

import android.content.Context; //导入方法依赖的package包/类
public boolean hasPermission(Context c) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (c.checkSelfPermission(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED) {
            return true;
        }
    } else {
        return true;
    }
    return false;
}
 
开发者ID:manuelsc,项目名称:Lunary-Ethereum-Wallet,代码行数:11,代码来源:QRScanActivity.java

示例7: writeExternalStoragePermission

import android.content.Context; //导入方法依赖的package包/类
public static boolean writeExternalStoragePermission(Context context) {
    Log.w("PermissionChecker", "check WRITE_EXTERNAL_STORAGE");
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        int permissionState = context.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
        if (permissionState == PackageManager.PERMISSION_GRANTED) {
            return true;
        }
    }
    return false;
}
 
开发者ID:limpoxe,项目名称:Android-DownloadManager,代码行数:11,代码来源:PermissionChecker.java

示例8: hasPermission

import android.content.Context; //导入方法依赖的package包/类
public static boolean hasPermission(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return context.checkSelfPermission(PERMISSION_CAMERA) == PackageManager.PERMISSION_GRANTED
                && context.checkSelfPermission(PERMISSION_STORAGE) == PackageManager.PERMISSION_GRANTED;
    } else {
        return true;
    }
}
 
开发者ID:deepenai,项目名称:deepenlib-android-sample,代码行数:9,代码来源:PermissionUtil.java

示例9: checkReadPhonePermission

import android.content.Context; //导入方法依赖的package包/类
public static boolean checkReadPhonePermission(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if(context.checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED)
            return true;
        return false;
    }
    return true;
}
 
开发者ID:KrongKrongPadakPadak,项目名称:mvo,代码行数:9,代码来源:Utils.java

示例10: hasStoragePermissions

import android.content.Context; //导入方法依赖的package包/类
private boolean hasStoragePermissions() {
if (Build.VERSION.SDK_INT < 23) {
	return true;
}

Context context = TiApplication.getInstance().getApplicationContext();

if (context.checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
	return true;
}

return false;
  }
 
开发者ID:prashantsaini1,项目名称:titanium-android-imagepicker,代码行数:14,代码来源:ImagepickerModule.java

示例11: grantExternalStoragePermission

import android.content.Context; //导入方法依赖的package包/类
private void grantExternalStoragePermission() {
    Context context = InstrumentationRegistry.getTargetContext();
    String readPermission = "android.permission.READ_EXTERNAL_STORAGE";
    if (context.checkSelfPermission(readPermission) != PackageManager.PERMISSION_GRANTED) {
        requestGrantPermission(readPermission);
    }

    String writePermission = "android.permission.WRITE_EXTERNAL_STORAGE";
    if (context.checkSelfPermission(writePermission) != PackageManager.PERMISSION_GRANTED) {
        requestGrantPermission(writePermission);
    }
}
 
开发者ID:forusoul70,项目名称:playTorrent,代码行数:13,代码来源:TestDownloadProcessor.java

示例12: isPermissionGranted

import android.content.Context; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
boolean isPermissionGranted(Context context,String permission) {
    return context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
}
 
开发者ID:paozhuanyinyu,项目名称:XPermission,代码行数:5,代码来源:XPermission.java

示例13: checkPermission

import android.content.Context; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
public static boolean checkPermission(Context context, String permission) {
    return !checkForVersion(Build.VERSION_CODES.M)
            || context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:6,代码来源:Permission.java

示例14: hasPhoneStatePermission

import android.content.Context; //导入方法依赖的package包/类
public static boolean hasPhoneStatePermission(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
        return (context.checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED);
    else
        return true;
}
 
开发者ID:miankai,项目名称:MKAPP,代码行数:7,代码来源:Util.java

示例15: isExplicitCameraPermissionRequired

import android.content.Context; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:prashantsaini1,项目名称:android-titanium-imagecropper,代码行数:15,代码来源:CropImage.java


注:本文中的android.content.Context.checkSelfPermission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。