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


Java Intent.FLAG_GRANT_WRITE_URI_PERMISSION属性代码示例

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


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

示例1: onActivityResult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
        case SELECT_GALLERY_PIC:
            if (data == null) return;
            // 用户从图库选择图片后会返回所选图片的Uri
            Uri uri = data.getData();
            this.headerImg.setImageURI(uri);
            saveImageUri(uri);

            // 获取永久访问图片URI的权限
            int takeFlags = data.getFlags();
            takeFlags &=(Intent.FLAG_GRANT_READ_URI_PERMISSION
                    | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            getContentResolver().takePersistableUriPermission(uri, takeFlags);
            break;
    }
}
 
开发者ID:yuukidach,项目名称:Ucount,代码行数:19,代码来源:MainActivity.java

示例2: getCallingOrSelfUriPermissionModeFlags

private static int getCallingOrSelfUriPermissionModeFlags(Context context, Uri uri) {
    // TODO: move this to a direct AMS call
    int modeFlags = 0;
    if (context.checkCallingOrSelfUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
            == PackageManager.PERMISSION_GRANTED) {
        modeFlags |= Intent.FLAG_GRANT_READ_URI_PERMISSION;
    }
    if (context.checkCallingOrSelfUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
            == PackageManager.PERMISSION_GRANTED) {
        modeFlags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
    }
    if (context.checkCallingOrSelfUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION
            | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)
            == PackageManager.PERMISSION_GRANTED) {
        modeFlags |= Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION;
    }
    return modeFlags;
}
 
开发者ID:kranthi0987,项目名称:easyfilemanager,代码行数:18,代码来源:DocumentsProvider.java

示例3: getCallingOrSelfUriPermissionModeFlags

private static int getCallingOrSelfUriPermissionModeFlags(Context context, Uri uri) {
    // TODO: move this to a direct AMS call
    int modeFlags = 0;
    if (context.checkCallingOrSelfUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
            == PackageManager.PERMISSION_GRANTED) {
        modeFlags |= Intent.FLAG_GRANT_READ_URI_PERMISSION;
    }
    if (context.checkCallingOrSelfUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
            == PackageManager.PERMISSION_GRANTED) {
        modeFlags |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
    }
    if (context.checkCallingOrSelfUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION
            | Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
            == PackageManager.PERMISSION_GRANTED) {
        modeFlags |= Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION;
    }
    return modeFlags;
}
 
开发者ID:gigabytedevelopers,项目名称:FireFiles,代码行数:18,代码来源:DocumentsProvider.java

示例4: grantPermissions

