当前位置: 首页>>代码示例>>Java>>正文


Java Activity.grantUriPermission方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:piskula,项目名称:FuelUp,代码行数:18,代码来源:GenericFileProvider.java

示例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;
    }
 
开发者ID:liying2008,项目名称:Simpler,代码行数:38,代码来源:CommonUtils.java

示例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);
                        }
    }
}
 
开发者ID:rosberry,项目名称:media-picker-android,代码行数:10,代码来源:CameraPicker.java


注:本文中的android.app.Activity.grantUriPermission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。