本文整理汇总了Java中android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION属性的典型用法代码示例。如果您正苦于以下问题:Java Intent.FLAG_GRANT_READ_URI_PERMISSION属性的具体用法?Java Intent.FLAG_GRANT_READ_URI_PERMISSION怎么用?Java Intent.FLAG_GRANT_READ_URI_PERMISSION使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.content.Intent
的用法示例。
在下文中一共展示了Intent.FLAG_GRANT_READ_URI_PERMISSION属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case SELECT_GALLERY_PIC:
if (data == null) return;
// 用户从图库选择图片后会返回所选图片的Uri
Uri uri = data.getData();
this.headerImg.setImageURI(uri);
saveImageUri(uri);
// 获取永久访问图片URI的权限
int takeFlags = data.getFlags();
takeFlags &=(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
getContentResolver().takePersistableUriPermission(uri, takeFlags);
break;
}
}
示例2: getCallingOrSelfUriPermissionModeFlags
private static int getCallingOrSelfUriPermissionModeFlags(Context context, Uri uri) {
// TODO: move this to a direct AMS call
int modeFlags = 0;
if (context.checkCallingOrSelfUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
== PackageManager.PERMISSION_GRANTED) {
modeFlags |= Intent.FLAG_GRANT_READ_URI_PERMISSION;
}
if (context.checkCallingOrSelfUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
== PackageManager.PERMISSION_GRANTED) {
modeFlags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
}
if (context.checkCallingOrSelfUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)
== PackageManager.PERMISSION_GRANTED) {
modeFlags |= Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION;
}
return modeFlags;
}
示例3: getCallingOrSelfUriPermissionModeFlags
private static int getCallingOrSelfUriPermissionModeFlags(Context context, Uri uri) {
// TODO: move this to a direct AMS call
int modeFlags = 0;
if (context.checkCallingOrSelfUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
== PackageManager.PERMISSION_GRANTED) {
modeFlags |= Intent.FLAG_GRANT_READ_URI_PERMISSION;
}
if (context.checkCallingOrSelfUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
== PackageManager.PERMISSION_GRANTED) {
modeFlags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
}
if (context.checkCallingOrSelfUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
== PackageManager.PERMISSION_GRANTED) {
modeFlags |= Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION;
}
return modeFlags;
}
示例4: grantPermissions
/**
* 授权
*
* @param context
* @param intent
* @param uri
* @param writeAble
*/
public static void grantPermissions(Context context, Intent intent, Uri uri, boolean writeAble) {
int flag = Intent.FLAG_GRANT_READ_URI_PERMISSION;
if (writeAble) {
flag |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
}
intent.addFlags(flag);
List<ResolveInfo> resInfoList = context.getPackageManager()
.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
context.grantUriPermission(packageName, uri, flag);
}
}
示例5: grantPermissions
static void grantPermissions(Context context, Intent intent, Uri uri, boolean writeAble) {
int flag = Intent.FLAG_GRANT_READ_URI_PERMISSION;
if (writeAble) {
flag |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
}
intent.addFlags(flag);
List<ResolveInfo> resInfoList = context.getPackageManager()
.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
context.grantUriPermission(packageName, uri, flag);
}
}
示例6: onActivityResult
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == LOCAL_CHOOSE_FILE_REQUEST && resultCode == RESULT_OK) {
int flags = data.getFlags() & Intent.FLAG_GRANT_READ_URI_PERMISSION & Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION & Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
fileUri = data.getData();
//noinspection WrongConstant
getContentResolver().takePersistableUriPermission(fileUri, flags);
onFileSelected();
}
if (requestCode == DBX_CHOOSE_FILE_REQUEST && resultCode == RESULT_OK) {
DbxChooser.Result result = new DbxChooser.Result(data);
fileUri = result.getLink();
onFileSelected();
}
super.onActivityResult(requestCode, resultCode, data);
}
示例7: onActivityResult
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if(resultCode != Activity.RESULT_OK) {
return;
}
if(requestCode == CODE_CHOOSE_FILE) {
Uri uri = intent.getData();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
final int takeFlags = intent.getFlags()
& (Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
cordova.getActivity().getContentResolver().takePersistableUriPermission(uri, takeFlags);
}
callbackContext.success(asFile(uri));
callbackContext = null;
}
super.onActivityResult(requestCode, resultCode, intent);
}
示例8: grantPermissions
public static void grantPermissions(Context context, Intent intent, Uri uri, boolean writeAble) {
int flag = Intent.FLAG_GRANT_READ_URI_PERMISSION;
if (writeAble) {
flag |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
}
intent.addFlags(flag);
List<ResolveInfo> resInfoList = context.getPackageManager()
.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
context.grantUriPermission(packageName, uri, flag);
}
}
示例9: grantPermissions
public static void grantPermissions(Context context, Intent intent, Uri uri, boolean writeAble) {
int flag = Intent.FLAG_GRANT_READ_URI_PERMISSION;
if (writeAble) {
flag |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
}
intent.addFlags(flag);
List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
context.grantUriPermission(packageName, uri, flag);
}
}
示例10: onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, requestCode, resultCode, data);
switch (requestCode) {
case ACTION_OPEN_DOCUMENT_TREE_REQUEST_CODE:
if (resultCode == RESULT_OK) {
Uri treeUri = data.getData();
// Persist permissions
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
grantUriPermission(getPackageName(), treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
final int takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION |
Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
getContentResolver().takePersistableUriPermission(treeUri, takeFlags);
}
DirectoryRepoFragment fragment =
(DirectoryRepoFragment) getSupportFragmentManager()
.findFragmentByTag(DirectoryRepoFragment.FRAGMENT_TAG);
fragment.updateUri(treeUri);
}
break;
}
}
示例11: ensureUriPermission
@SuppressWarnings("ResourceType")
@TargetApi(Build.VERSION_CODES.KITKAT)
public static Uri ensureUriPermission(Context context, Intent intent) {
Uri uri = intent.getData();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
final int takeFlags = intent.getFlags() & Intent.FLAG_GRANT_READ_URI_PERMISSION;
context.getContentResolver().takePersistableUriPermission(uri, takeFlags);
}
return uri;
}
示例12: onActivityResult
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (resultCode) {
case RESULT_CANCELED:
break;
case RESULT_OK:
if (requestCode == GALLERY_INTENT_CALLED || requestCode == CAMERA_CODE
|| requestCode == GALLERY_KITKAT_INTENT_CALLED) {
if (requestCode == GALLERY_INTENT_CALLED) {
selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
} else if (requestCode == GALLERY_KITKAT_INTENT_CALLED) {
selectedImageUri = data.getData();
final int takeFlags = data.getFlags()
& (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
// Check for the freshest data.
if (selectedImageUri != null) {
getContentResolver().takePersistableUriPermission(
selectedImageUri, takeFlags);
selectedImagePath = getPath(selectedImageUri);
}
} else {
selectedImagePath = selectedOutputPath;
}
if (UtilFunctions.stringIsNotEmpty(selectedImagePath)) {
// decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeFile(selectedImagePath, o);
// Find the correct scale value. It should be the power of
// 2.
int width_tmp = o.outWidth, height_tmp = o.outHeight;
Log.d("MediaActivity", "MediaActivity : image size : "
+ width_tmp + " ; " + height_tmp);
final int MAX_SIZE = getResources().getDimensionPixelSize(
R.dimen.image_loader_post_width);
int scale = 1;
// while (true) {
// if (width_tmp / 2 < MAX_SIZE
// || height_tmp / 2 < MAX_SIZE)
// break;
// width_tmp /= 2;
// height_tmp /= 2;
// scale *= 2;
// }
if (height_tmp > MAX_SIZE || width_tmp > MAX_SIZE) {
if (width_tmp > height_tmp) {
scale = Math.round((float) height_tmp
/ (float) MAX_SIZE);
} else {
scale = Math.round((float) width_tmp
/ (float) MAX_SIZE);
}
}
Log.d("MediaActivity", "MediaActivity : scaling image by factor : " + scale);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = scale;
bitmap = BitmapFactory.decodeFile(selectedImagePath, options);
_taken = true;
onPhotoTaken();
System.gc();
}
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}