更新记录
1.0.0(2025-08-17)
暂时只支持安卓
平台兼容性
云端兼容性
阿里云 | 腾讯云 | 支付宝云 |
---|---|---|
√ | √ | √ |
uni-app x(4.44)
Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
---|---|---|---|---|---|
× | × | √ | × | - | × |
x-share
一个用于 Android 的通用分享模块(文本 / 图片 / 视频 / 任意文件) 。
功能与平台
- 支持分享:文本、图片、视频、任意文件(PDF/EPUB/ZIP 等)
- 平台:uni-app x(App-Android)
- 适配策略:
- 优先使用 MediaStore 发布文件,获得系统可读的
content://
URI; - 失败时回退使用 FileProvider;
- 自动为
content://
与file://
以及绝对路径做适配与 MIME 推断。
- 优先使用 MediaStore 发布文件,获得系统可读的
导出 API
shareText(options: ShareTextOptions): void
shareImage(options: ShareMediaOptions): void
shareVideo(options: ShareMediaOptions): void
shareFile(options: ShareMediaOptions): void
快速上手
以 uni-app x(uvue/ts)为例
import { shareText, shareImage, shareVideo, shareFile } from '@/uni_modules/x-share'
// 文本
shareText({
text: 'Hello x-share',
chooserTitle: '分享到',
})
// 图片(已拥有路径)
shareImage({
path: 'file:///sdcard/Download/a.jpg',
chooserTitle: '分享到'
})
// 视频(已拥有路径)
shareVideo({
path: 'content://.../video/xxx',
chooserTitle: '分享到'
})
// 任意文件(已拥有路径)
shareFile({
path: '/sdcard/Download/a.pdf',
chooserTitle: '分享到',
mimeType: 'application/pdf' // 可选,建议传
})
搭配系统选择器
推荐使用系统选择器拿到路径后直接分享,已适配返回的
content://
。
-
选择图片(推荐):
uni.chooseImage({ count: 1, sourceType: ['album'], albumMode: 'system', sizeType: ['original'], success: (res) => { const picked = res.tempFiles?.[0]?.path || res.tempFilePaths?.[0] || '' if (!picked) return shareImage({ path: picked, chooserTitle: '分享到' }) } })
-
选择视频:
uni.chooseVideo({ sourceType: ['album'], success: (res) => { const picked = res.tempFilePath if (!picked) return shareVideo({ path: picked, chooserTitle: '分享到' }) } })
-
选择任意文件:
uni.chooseFile({ count: 1, success: (res) => { const picked = res.tempFiles?.[0]?.path || res.tempFilePaths?.[0] || '' if (!picked) return // 可选:按文件类型显式传入 mimeType,提升兼容性 shareFile({ path: picked, chooserTitle: '分享到' }) } })