本文整理匯總了Java中android.content.Context.checkPermission方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.checkPermission方法的具體用法?Java Context.checkPermission怎麽用?Java Context.checkPermission使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.Context
的用法示例。
在下文中一共展示了Context.checkPermission方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: lacksPermission
import android.content.Context; //導入方法依賴的package包/類
/**
* Returns whether the current context lacks a given permission. Skips the check on M+ systems
* if {@code onlyPreM} is {@code true}, and just returns {@code false}.
*/
@VisibleForTesting
boolean lacksPermission(Context context, String permission, boolean onlyPreM) {
if (onlyPreM && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return false;
int permissionResult =
context.checkPermission(permission, Process.myPid(), Process.myUid());
return permissionResult != PackageManager.PERMISSION_GRANTED;
}
示例2: getThumbnailOfLastPhoto
import android.content.Context; //導入方法依賴的package包/類
private Bitmap getThumbnailOfLastPhoto(Context context) {
boolean canReadExternalStorage = context.checkPermission(
Manifest.permission.READ_EXTERNAL_STORAGE, Process.myPid(), Process.myUid()) ==
PackageManager.PERMISSION_GRANTED;
if (!canReadExternalStorage) {
// MediaStore.Images.Media.EXTERNAL_CONTENT_URI requires
// the READ_EXTERNAL_STORAGE permission
return null;
}
Cursor cursor = MediaStore.Images.Media.query(context.getContentResolver(),
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[]{MediaStore.Images.ImageColumns._ID,
MediaStore.Images.ImageColumns.DATE_TAKEN},
null, null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC LIMIT 1");
Bitmap thumb = null;
if (cursor != null) {
if (cursor.moveToNext()) {
int id = cursor.getInt(0);
thumb = MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(),
id, MediaStore.Images.Thumbnails.MINI_KIND, null);
}
cursor.close();
}
return thumb;
}
示例3: performImportIfPossible
import android.content.Context; //導入方法依賴的package包/類
/**
* Performs data import if possible.
* @return true on successful data import, false if it was not available
* @throws Exception if the import failed
*/
public static boolean performImportIfPossible(Context context) throws Exception {
SharedPreferences devicePrefs = getDevicePrefs(context);
String sourcePackage = devicePrefs.getString(KEY_DATA_IMPORT_SRC_PKG, "");
String sourceAuthority = devicePrefs.getString(KEY_DATA_IMPORT_SRC_AUTHORITY, "");
if (TextUtils.isEmpty(sourcePackage) || TextUtils.isEmpty(sourceAuthority)) {
return false;
}
// Synchronously clear the migration flags. This ensures that we do not try migration
// again and thus prevents potential crash loops due to migration failure.
devicePrefs.edit().remove(KEY_DATA_IMPORT_SRC_PKG).remove(KEY_DATA_IMPORT_SRC_AUTHORITY).apply();
if (!Settings.call(context.getContentResolver(), Settings.METHOD_WAS_EMPTY_DB_CREATED)
.getBoolean(Settings.EXTRA_VALUE, false)) {
// Only migration if a new DB was created.
return false;
}
for (ProviderInfo info : context.getPackageManager().queryContentProviders(
null, context.getApplicationInfo().uid, 0)) {
if (sourcePackage.equals(info.packageName)) {
if ((info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
// Only migrate if the source launcher is also on system image.
return false;
}
// Wait until we found a provider with matching authority.
if (sourceAuthority.equals(info.authority)) {
if (TextUtils.isEmpty(info.readPermission) ||
context.checkPermission(info.readPermission, Process.myPid(),
Process.myUid()) == PackageManager.PERMISSION_GRANTED) {
// All checks passed, run the import task.
return new ImportDataTask(context, sourceAuthority).importWorkspace();
}
}
}
}
return false;
}
示例4: checkWriteSecureSettingPermission
import android.content.Context; //導入方法依賴的package包/類
private static boolean checkWriteSecureSettingPermission(Context paramContext)
{
return paramContext.checkPermission("android.permission.WRITE_SECURE_SETTINGS", Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_GRANTED;
}
示例5: check_p1
import android.content.Context; //導入方法依賴的package包/類
public void check_p1(){
Context.checkPermission("android.permission.P1",0, 1);
}
示例6: checkSelfPermission
import android.content.Context; //導入方法依賴的package包/類
public static int checkSelfPermission(@NonNull Context context, @NonNull String permission) {
if (permission != null) {
return context.checkPermission(permission, Process.myPid(), Process.myUid());
}
throw new IllegalArgumentException("permission is null");
}
示例7: checkSelfPermission
import android.content.Context; //導入方法依賴的package包/類
private int checkSelfPermission(Context context, String permission) {
if (permission == null) {
throw new IllegalArgumentException("permission is null");
}
return context.checkPermission(permission, android.os.Process.myPid(), Process.myUid());
}
示例8: hasPermission
import android.content.Context; //導入方法依賴的package包/類
public static boolean hasPermission(Context context, String permission) {
return context.checkPermission(permission, Process.myPid(), Process.myUid())
== PackageManager.PERMISSION_GRANTED;
}
示例9: havePermission
import android.content.Context; //導入方法依賴的package包/類
public static boolean havePermission( Context c ) {
return c.checkPermission( PERMISSION_RUN_TASKS, Process.myPid(), Process.myUid() ) ==
PackageManager.PERMISSION_GRANTED;
}
示例10: check_p7
import android.content.Context; //導入方法依賴的package包/類
public void check_p7(){
Context.checkPermission("android.permission.P7");
}
示例11: check_p2
import android.content.Context; //導入方法依賴的package包/類
public void check_p2(){
Context.checkPermission("android.permission.P2",0, 1);
}
示例12: check_p1
import android.content.Context; //導入方法依賴的package包/類
public void check_p1(){
Context.checkPermission("android.permission.P1");
}
示例13: check_p2
import android.content.Context; //導入方法依賴的package包/類
public void check_p2(){
Context.checkPermission("android.permission.P2");
}
示例14: check_p3
import android.content.Context; //導入方法依賴的package包/類
public void check_p3(){
Context.checkPermission("android.permission.P3");
}
示例15: performImportIfPossible
import android.content.Context; //導入方法依賴的package包/類
/**
* Performs data import if possible.
* @return true on successful data import, false if it was not available
* @throws Exception if the import failed
*/
public static boolean performImportIfPossible(Context context) throws Exception {
SharedPreferences devicePrefs = getDevicePrefs(context);
String sourcePackage = devicePrefs.getString(KEY_DATA_IMPORT_SRC_PKG, "");
String sourceAuthority = devicePrefs.getString(KEY_DATA_IMPORT_SRC_AUTHORITY, "");
if (TextUtils.isEmpty(sourcePackage) || TextUtils.isEmpty(sourceAuthority)) {
return false;
}
// Synchronously clear the migration flags. This ensures that we do not try migration
// again and thus prevents potential crash loops due to migration failure.
devicePrefs.edit().remove(KEY_DATA_IMPORT_SRC_PKG).remove(KEY_DATA_IMPORT_SRC_AUTHORITY).commit();
if (!Settings.call(context.getContentResolver(), Settings.METHOD_WAS_EMPTY_DB_CREATED)
.getBoolean(Settings.EXTRA_VALUE, false)) {
// Only migration if a new DB was created.
return false;
}
for (ProviderInfo info : context.getPackageManager().queryContentProviders(
null, context.getApplicationInfo().uid, 0)) {
if (sourcePackage.equals(info.packageName)) {
if ((info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
// Only migrate if the source launcher is also on system image.
return false;
}
// Wait until we found a provider with matching authority.
if (sourceAuthority.equals(info.authority)) {
if (TextUtils.isEmpty(info.readPermission) ||
context.checkPermission(info.readPermission, Process.myPid(),
Process.myUid()) == PackageManager.PERMISSION_GRANTED) {
// All checks passed, run the import task.
return new ImportDataTask(context, sourceAuthority).importWorkspace();
}
}
}
}
return false;
}