本文整理汇总了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;
}