提交 eaeaa109 编写于 作者: M mahaifeng

[share]添加分享示例

上级 2e6f64bf
<template> <template>
<view id="viewshot"> <view id="viewshot">
<button class="button" @click="shareText('https://uniapp.dcloud.io/uni-app-x','分享到')">分享文本</button> <button class="button" @click="shareText()">分享文本</button>
<button class="button" @click="shareSnapShot">指定view截图并分享</button> <button class="button" @click="sharePrivateImg()">分享私有目录图片</button>
<button class="button" @click="sharePubImg()">选择图片并分享</button>
<button class="button" @click="shareSnapShot()">指定view截图并分享</button>
</view> </view>
</template> </template>
<script> <script>
import Intent from 'android.content.Intent'; import Intent from 'android.content.Intent';
import File from 'java.io.File'; import File from 'java.io.File';
export default { export default {
data() { data() {
return { return {
summary: '欢迎使用hello uniapp-x'
} }
}, },
methods: { methods: {
shareText(text : string, title : string) {
const context = UTSAndroid.getUniActivity()!; shareText() {
const intent = new Intent(Intent.ACTION_SEND) uni.shareWithSystem({
intent.setType("text/plain"); summary: this.summary,
intent.putExtra(Intent.EXTRA_TEXT, text); href: 'https://uniapp.dcloud.io',
context.startActivity(Intent.createChooser(intent, title)); success(res) {
// 这里是简单的文本分享示例,如需分享文件图片,需要使用fileProvider console.log('success')
// 分享完成,请注意此时不一定是成功分享
},
fail(res) {
console.log('fail')
// 分享失败
},
complete(res) {
}
} )
},
sharePrivateImg() {
const imageSrc : string = "/static/logo.png";
uni.shareWithSystem({
summary: this.summary,
href: 'https://uniapp.dcloud.io',
imageUrl:imageSrc,
success(res) {
console.log('success')
// 分享完成,请注意此时不一定是成功分享
},
fail(res) {
console.log('fail')
// 分享失败
},
complete(res) {
}
} )
},
sharePubImg() {
uni.chooseImage({
count: 3,
success(e) {
console.log(JSON.stringify(e))
// const imageSrc : string = "/static/logo.png";
// var imageList = new UTSArray<string>()
// imageList.push(imageSrc)
// imageList.push(imageSrc)
uni.shareWithSystem({
summary: this.summary,
href: 'https://uniapp.dcloud.io',
imageUrlList:e.tempFilePaths,
success(res) {
console.log('success')
// 分享完成,请注意此时不一定是成功分享
},
fail(res) {
console.log('fail')
// 分享失败
},
complete(res) {
}
} )
}
})
}, },
shareSnapShot() { shareSnapShot() {
uni.getElementById("viewshot")?.takeSnapshot( uni.getElementById("viewshot")?.takeSnapshot(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册