本文整理了Java中android.content.Context.grantUriPermission()
方法的一些代码示例,展示了Context.grantUriPermission()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.grantUriPermission()
方法的具体详情如下:
包路径:android.content.Context
类名称:Context
方法名:grantUriPermission
暂无
代码示例来源:origin: oasisfeng/condom
@Override public void grantUriPermission(String toPackage, Uri uri, int modeFlags) {
mBase.grantUriPermission(toPackage, uri, modeFlags);
}
代码示例来源:origin: Justson/AgentWeb
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);
}
}
代码示例来源:origin: ACRA/acra
private void grantPermission(@NonNull Context context, @NonNull Intent intent, String packageName, @NonNull List<Uri> attachments) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
} else {
//flags do not work on extras prior to lollipop, so we have to grant read permissions manually
for (Uri uri : attachments) {
context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
}
代码示例来源:origin: zhihu/Matisse
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
context.grantUriPermission(packageName, mCurrentPhotoUri,
Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
代码示例来源:origin: Trumeet/MiPushFramework
@Override public void grantUriPermission(String toPackage, Uri uri, int modeFlags) {
mBase.grantUriPermission(toPackage, uri, modeFlags);
}
代码示例来源:origin: jkwiecien/EasyImage
private static void grantWritePermission(@NonNull Context context, Intent intent, Uri uri) {
List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
代码示例来源:origin: a-voyager/AutoInstaller
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri contentUri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileProvider", file);
mContext.grantUriPermission(mContext.getPackageName(), contentUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
} else {
代码示例来源:origin: klinker41/android-smsmms
private void grantUriPermission(Context context, Uri contentUri) {
context.grantUriPermission(context.getPackageName() + ".MmsFileProvider",
contentUri,
Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
}
代码示例来源:origin: nguyenhoanglam/ImagePicker
public static void grantAppPermission(Context context, Intent intent, Uri fileUri) {
List<ResolveInfo> resolvedIntentActivities = context.getPackageManager()
.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolvedIntentInfo : resolvedIntentActivities) {
String packageName = resolvedIntentInfo.activityInfo.packageName;
context.grantUriPermission(packageName, fileUri,
Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
代码示例来源:origin: amahi/android
private void grantUriPermission(Intent intent, Uri fileUri) {
List<ResolveInfo> resolvedIntentActivities = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolvedIntentInfo : resolvedIntentActivities) {
String packageName = resolvedIntentInfo.activityInfo.packageName;
context.grantUriPermission(packageName, fileUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
代码示例来源:origin: esafirm/android-image-picker
public static void grantAppPermission(Context context, Intent intent, Uri fileUri) {
List<ResolveInfo> resolvedIntentActivities = context.getPackageManager()
.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolvedIntentInfo : resolvedIntentActivities) {
String packageName = resolvedIntentInfo.activityInfo.packageName;
context.grantUriPermission(packageName, fileUri,
Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
代码示例来源:origin: hongyangAndroid/FitAndroid7
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);
}
}
代码示例来源:origin: zendesk/belvedere
/**
* Grant all Apps that are resolved through the provided {@link Intent} permissions to the file
* behind the provided {@link Uri}
*
* @param context A valid application {@link Context}
* @param intent An {@link Intent}
* @param uri An {@link Uri} to a file, managed by our {@link BelvedereFileProvider}
* @param permission Permission that should be granted to the Apps, opened by the provided Intent
*/
void grantPermissionsForUri(Context context, Intent intent, Uri uri, int permission) {
List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
context.grantUriPermission(packageName, uri, permission);
}
}
代码示例来源:origin: Hu12037102/MediaSelector
public static Uri fileToUri(@NonNull Context context, @NonNull File file, @NonNull Intent intent) {
Uri uri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
String authority = context.getPackageName() + ".provider";
uri = FileProvider.getUriForFile(context, authority, file);
List<ResolveInfo> resolveInfoData = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfoData != null && resolveInfoData.size() > 0)
for (ResolveInfo resolveInfo : resolveInfoData) {
String packageName = resolveInfo.activityInfo.packageName;
context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
}
} else {
uri = Uri.fromFile(file);
}
return uri;
}
代码示例来源:origin: Hu12037102/ImageCompress
public static Uri fileToUri(@NonNull Context context, @NonNull File file, @NonNull Intent intent) {
Uri uri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
String authority = context.getPackageName() + ".provider";
uri = FileProvider.getUriForFile(context, authority, file);
List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfos != null && resolveInfos.size() > 0)
for (ResolveInfo resolveInfo : resolveInfos) {
String packageName = resolveInfo.activityInfo.packageName;
context.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
}
} else {
uri = Uri.fromFile(file);
}
return uri;
}
代码示例来源:origin: miguelbcr/RxPaparazzo
/**
* Workaround for Android bug.<br/>
* See https://code.google.com/p/android/issues/detail?id=76683 <br/>
* See http://stackoverflow.com/questions/18249007/how-to-use-support-fileprovider-for-sharing-content-to-other-apps
*/
private static void grantFileReadWritePermissions(TargetUi targetUi, Intent intent, Uri uri) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
List<ResolveInfo> resInfoList = targetUi.getContext()
.getPackageManager()
.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
targetUi.getContext().grantUriPermission(packageName, uri, READ_WRITE_PERMISSIONS);
}
}
}
代码示例来源:origin: miguelbcr/RxPaparazzo
public static void grantReadPermissionToUri(TargetUi targetUi, Uri uri) {
String uiPackageName = targetUi.getContext().getPackageName();
targetUi.getContext().grantUriPermission(uiPackageName, uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
代码示例来源:origin: stkent/bugshaker-android
private void sendEmailWithScreenshot(
@NonNull final Activity activity,
@NonNull final Uri screenshotUri) {
final Intent feedbackEmailIntent = feedbackEmailIntentProvider.getFeedbackEmailIntent(
emailAddresses,
emailSubjectLine,
screenshotUri);
final List<ResolveInfo> resolveInfoList = applicationContext.getPackageManager()
.queryIntentActivities(feedbackEmailIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (final ResolveInfo receivingApplicationInfo: resolveInfoList) {
// FIXME: revoke these permissions at some point!
applicationContext.grantUriPermission(
receivingApplicationInfo.activityInfo.packageName,
screenshotUri,
Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
activity.startActivity(feedbackEmailIntent);
logger.d("Sending email with screenshot.");
}
代码示例来源:origin: YancyYe/GalleryPick
/**
* 选择相机
*/
private void showCameraAction() {
// 跳转到系统照相机
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraIntent.resolveActivity(mActivity.getPackageManager()) != null) {
// 设置系统相机拍照后的输出路径
// 创建临时文件
cameraTempFile = FileUtils.createTmpFile(mActivity, galleryConfig.getFilePath());
Uri imageUri = FileProvider.getUriForFile(mContext, galleryConfig.getProvider(), cameraTempFile);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
cameraIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
List<ResolveInfo> resInfoList = mContext.getPackageManager().queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
mContext.grantUriPermission(packageName, imageUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
startActivityForResult(cameraIntent, REQUEST_CAMERA);
} else {
Toast.makeText(mContext, R.string.gallery_msg_no_camera, Toast.LENGTH_SHORT).show();
galleryConfig.getIHandlerCallBack().onError();
}
}
代码示例来源:origin: RameshBhupathi/ImagePicker-OLX
private void startCameraIntent() {
Intent cameraInent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (cameraInent.resolveActivity(getActivity().getPackageManager()) == null) {
errorMessage("This Application do not have Camera Application");
return;
}
File imageFile = getImageFile();
Uri photoURI = FileProvider.getUriForFile(getContext(), getContext().getApplicationContext().getPackageName() + ".provider", imageFile);
List<ResolveInfo> resolvedIntentActivities = getContext().getPackageManager().queryIntentActivities(cameraInent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolvedIntentInfo : resolvedIntentActivities) {
String packageName = resolvedIntentInfo.activityInfo.packageName;
getContext().grantUriPermission(packageName, photoURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
cameraInent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(cameraInent, REQ_CODE_CAMERA);
}
内容来源于网络,如有侵权,请联系作者删除!