當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。