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