config.json
{
"name": "ohos.data.file.FileAbility",
"icon": "$media:icon",
"type": "data",
"uri": "dataability://ohos.data.file.FileAbility",
"grantPermission": true
}
image.png
fileability.json
{
"paths": [
{
"tag": "fileability-external-path",
"name": "external_storage_root",
"path": "."
},
{
"tag": "fileability-files-path",
"name": "files-path",
"path": "."
},
{
"tag": "fileability-cache-path",
"name": "external_file_path",
"path": "."
},
{
"tag": "fileability-external-cache-path",
"name": "external_cache_path",
"path": "."
},
{
"tag": "fileability-root-path",
"name": "root-path",
"path": "."
}
]
}
代码
{
try {
//获取文件类型
String type = getMIMEType(file);
Intent intent = new Intent();
intent.setType(type);
Uri fileUri = FileAbility.getUriViaFile(mContext, "/ohos.data.file.FileAbility", file);
Operation operation = new Intent.OperationBuilder()
.withAction(IntentConstants.ACTION_VIEW_DATA)
.withFlags(Intent.FLAG_ABILITY_NEW_MISSION)
.withUri(fileUri).build();
intent.setOperation(operation);
mContext.startAbility(intent, 0);
} catch (Exception e) {
Log.e(TAG, "openFile: " + e.getMessage());
}
}
网友评论