当前位置: 首页>>代码示例>>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;未经允许,请勿转载。