提交 ee7e62aa 编写于 作者: W wanganxp

完善file示例;补充截图分享示例

上级 70d47a8f
......@@ -40,10 +40,10 @@
<view class="uni-padding-wrap">
<view class="uni-btn-v">
<button class="uni-btn btn-getStorageInfoASync" type="primary" @tap="getStorageInfo">
获取存储概述-异步
获取存储概述信息-异步
</button>
<button class="uni-btn btn-getStorageInfoSync" @tap="getStorageInfoSync">
获取存储概述-同步
获取存储概述信息-同步
</button>
</view>
<text>{{ storageInfo }}</text>
......
<template>
<view>
<button class="button" @click="shareText('https://uniapp.dcloud.io/uni-app-x','分享到')">分享</button>
<view id="viewshot">
<button class="button" @click="shareText('https://uniapp.dcloud.io/uni-app-x','分享到')">分享文本</button>
<button class="button" @click="shareSnapShot">指定view截图并分享</button>
</view>
</template>
<script>
import Intent from 'android.content.Intent';
import Intent from 'android.content.Intent';
import File from 'java.io.File';
export default {
data() {
......@@ -14,7 +16,7 @@ import Intent from 'android.content.Intent';
}
},
methods: {
shareText(text:string,title:string){
shareText(text : string, title : string) {
const context = UTSAndroid.getUniActivity()!;
const intent = new Intent(Intent.ACTION_SEND)
intent.setType("text/plain");
......@@ -22,12 +24,37 @@ import Intent from 'android.content.Intent';
context.startActivity(Intent.createChooser(intent, title));
// 这里是简单的文本分享示例,如需分享文件图片,需要使用fileProvider
},
shareSnapShot() {
uni.getElementById("viewshot")?.takeSnapshot(
{
success: function (res) {
// 打印截图文件临时路径
console.log(res.tempFilePath)
const context = UTSAndroid.getUniActivity()!;
const intent = new Intent(Intent.ACTION_SEND)
intent.setType("image/*");
let file = new File(res.tempFilePath)
const uri = UTSAndroid.getFileProviderUri(file)
intent.putExtra(Intent.EXTRA_STREAM, uri);
context.startActivity(Intent.createChooser(intent, "分享到"));
},
fail: function (res) {
console.log(res)
uni.showToast({
icon: 'error',
title: '截图失败'
})
}
}
)
},
}
}
</script>
<style>
.button {
.button {
margin: 30rpx;
}
}
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册