let REQUESTCODE = 1;
let main = plus.android.runtimeMainActivity();
// 导入android.content.Intent类对象
let Intent = plus.android.importClass('android.content.Intent');
// 导入后可以使用new方法创建类的实例对象
let intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");//设置类型,任意类型
// intent.setType("image/*");
//intent.setType("audio/*"); //选择音频
//intent.setType("video/;image/*"); //选择视频 (mp4 3gp 是android支持的视频格式)
intent.addCategory(Intent.CATEGORY_OPENABLE);
main.startActivityForResult(intent,REQUESTCODE);
main.onActivityResult = function(requestCode, resultCode, data) {
if (REQUESTCODE == requestCode) {
let context = main;
console.log(JSON.stringify(context))
plus.android.importClass(data);
// 获得文件路径
let fileData = data.getData();
console.log(JSON.stringify(fileData))
let path = plus.android.invoke(fileData, "getPath");
console.log("path:"+path);
// 判断文件类型
let resolver = context.getContentResolver();
let fileType = plus.android.invoke(resolver, "getType",fileData);
console.log("fileType:"+fileType);
}
}