From bc99c08006570f5ee2d1c5268ff9b0897ff59567 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Thu, 23 Nov 2023 15:09:23 +0800 Subject: [PATCH] =?UTF-8?q?vue=20=E7=A4=BA=E4=BE=8B=E5=A2=9E=E5=8A=A0=20?= =?UTF-8?q?=E4=B8=89=E6=96=B9=E5=BA=94=E7=94=A8=E6=89=93=E5=BC=80=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E6=96=87=E4=BB=B6=E7=9A=84=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AndroidManifest.xml | 11 ++++++++++- pages/advance/advance.vue | 12 +++++++++++- .../uts-nativepage/utssdk/app-android/index.uts | 14 ++++++++++++++ .../utssdk/app-android/res/xml/filepaths.xml | 4 ++++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 uni_modules/uts-nativepage/utssdk/app-android/res/xml/filepaths.xml diff --git a/AndroidManifest.xml b/AndroidManifest.xml index a507756..206c240 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -5,6 +5,15 @@ - + + + + diff --git a/pages/advance/advance.vue b/pages/advance/advance.vue index 3f37c4e..b8e961b 100644 --- a/pages/advance/advance.vue +++ b/pages/advance/advance.vue @@ -27,6 +27,8 @@ quitApp, arrayConvert } from "../../uni_modules/uts-advance"; + + import {openFileWithProvider} from '../../uni_modules/uts-nativepage' export default { data() { @@ -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() diff --git a/uni_modules/uts-nativepage/utssdk/app-android/index.uts b/uni_modules/uts-nativepage/utssdk/app-android/index.uts index ca3d0ed..4191d8f 100644 --- a/uni_modules/uts-nativepage/utssdk/app-android/index.uts +++ b/uni_modules/uts-nativepage/utssdk/app-android/index.uts @@ -28,6 +28,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 { @@ -309,3 +311,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); +} + diff --git a/uni_modules/uts-nativepage/utssdk/app-android/res/xml/filepaths.xml b/uni_modules/uts-nativepage/utssdk/app-android/res/xml/filepaths.xml new file mode 100644 index 0000000..56d2226 --- /dev/null +++ b/uni_modules/uts-nativepage/utssdk/app-android/res/xml/filepaths.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file -- GitLab