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


Java Context.grantUriPermission方法代码示例

本文整理汇总了Java中android.content.Context.grantUriPermission方法的典型用法代码示例。如果您正苦于以下问题:Java Context.grantUriPermission方法的具体用法?Java Context.grantUriPermission怎么用?Java Context.grantUriPermission使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.Context的用法示例。


在下文中一共展示了Context.grantUriPermission方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: grantPermissions

import android.content.Context; //导入方法依赖的package包/类
/**
 * 授权
 *
 * @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);
    }
}
 
开发者ID:Jusenr,项目名称:AppFirCloud,代码行数:23,代码来源:FileProvider7.java

示例2: getSafeUri

import android.content.Context; //导入方法依赖的package包/类
private static Uri getSafeUri(Context context, SanitizedFile tempApkFile, boolean useContentUri) {
    if (useContentUri) {
        // return a content Uri using support libs FileProvider
        Uri apkUri = getUriForFile(context, AUTHORITY, tempApkFile);
        context.grantUriPermission("org.fdroid.fdroid.privileged", apkUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
        context.grantUriPermission("com.android.bluetooth", apkUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
        return apkUri;
    }

    // Need the apk to be world readable, so that the installer is able to read it.
    // Note that saving it into external storage for the purpose of letting the installer
    // have access is insecure, because apps with permission to write to the external
    // storage can overwrite the app between F-Droid asking for it to be installed and
    // the installer actually installing it.
    tempApkFile.setReadable(true, false);

    return Uri.fromFile(tempApkFile);
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:19,代码来源:ApkFileProvider.java

示例3: grantPermissions

import android.content.Context; //导入方法依赖的package包/类
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);
        }
    }
 
开发者ID:Justson,项目名称:AgentWeb,代码行数:15,代码来源:AgentWebUtils.java

示例4: canonicalize

import android.content.Context; //导入方法依赖的package包/类
/**
 * Implementation is provided by the parent class. Can be overridden to
 * provide additional functionality, but subclasses <em>must</em> always
 * call the superclass. If the superclass returns {@code null}, the subclass
 * may implement custom behavior.
 * <p>
 * This is typically used to resolve a subtree URI into a concrete document
 * reference, issuing a narrower single-document URI permission grant along
 * the way.
 *
 * @see android.provider.DocumentsContract#buildDocumentUriUsingTree(android.net.Uri, String)
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public Uri canonicalize(Uri uri) {
    final Context context = getContext();
    switch (mMatcher.match(uri)) {
        case MATCH_DOCUMENT_TREE:
            enforceTree(uri);

            final Uri narrowUri = buildDocumentUri(uri.getAuthority(), getDocumentId(uri));

            // Caller may only have prefix grant, so extend them a grant to
            // the narrow URI.
            final int modeFlags = getCallingOrSelfUriPermissionModeFlags(context, uri);
            if(Utils.hasKitKat()) {
                context.grantUriPermission(getCallingPackage(), narrowUri, modeFlags);
            }
            return narrowUri;
    }
    return null;
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:33,代码来源:DocumentsProvider.java

示例5: grantPermissions

import android.content.Context; //导入方法依赖的package包/类
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);
        }
    }
 
开发者ID:hongyangAndroid,项目名称:FitAndroid7,代码行数:15,代码来源:FileProvider7.java

示例6: grantPermissions

import android.content.Context; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:why168,项目名称:AndroidHttpUtils,代码行数:13,代码来源:FileProviderUtils.java

示例7: dispatchCaptureIntent

import android.content.Context; //导入方法依赖的package包/类
public void dispatchCaptureIntent(Context context, int requestCode) {
    Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (captureIntent.resolveActivity(context.getPackageManager()) != null) {
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (photoFile != null) {
            mCurrentPhotoPath = photoFile.getAbsolutePath();
            mCurrentPhotoUri = FileProvider.getUriForFile(mContext.get(),
                    mCaptureStrategy.authority, photoFile);
            captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCurrentPhotoUri);
            captureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                List<ResolveInfo> resInfoList = context.getPackageManager()
                        .queryIntentActivities(captureIntent, PackageManager.MATCH_DEFAULT_ONLY);
                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);
                }
            }
            if (mFragment != null) {
                mFragment.get().startActivityForResult(captureIntent, requestCode);
            } else {
                mContext.get().startActivityForResult(captureIntent, requestCode);
            }
        }
    }
}
 
开发者ID:sathishmscict,项目名称:Matisse-Image-and-Video-Selector,代码行数:34,代码来源:MediaStoreCompat.java

示例8: oggToCacheAndGrant

import android.content.Context; //导入方法依赖的package包/类
/**
 * Convert a raw resource to a file on the private storage
 *
 * @param ctx        the application context
 * @param resourceId the resource identifier
 * @return the file or null if the process failed
 */
public static File oggToCacheAndGrant(@NonNull final Context ctx, final int resourceId, final String packageName) {

    final String cachePath = getPrivateDirPath(ctx);

    if (UtilsString.notNaked(cachePath)) {

        final String name = ctx.getResources().getResourceEntryName(resourceId);

        final File file = resourceToFile(ctx, resourceId, new File(cachePath + SOUND_EFFECT_DIR + name
                + "." + Constants.OGG_AUDIO_FILE_SUFFIX));

        if (file != null) {
            if (DEBUG) {
                MyLog.i(CLS_NAME, "wavToCacheAndGrant file exists: " + file.exists());
                MyLog.i(CLS_NAME, "wavToCacheAndGrant file path: " + file.getAbsolutePath());
            }

            final Uri contentUri = FileProvider.getUriForFile(ctx, FILE_PROVIDER, file);
            ctx.grantUriPermission(packageName, contentUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);

            return file;
        } else {
            if (DEBUG) {
                MyLog.e(CLS_NAME, "wavToCacheAndGrant file null");
            }
        }
    } else {
        if (DEBUG) {
            MyLog.e(CLS_NAME, "wavToCacheAndGrant failed to get any path");
        }
    }

    return null;

}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:43,代码来源:UtilsFile.java

示例9: grantPermissionsToUri

import android.content.Context; //导入方法依赖的package包/类
public static void grantPermissionsToUri(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);
    }
}
 
开发者ID:UTN-FRBA-Mobile,项目名称:Clases-2017c1,代码行数:8,代码来源:SelectPictureActivity.java


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