當前位置: 首頁>>代碼示例>>Java>>正文


Java Context.checkPermission方法代碼示例

本文整理匯總了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;
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:13,代碼來源:HttpNegotiateAuthenticator.java

示例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;
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:29,代碼來源:PickImageInfo.java

示例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;
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:46,代碼來源:ImportDataTask.java

示例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;
}
 
開發者ID:l465659833,項目名稱:Bigbang,代碼行數:5,代碼來源:GetAwayNotificationListenerService.java

示例5: check_p1

import android.content.Context; //導入方法依賴的package包/類
public void check_p1(){
 Context.checkPermission("android.permission.P1",0, 1); 
}
 
開發者ID:Alexandre-Bartel,項目名稱:permission-map,代碼行數:4,代碼來源:Ep1.java

示例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");
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:7,代碼來源:ContextCompat.java

示例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());
}
 
開發者ID:villela,項目名稱:flutter_qrcode_reader,代碼行數:7,代碼來源:QRCodeReaderPlugin.java

示例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;
}
 
開發者ID:Piasy,項目名稱:AppRTC-Android,代碼行數:5,代碼來源:WebRtcAudioUtils.java

示例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;
}
 
開發者ID:Rai220,項目名稱:Telephoto,代碼行數:5,代碼來源:TaskerIntent.java

示例10: check_p7

import android.content.Context; //導入方法依賴的package包/類
public void check_p7(){
 Context.checkPermission("android.permission.P7"); 
}
 
開發者ID:Alexandre-Bartel,項目名稱:permission-map,代碼行數:4,代碼來源:C.java

示例11: check_p2

import android.content.Context; //導入方法依賴的package包/類
public void check_p2(){
 Context.checkPermission("android.permission.P2",0, 1); 
}
 
開發者ID:Alexandre-Bartel,項目名稱:permission-map,代碼行數:4,代碼來源:Ep1.java

示例12: check_p1

import android.content.Context; //導入方法依賴的package包/類
public void check_p1(){
 Context.checkPermission("android.permission.P1"); 
}
 
開發者ID:Alexandre-Bartel,項目名稱:permission-map,代碼行數:4,代碼來源:C.java

示例13: check_p2

import android.content.Context; //導入方法依賴的package包/類
public void check_p2(){
 Context.checkPermission("android.permission.P2"); 
}
 
開發者ID:Alexandre-Bartel,項目名稱:permission-map,代碼行數:4,代碼來源:C.java

示例14: check_p3

import android.content.Context; //導入方法依賴的package包/類
public void check_p3(){
 Context.checkPermission("android.permission.P3"); 
}
 
開發者ID:Alexandre-Bartel,項目名稱:permission-map,代碼行數:4,代碼來源:C.java

示例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;
}
 
開發者ID:TeamBrainStorm,項目名稱:SimpleUILauncher,代碼行數:47,代碼來源:ImportDataTask.java


注:本文中的android.content.Context.checkPermission方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。