當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。