本文整理匯總了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;
}