「Android」使用SAF打开指定目录

配置读写权限

AndroidManifest

        

使用SAF打开指定目录

使用SAF打开微信下载目录Demo

    void openWeChatDownloadDirectory() {        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);        Uri weChatUri = Uri.parse("content://com.android.externalstorage.documents/document/primary%3AAndroid%2Fdata%2Fcom.tencent.mm%2FMicroMsg%2FDownload");        intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, weChatUri);        intent.setType("*/*");        String[] mimeTypes = {                "application/msword",                "application/vnd.openxmlformats-officedocument.wordprocessingml.document",                "application/vnd.ms-powerpoint",                "application/vnd.openxmlformats-officedocument.presentationml.presentation",                "application/vnd.ms-excel",                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",                "application/pdf"        };        intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);        startActivityForResult(intent, REQUEST_CODE);    }

EXTRA_INITIAL_URI

    /**     * Sets the desired initial location visible to user when file chooser is shown.     *     * 

Applicable to {@link Intent} with actions: *

    *
  • {@link Intent#ACTION_OPEN_DOCUMENT}
  • *
  • {@link Intent#ACTION_CREATE_DOCUMENT}
  • *
  • {@link Intent#ACTION_OPEN_DOCUMENT_TREE}
  • *
* *

Location should specify a document URI or a tree URI with document ID. If * this URI identifies a non-directory, document navigator will attempt to use the parent * of the document as the initial location. * *

The initial location is system specific if this extra is missing or document navigator * failed to locate the desired initial location. */ public static final String EXTRA_INITIAL_URI = "android.provider.extra.INITIAL_URI";

ACTION_OPEN_DOCUMENT

    /**     * Activity Action: Allow the user to select and return one or more existing     * documents. When invoked, the system will display the various     * {@link DocumentsProvider} instances installed on the device, letting the     * user interactively navigate through them. These documents include local     * media, such as photos and video, and documents provided by installed     * cloud storage providers.     * 

* Each document is represented as a {@code content://} URI backed by a * {@link DocumentsProvider}, which can be opened as a stream with * {@link ContentResolver#openFileDescriptor(Uri, String)}, or queried for * {@link android.provider.DocumentsContract.Document} metadata. *

* All selected documents are returned to the calling application with * persistable read and write permission grants. If you want to maintain * access to the documents across device reboots, you need to explicitly * take the persistable permissions using * {@link ContentResolver#takePersistableUriPermission(Uri, int)}. *

* Callers must indicate the acceptable document MIME types through * {@link #setType(String)}. For example, to select photos, use * {@code image/*}. If multiple disjoint MIME types are acceptable, define * them in {@link #EXTRA_MIME_TYPES} and {@link #setType(String)} to * {@literal *}/*. *

* If the caller can handle multiple returned items (the user performing * multiple selection), then you can specify {@link #EXTRA_ALLOW_MULTIPLE} * to indicate this. *

* Callers must include {@link #CATEGORY_OPENABLE} in the Intent to obtain * URIs that can be opened with * {@link ContentResolver#openFileDescriptor(Uri, String)}. *

* Callers can set a document URI through * {@link DocumentsContract#EXTRA_INITIAL_URI} to indicate the initial * location of documents navigator. System will do its best to launch the * navigator in the specified document if it's a folder, or the folder that * contains the specified document if not. *

* Output: The URI of the item that was picked, returned in * {@link #getData()}. This must be a {@code content://} URI so that any * receiver can access it. If multiple documents were selected, they are * returned in {@link #getClipData()}. * * @see DocumentsContract * @see #ACTION_OPEN_DOCUMENT_TREE * @see #ACTION_CREATE_DOCUMENT * @see #FLAG_GRANT_PERSISTABLE_URI_PERMISSION */ @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) public static final String ACTION_OPEN_DOCUMENT = "android.intent.action.OPEN_DOCUMENT";

常见App的目录

微信

微信7.0.15及以上版本:
图片及视频:文件管理 > 浏览 > 我的手机 > Pictures > WeiXin
文档:文件管理 > 浏览 > 我的手机(或存储卡) > Android > data > com.tencent.mm > MicroMsg > Download

QQ

QQ8.2.8及以上版本:
图片:文件管理 > 浏览 > 我的手机(或存储卡) > tencent > QQ_Images
视频:文件管理 > 浏览 > 我的手机(或存储卡) > Movies
文件:文件管理 > 浏览 > 我的手机(或存储卡) > Android > data > com.tencent.mobileqq > Tencent > QQfile_recv

QQ浏览器

文件管理 > 浏览 > 我的手机 > QQBrowser

自带浏览器

文件管理 > 浏览 > 我的手机(或存储卡) > Download,进入Download目录以及Download/browser下查找下载的文件

百度云盘

文件管理 > 浏览 > 我的手机(或存储卡) > BaiduNetdisk

WPS

文件管理 > 浏览 > 我的手机 > Android > data > cn.wps.moffice_eng目录下查找下载的文件

更多内容请参考: https://consumer.huawei.com/c...

更多相关文章

  1. 【Android】简单图片浏览器
  2. 获取Android(安卓)手机屏幕宽度和高度以及获取Android手机序列号
  3. ReactNative 命令生成bundle文件
  4. Android加速度传感器实现“摇一摇”,带手机振动
  5. 用Javascript判断访问来源操作系统, 设备, 浏览器类型
  6. Android(安卓)手机存储文件各种路径
  7. Android(安卓)library projects cannot be launched
  8. android:向手机卡上写入文件时总是不成功,解决办法
  9. android adb am命令

随机推荐

  1. Android HIDL 简介
  2. 解决Android启动显示空白界面的问题
  3. UI设计
  4. Android Studio 无法引用org.apache.http
  5. android-pickerview-master的导入
  6. OpenGL ES教程IV之着色(原文对照)
  7. Android 加载.gif格式图片
  8. Androidの通过查询电话号码或ID获取联系
  9. Android 自定义视图
  10. Android中AsyncTask异步加载