本文整理匯總了Java中android.app.Activity.grantUriPermission方法的典型用法代碼示例。如果您正苦於以下問題:Java Activity.grantUriPermission方法的具體用法?Java Activity.grantUriPermission怎麽用?Java Activity.grantUriPermission使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.app.Activity
的用法示例。
在下文中一共展示了Activity.grantUriPermission方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: grantUriPermission
import android.app.Activity; //導入方法依賴的package包/類
/**
* Grants URI permissions to all applications which can respond to given intent
*
* @param ctx
* @param intent
* @param uri
* @param permissionFlags
*/
public static void grantUriPermission(Activity ctx, Intent intent, Uri uri, int permissionFlags) {
List<ResolveInfo> resolvedIntentActivities = ctx.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolvedIntentInfo : resolvedIntentActivities) {
String packageName = resolvedIntentInfo.activityInfo.packageName;
ctx.grantUriPermission(packageName, uri, permissionFlags);
}
}
示例2: capture
import android.app.Activity; //導入方法依賴的package包/類
/**
* 拍照
*/
public static String capture(Activity activity, int requestCode) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String picName = null;
if (cameraIntent.resolveActivity(activity.getPackageManager()) != null) {
if (BaseConfig.sSDCardExist) {
picName = Environment.getExternalStorageDirectory().getAbsolutePath() +
File.separator + Environment.DIRECTORY_DCIM + File.separator +
"Camera" + File.separator + activity.getString(R.string.app_name) +
"_" + System.currentTimeMillis() + ".jpg";
} else {
picName = activity.getCacheDir().getPath() + File.separator +
activity.getString(R.string.app_name) + "_" + System.currentTimeMillis() + ".jpg";
}
File photoFile = new File(picName);
// FileUtils.createFile(photoFile);
Uri uri = FileProvider.getUriForFile(activity,
App.getInstance().getApplicationId() + ".provider", photoFile);
List<ResolveInfo> resInfoList = activity.getPackageManager()
.queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
activity.grantUriPermission(packageName, uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION
| Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
activity.startActivityForResult(cameraIntent, requestCode);
} else {
AppToast.showToast(R.string.open_camera_failure);
}
return picName;
}
示例3: grantReadWritePermission
import android.app.Activity; //導入方法依賴的package包/類
private void grantReadWritePermission(Activity activity, Uri externalUri) {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
List<ResolveInfo> resInfoList = activity.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
activity.grantUriPermission(packageName, externalUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
}
}