分享 UI 业务包

更新时间:2024-04-01 06:55:46下载pdf

分享 UI 业务包支持三方分享能力,用户可以将信息通过微信、短信、邮箱等渠道分享给其他好友。

功能说明

  • 微信分享:要求中国大陆地区账号,配置微信 appkey
  • 短信分享:调起短信功能,选择联系人,发送分享内容
  • 复制分享:自动复制分享内容
  • 邮箱分享/系统应用分享:调起系统分享的弹框,选择应用分享
  • 文本分享:将图片通过系统应用分享,需提供文本内容
  • 图片分享:将图片通过系统应用分享,需提供 imagePath

业务包集成

在工程 modulebuild.gradle 添加配置。

   
   dependencies {
      api enforcedPlatform("com.thingclips.smart:thingsmart-BizBundlesBom:${biz_bom_version}")
      api 'com.thingclips.smart:thingsmart-bizbundle-share'
      api "com.tencent.mm.opensdk:wechat-sdk-android-without-mta:6.7.0"
      api "com.thingclips.smart:thingsmart:${sdk_version}}"
   }
   
   

微信分享

申请 Key

步骤详情,请参考 申请微信 appKey

配置 Key

res 资源文件中添加以下配置:

   <string name="wxAppKey">微信 key</string>

功能使用

//微信分享
val mShareManager = MicroContext.getServiceManager().findServiceByInterface<AbsShareManager>(AbsShareManager::class.java.name)

//初始化微信
mShareManager?.initWxShare(wxAppId)

//判断微信是否安装
mShareManager?.isWxInstalled()

短信分享

val mShareManager = MicroContext.getServiceManager().findServiceByInterface<AbsShareManager>(AbsShareManager::class.java.name)
mShareManager?.doShareBySms(mContext, "share content")

复制分享

val mShareManager = MicroContext.getServiceManager().findServiceByInterface<AbsShareManager>(AbsShareManager::class.java.name)
mShareManager?.doShareByCopy("share content")

图片分享

val mShareManager = MicroContext.getServiceManager().findServiceByInterface<AbsShareManager>(AbsShareManager::class.java.name)
mShareManager?.doShareByImage(mActivity, “mImagePath”)

邮箱分享

  • 检查邮箱是否存在:

    val mShareManager = MicroContext.getServiceManager().findServiceByInterface<AbsShareManager>(AbsShareManager::class.java.name)
    mShareManager?.checkEmailApkExist()
    
  • 邮箱分享:

    val mShareManager = MicroContext.getServiceManager().findServiceByInterface<AbsShareManager>(AbsShareManager::class.java.name)
    mShareManager?.doShareByEmail(mActivity, “mShareTitle”, "share content", “mEmailUrl”)
    

系统邮箱分享

val mShareManager = MicroContext.getServiceManager().findServiceByInterface<AbsShareManager>(AbsShareManager::class.java.name)
mShareManager?.doShareByEmail(mContext,"share content")

系统全部应用分享

val mShareManager = MicroContext.getServiceManager().findServiceByInterface<AbsShareManager>(AbsShareManager::class.java.name)
mShareManager?.doShareBySystemDefault(mContext, "share content")

指定分享的应用类型

val mShareManager = MicroContext.getServiceManager().findServiceByInterface<AbsShareManager>(AbsShareManager::class.java.name)
mShareManager?.launchSharePlatform(this, ShareType.TYPE_MORE, "share content")