Skip to content

手机端发送消息与文件

示例说明

演示手机端如何通过经典蓝牙和 Wi-Fi P2P 向眼镜发送文本、文件、通知和 APK。

使用位置

手机端首页:

  • MainPhoneActivity -> SendMessageActivity

示例页面:

  • com.rokid.phone.SendMessageActivity

适用端

  • 手机端

关键文件

能力清单

  • P2P 发送文本
  • P2P 发送文件
  • 蓝牙发送文本
  • 蓝牙发送文件
  • 发送系统通知到眼镜
  • 通过 P2P 发送 APK

流程说明

文本消息

  • P2P:sendTextMessageByP2P("...", "GlassSample")
  • 蓝牙:sendTextMessageByClassicBT("...", "GlassSample")

文件传输

  • P2P:getFileOperater().sendFile(...)
  • 蓝牙:getBtFileOperater().sendFile(...)

通知同步

  • 构造 NotificationMessage
  • 调用 getAbsNotificationService()?.sendNotification(...)

APK 下发

  • 调用 getApkFileOperator()?.sendFile(...)
  • 监听 TransferProgressListener

实现说明

什么时候用蓝牙,什么时候用 P2P

  • 文本、小控制消息:蓝牙即可
  • 图片、APK、大文件:优先 P2P

示例中的测试文件从哪来

页面启动时会把 assets 内文件复制到应用缓存目录,再从缓存目录发出。

注意事项

  • 发送 APK 前,页面要求已经连上 P2P。
  • 示例使用的 clientId 是 GlassSample
  • 正式业务中建议把 clientId 和业务协议统一抽成常量。