/**
 * 授权
 *
 * @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,代码行数:22,代码来源:FileProvider7.java

示例5: grantPermissions

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,代码行数:14,代码来源:AgentWebUtils.java

示例6: onActivityResult

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == LOCAL_CHOOSE_FILE_REQUEST && resultCode == RESULT_OK) {
        int flags = data.getFlags() & Intent.FLAG_GRANT_READ_URI_PERMISSION & Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION & Intent.FLAG_GRANT_WRITE_URI_PERMISSION;
        fileUri = data.getData();
        //noinspection WrongConstant
        getContentResolver().takePersistableUriPermission(fileUri, flags);
        onFileSelected();
    }
    if (requestCode == DBX_CHOOSE_FILE_REQUEST && resultCode == RESULT_OK) {
        DbxChooser.Result result = new DbxChooser.Result(data);
        fileUri = result.getLink();

        onFileSelected();
    }
    super.onActivityResult(requestCode, resultCode, data);
}
 
开发者ID:monsieurh,项目名称:homebank_android,代码行数:17,代码来源:HomeActivity.java

示例7: onActivityResult

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    if(resultCode != Activity.RESULT_OK) {
        return;
    }

    if(requestCode == CODE_CHOOSE_FILE) {
        Uri uri = intent.getData();

        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            final int takeFlags = intent.getFlags()
                    & (Intent.FLAG_GRANT_READ_URI_PERMISSION
                    | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            cordova.getActivity().getContentResolver().takePersistableUriPermission(uri, takeFlags);
        }

        callbackContext.success(asFile(uri));
        callbackContext = null;
    }

    super.onActivityResult(requestCode, resultCode, intent);
}
 
开发者ID:alex-shpak,项目名称:keemob,代码行数:23,代码来源:FileChooser.java

示例8: grantPermissions

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,代码行数:14,代码来源:FileProvider7.java

示例9: grantPermissions

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,代码行数:12,代码来源:FileProviderUtils.java

示例10: onActivityResult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG, requestCode, resultCode, data);

    switch (requestCode) {
        case ACTION_OPEN_DOCUMENT_TREE_REQUEST_CODE:
            if (resultCode == RESULT_OK) {
                Uri treeUri = data.getData();

                // Persist permissions
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                    grantUriPermission(getPackageName(), treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);

                    final int takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION |
                                          Intent.FLAG_GRANT_WRITE_URI_PERMISSION;

                    getContentResolver().takePersistableUriPermission(treeUri, takeFlags);
                }

                DirectoryRepoFragment fragment =
                        (DirectoryRepoFragment) getSupportFragmentManager()
                                .findFragmentByTag(DirectoryRepoFragment.FRAGMENT_TAG);

                fragment.updateUri(treeUri);
            }

            break;
    }
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:29,代码来源:ReposActivity.java

示例11: onActivityResult

@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (resultCode) {
        case RESULT_CANCELED:
            break;
        case RESULT_OK:
            if (requestCode == GALLERY_INTENT_CALLED || requestCode == CAMERA_CODE
                    || requestCode == GALLERY_KITKAT_INTENT_CALLED) {
                if (requestCode == GALLERY_INTENT_CALLED) {
                    selectedImageUri = data.getData();
                    selectedImagePath = getPath(selectedImageUri);
                } else if (requestCode == GALLERY_KITKAT_INTENT_CALLED) {
                    selectedImageUri = data.getData();
                    final int takeFlags = data.getFlags()
                            & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                    // Check for the freshest data.
                    if (selectedImageUri != null) {
                        getContentResolver().takePersistableUriPermission(
                                selectedImageUri, takeFlags);
                        selectedImagePath = getPath(selectedImageUri);
                    }
                } else {
                    selectedImagePath = selectedOutputPath;
                }

                if (UtilFunctions.stringIsNotEmpty(selectedImagePath)) {
                    // decode image size
                    BitmapFactory.Options o = new BitmapFactory.Options();
                    o.inJustDecodeBounds = true;
                    BitmapFactory.decodeFile(selectedImagePath, o);
                    // Find the correct scale value. It should be the power of
                    // 2.
                    int width_tmp = o.outWidth, height_tmp = o.outHeight;
                    Log.d("MediaActivity", "MediaActivity : image size : "
                            + width_tmp + " ; " + height_tmp);
                    final int MAX_SIZE = getResources().getDimensionPixelSize(
                            R.dimen.image_loader_post_width);
                    int scale = 1;
                    // while (true) {
                    // if (width_tmp / 2 < MAX_SIZE
                    // || height_tmp / 2 < MAX_SIZE)
                    // break;
                    // width_tmp /= 2;
                    // height_tmp /= 2;
                    // scale *= 2;
                    // }
                    if (height_tmp > MAX_SIZE || width_tmp > MAX_SIZE) {
                        if (width_tmp > height_tmp) {
                            scale = Math.round((float) height_tmp
                                    / (float) MAX_SIZE);
                        } else {
                            scale = Math.round((float) width_tmp
                                    / (float) MAX_SIZE);
                        }
                    }
                    Log.d("MediaActivity", "MediaActivity : scaling image by factor : " + scale);
                    BitmapFactory.Options options = new BitmapFactory.Options();
                    options.inSampleSize = scale;
                    bitmap = BitmapFactory.decodeFile(selectedImagePath, options);
                    _taken = true;
                    onPhotoTaken();
                    System.gc();
                }
            }
            break;
    }
    super.onActivityResult(requestCode, resultCode, data);
}
 
开发者ID:eventtus,项目名称:photo-editor-android,代码行数:69,代码来源:MediaActivity.java


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