「Android」使用SAF打开指定目录
「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.
*
* 【「Android」使用SAF打开指定目录】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
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...
推荐阅读
- android第三方框架(五)ButterKnife
- Android中的AES加密-下
- 八、「料理风云」
- 带有Hilt的Android上的依赖注入
- 「#1-颜龙武」区块链的价值是什么()
- 《深度倾听》第5天──「RIA学习力」便签输出第16期
- android|android studio中ndk的使用
- 「按键精灵安卓版」关于全分辨率脚本的一些理解(非游戏app)
- Android事件传递源码分析
- RxJava|RxJava 在Android项目中的使用(一)