"ui";
importClass(android.Manifest);
importClass(android.os.Environment);
importClass(android.os.Build);
let androidx = Packages.androidx;
importClass(android.net.Uri)
importClass(android.provider.DocumentsContract)
importClass(androidx.documentfile.provider.DocumentFile)
//importClass(android.support.v4.provider.DocumentFile)
importClass(java.nio.ByteBuffer)
function SystemFileManagement() {
function SystemFileManagement() {
this.ResultIntent = this.SystemResultIntent();
//初始化监听
this.ResultIntent.init();
}
//接收信息
SystemFileManagement.prototype.SystemResultIntent = function() {
return {
intentCallback: {
REQUEST_CODE_FOR_DIR: null
},
init: function() {
activity.getEventEmitter().on("activity_result", (requestCode, resultCode, data) => {
this.onActivityResult(requestCode, resultCode, data);
});
},
startActivityForResult: function(intent, callback) {
var i;
for (i = 0; i < 65536; i++) {
if (!(i in this.intentCallback)) break;
}
if (i >= 65536) {
toast("启动Intent失败:同时请求的Intent过多");
return;
}
this.intentCallback[i] = callback;
REQUEST_CODE_FOR_DIR = i;
activity.startActivityForResult(intent, i);
},
onActivityResult: function(requestCode, resultCode, data) {
var cb = this.intentCallback[requestCode];
if (!cb) return;
delete this.intentCallback[requestCode];
cb(requestCode, resultCode, data);
}
};
}
//链接转换
SystemFileManagement.prototype.PathToUri = function(path) {
return Uri.parse("content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fdata/document/primary%3A" + path.replace("/storage/emulated/0/", "").replace("/", "%2F"));
}
//获得访问data权限
SystemFileManagement.prototype.PermissionDeclaration = function(fun) {
var uri = Uri.parse("content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fdata");
var documentFile = DocumentFile.fromTreeUri(activity, uri);
var intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION |
Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION |
Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, documentFile.getUri());
//activity.startActivityForResult(intent, 8000);
this.ResultIntent.startActivityForResult(intent, function(requestCode, resultCode, data) {
//if (resultCode != activity.RESULT_OK) return;
if (data == null) {
return;
}
var url = null;
if ((uri = data.getData()) != null) {
activity.getContentResolver().takePersistableUriPermission(uri, data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION)); //保存目录的访问权限
}
});
}
//URL转换
SystemFileManagement.prototype.PathToUri = function(path) {
return Uri.parse("content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fdata/document/primary%3A" + path.replace("/storage/emulated/0/", "").replace("/", "%2F"));
}
//使用系统文件管理选择文件
SystemFileManagement.prototype.OpenPath = function(Path, FileType, fun) {
var path = AltText(Path, '/', '%2f');
var uri = Uri.parse("content://com.android.externalstorage.documents/document/primary:" + path);
var intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType(FileType); //想要展示的文件类型
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, uri);
//app.startActivity(intent);
this.ResultIntent.startActivityForResult(intent, function(requestCode, resultCode, data) {
if (resultCode != activity.RESULT_OK) return;
fun(new SystemFileManagement().URIUtils_uriToFile(data.getData()));
});
}
//转换文件路径
SystemFileManagement.prototype.URIUtils_uriToFile = function(uri) { //Source : https://www.cnblogs.com/panhouye/archive/2017/04/23/6751710.html
var r = null,
cursor, column_index, selection = null,
selectionArgs = null,
isKitKat = android.os.Build.VERSION.SDK_INT >= 19,
docs;
if (uri.getScheme().equalsIgnoreCase("content")) {
if (isKitKat && android.provider.DocumentsContract.isDocumentUri(activity, uri)) {
if (String(uri.getAuthority()) == "com.android.externalstorage.documents") {
docs = String(android.provider.DocumentsContract.getDocumentId(uri)).split(":");
if (docs[0] == "primary") {
return android.os.Environment.getExternalStorageDirectory() + "/" + docs[1];
}
} else if (String(uri.getAuthority()) == "com.android.providers.downloads.documents") {
uri = android.content.ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"),
parseInt(android.provider.DocumentsContract.getDocumentId(uri))
);
} else if (String(uri.getAuthority()) == "com.android.providers.media.documents") {
docs = String(android.provider.DocumentsContract.getDocumentId(uri)).split(":");
if (docs[0] == "image") {
uri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if (docs[0] == "video") {
uri = android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if (docs[0] == "audio") {
uri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
selection = "_id=?";
selectionArgs = [docs[1]];
}
}
try {
cursor = activity.getContentResolver().query(uri, ["_data"], selection, selectionArgs, null);
if (cursor && cursor.moveToFirst()) {
r = String(cursor.getString(cursor.getColumnIndexOrThrow("_data")));
}
} catch (e) {
log(e)
}
if (cursor) cursor.close();
return r;
} else if (uri.getScheme().equalsIgnoreCase("file")) {
return String(uri.getPath());
}
return null;
}
return new SystemFileManagement;
}
//替换字符串
function AltText(max, may, maz) {
var tun = max.split(may).join(maz);
return tun;
}
var FileManagement = new SystemFileManagement();
//获得data访问权限
FileManagement.PermissionDeclaration();
/*
//使用系统文件管理器选择文件并返回路径---非阻塞回调
FileManagement.OpenPath("/脚本/", "text/*", function(FilePath) {
log(FilePath)
});
*/
//log(context.checkSelfPermission)
/*
类型介绍
image/jpeg
audio/mpeg4-generic
text/html
audio/mpeg
audio/aac
audio/wav
audio/ogg
audio/midi
audio/x-ms-wma
video/mp4
video/x-msvideo
video/x-ms-wmv
image/png
image/jpeg
image/gif
.xml ->text/xml
.txt -> text/plain
.cfg -> text/plain
.csv -> text/plain
.conf -> text/plain
.rc -> text/plain
.htm -> text/html
.html -> text/html
.pdf -> application/pdf
.apk -> application/vnd.android.package-archive
DOC = “application/msword”
DOCX = “application/vnd.openxmlfor
没有合适的资源?快使用搜索试试~ 我知道了~
系统文件管理类-1.0.0.0.zip
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共3个文件
png:1个
json:1个
js:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
需积分: 5 0 下载量 31 浏览量
2024-05-23
17:48:37
上传
评论
收藏 15KB ZIP 举报
温馨提示
用autojs写的安卓手机系统文件管理
资源推荐
资源详情
资源评论
![rm5](https://img-home.csdnimg.cn/images/20210720083646.png)
![rm2](https://img-home.csdnimg.cn/images/20210720083646.png)
![rm4](https://img-home.csdnimg.cn/images/20210720083646.png)
![rm1](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![img](https://img-home.csdnimg.cn/images/20210720083646.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 3 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
h3009nie
- 粉丝: 0
- 资源: 12
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)