共计 4266 个字符,预计需要花费 11 分钟才能阅读完成。
「Android」应用 SAF 关上指定目录
配置读写权限
AndroidManifest
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
应用 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.
*
* <p>Applicable to {@link Intent} with actions:
* <ul>
* <li>{@link Intent#ACTION_OPEN_DOCUMENT}</li>
* <li>{@link Intent#ACTION_CREATE_DOCUMENT}</li>
* <li>{@link Intent#ACTION_OPEN_DOCUMENT_TREE}</li>
* </ul>
*
* <p>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.
*
* <p>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.
* <p>
* 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.
* <p>
* 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)}.
* <p>
* 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 *}/*.
* <p>
* If the caller can handle multiple returned items (the user performing
* multiple selection), then you can specify {@link #EXTRA_ALLOW_MULTIPLE}
* to indicate this.
* <p>
* Callers must include {@link #CATEGORY_OPENABLE} in the Intent to obtain
* URIs that can be opened with
* {@link ContentResolver#openFileDescriptor(Uri, String)}.
* <p>
* 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.
* <p>
* 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…
正文完