本文整理汇总了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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}