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

增加 UTSAndroid.getFileProviderUri 示例

上级 ef9e71ed
...@@ -6,16 +6,6 @@ ...@@ -6,16 +6,6 @@
> >
<!--meta-data--> <!--meta-data-->
<meta-data android:name="TencentMapSDK" android:value="您申请的腾讯定位App Key" /> <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>
<activity android:name="uni.UNI70BE9D0.RootPackageActivity" <activity android:name="uni.UNI70BE9D0.RootPackageActivity"
android:launchMode="singleTask" android:launchMode="singleTask"
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
<view class="uni-hello-text"> 获取设备信息,观察是否符合预期 </view> <view class="uni-hello-text"> 获取设备信息,观察是否符合预期 </view>
</view> </view>
<button @tap="getDeviceInfoClick">获取设备基础信息</button> <button @tap="getDeviceInfoClick">获取设备基础信息</button>
<button @tap="getFileProviderUriClick">使用外部应用访问私有文件</button>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
</scroll-view> </scroll-view>
...@@ -63,6 +64,8 @@ import { ...@@ -63,6 +64,8 @@ import {
privacyStateTest, privacyStateTest,
} from '@/uni_modules/uts-platform-api' } from '@/uni_modules/uts-platform-api'
import Intent from 'android.content.Intent';
/** /**
* 测试在页面生命周期之外,使用api * 测试在页面生命周期之外,使用api
*/ */
...@@ -157,6 +160,15 @@ export default { ...@@ -157,6 +160,15 @@ export default {
}) })
} }
}, },
getFileProviderUriClick() {
let file = new java.io.File(UTSAndroid.getResourcePath("static/logo.png"))
const uri = UTSAndroid.getFileProviderUri(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);
},
getAppTempPathClick() { getAppTempPathClick() {
if (getAppTempPathTest()) { if (getAppTempPathTest()) {
uni.showToast({ uni.showToast({
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
arrayConvert arrayConvert
} from "../../uni_modules/uts-advance"; } from "../../uni_modules/uts-advance";
import {openFileWithProvider} from '../../uni_modules/uts-nativepage' import {openFileWithProvider} from '../../uni_modules/uts-advance'
export default { export default {
data() { data() {
......
...@@ -554,3 +554,13 @@ export function arrayConvert():boolean{ ...@@ -554,3 +554,13 @@ export function arrayConvert():boolean{
return true return true
} }
export function openFileWithProvider(url:String){
let file = new File(UTSAndroid.getResourcePath("static/logo.png"))
const uri = UTSAndroid.getFileProviderUri(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);
}
...@@ -327,14 +327,5 @@ export function gotoDemoActivity():boolean { ...@@ -327,14 +327,5 @@ 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);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册