提交 fae997b6 编写于 作者: 杜庆泉's avatar 杜庆泉

vue 示例增加 三方应用打开本地文件的示例

上级 e007912d
......@@ -5,6 +5,15 @@
<application>
<!--meta-data-->
<meta-data android:name="TencentMapSDK" android:value="您申请的腾讯定位App Key" />
<!--fileprovider注册,请注意authorities 需要替换为自己的唯一标识-->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="io.dcloud.hellouts.uts_nativepage.fileprovider"
android:grantUriPermissions="true"
android:exported="false">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>
</application>
</manifest>
......@@ -28,6 +28,8 @@
arrayConvert
} from "../../uni_modules/uts-advance";
import {openFileWithProvider} from '../../uni_modules/uts-nativepage'
export default {
data() {
return {
......@@ -81,7 +83,12 @@
}, {
name: "播放asset音频(需自定义基座)",
url: "advance/android/assetaudio"
}, {
},
{
name: "使用三方应用打开项目文件(需自定义基座)",
function: "testOpenFileWithProvider"
},
{
name: "操作DecorView",
url: "advance/android/decorview"
}, {
......@@ -215,6 +222,9 @@
},
testQuitApp() {
quitApp()
},
testOpenFileWithProvider() {
openFileWithProvider("apps/__UNI__70BE9D0/www/static/logo.png")
},
testArrayConvert() {
let convertRet = arrayConvert()
......
......@@ -27,6 +27,8 @@ import LayoutInflater from 'android.view.LayoutInflater';
import LinearLayoutManager from 'androidx.recyclerview.widget.LinearLayoutManager';
export {DoAppWidget} from "./DoAppWidget.uts"
import Application from 'android.app.Application';
import File from 'java.io.File';
import Uri from 'android.net.Uri';
export class AppHookProxy implements UTSAndroidHookProxy {
......@@ -307,3 +309,15 @@ export function gotoDemoActivity():boolean {
}
export function openFileWithProvider(url:String){
let file = new File(UTSAndroid.getResourcePath("static/logo.png"))
// 这里的 io.dcloud.hellouts.uts_nativepage.fileprovider 应该是你唯一的fileprovider 标识
const uri = androidx.core.content.FileProvider.getUriForFile(UTSAndroid.getUniActivity()!,"io.dcloud.hellouts.uts_nativepage.fileprovider",file)
console.log("uri",uri.toString())
const intent = new Intent(Intent.ACTION_VIEW, uri)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) // 添加权限标志
const context = UTSAndroid.getUniActivity()!;
context.startActivity(intent);
}
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path name="external" path="." />
</paths>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册