Android Bluetooth OPP的理解与使用之一

当前OPP Source Code基于Android O(8);

Andorid 中Bluetooth OPP的实现与其HFP、A2DP等Profile不一样,其没有Framework层实现,即

frameworks\base\core\java\android\bluetooth中并没有OPP的对外接口;

同时Server 层中,packages\apps\Bluetooth\src\com\android\bluetooth\opp的命名也和HFPProfile不一样:其Java file命名使用了Bluetoothxxx字样,这通常只出现在Framework等对外的接口中;

本文继续以问答形式展开:

问题点1: Android 手机的OPP 如何使用?

  OPP的使用并不是先配对连接再操作,而是在Android手机中先选择需发送的文件,然后选择蓝牙发送,其会弹出已配对设备,选择后将直接发送,发送完成后将自动断开OPP连接

以下截图是OPP手机操作文件发送:

 

问题点2Android Bluetooth OPP Server 层相关OPP files的作用;

packages\apps\Bluetooth\src\com\android\bluetooth\opp中相关OPP files比别的profile多很多,理清基本file作用,有助于对OPP的理解;

  BluetoothOppBatchThis class stores information about a batch of OPP shares that should be transferred in one session;用于保存一个或一批OPP 发送或接收对象信息,其作为OPP的操作单元去理解

 BluetoothOppBtEnableActivity: 用于BluetoothOppLauncherActivity,若当前BT 没有打开时,BluetoothOppLauncherActivity将执行当前Activity弹出提示菜单用于User 点击确认(将执行mOppManager.enableBluetooth();)或取消打开BT(此时不做任何处理直接关闭当前dialog);

BluetoothOppBtEnablingActivity: 当前菜单将在BluetoothOppBtEnableActivity点击确认后弹出,其内部设置20S超时Message BT_ENABLING_TIMEOUT用于等待BT on成功或失败; 

BluetoothOppBtErrorActivity: 这是一个错误提示菜单,用于基于实际情形进行错误信息提示;

 BluetoothOppFileProvider继承于FileProvider(但FileProvider本身是ContentProvider的子类),用于操作已经接收到的文件(注意:这里并不是操作接收的过程,而是对已经接收到的文件进行操作)

BluetoothOppHandoverReceiver: 用于接收特定4Message

"android.btopp.intent.action.WHITELIST_DEVICE",

"android.btopp.intent.action.STOP_HANDOVER_TRANSFER",

"android.nfc.handover.intent.action.HANDOVER_SEND",

"android.nfc.handover.intent.action.HANDOVER_SEND_MULTIPLE"

其在Androidmanifest.xml静态注册

BluetoothOppIncomingFileConfirmActivity: 同于提示User,OPP 收到新的文件;

Note:注意其与方法updateIncomingFileConfirmNotification的区别及关联;

Android O实测:当收到新文件,在系统通知(updateIncomingFileConfirmNotification中发出的系统通知)中点击ACCEPT时,Log显示收到了“Constants.ACTION_ACCEPT” 但并没有显示收到“Receiver ACTION_INCOMING_FILE_CONFIRM”,

进而BluetoothOppIncomingFileConfirmActivity没有被触发,但不影响文件的接收;

 

 BluetoothOppLauncherActivity其他APP 需要调用BT 发送文件时的入口类,在BluetoothManagerService.java中被拉起;---具体详看后续问题点的描述;

 BluetoothOppManager: 这是一个OPP 操作管理实现,提供类似其他profile的操作接口,如提供主动发送的方法startTransfer。

 BluetoothOppNotification:用于通知正在发送、正在接收以及发送成功、失败时的消息告知;

BluetoothOppObexClientSession:实现接口BluetoothOppObexSession。实现了主动断开、连接、发送等;---但这里需要关注其状态结果(连接、断开等消息)在哪返回;

BluetoothOppObexServerSession: 实现接口BluetoothOppObexSession 和继承

ServerRequestHandler;其没有主动连接等实现,但有关于连接和断开的相关callback API;

其中“onPut”为接收data callback,可理解为OPP Server端数据开始暴露出来的callback

BluetoothOppObexSession: 这是一个接口,本身并没有具体实现,

当前被BluetoothOppObexClientSession和BluetoothOppObexServerSession实作

BluetoothOppPreference: 用于保存本地蓝牙名称和channel,其自身描述是:

This class cache Bluetooth device name and channel locally. Its a temp

solution which should be replaced by bluetooth_devices in SettingsProvider

Note:这里虽说是一个temp solution,但实际上在Android910、11还继续存在;

BluetoothOppProvider:继承于ContentProvider,用于实现类似数据库(但其并不直接描述为数据库操作,而是使用“表格”来描述,原因是:数据库形式只是其中一种使用方式)的相关操作;---具体详看后续问题点描述

 BluetoothOppReceiveFileInfo: 用于存储正在接收的单一文件信息;

BluetoothOppReceiver:继承于BroadcastReceiver,用于接收相关Message

虽然在Androidmanifest.xml静态注册时以下截图所示Message,但实际上在Source Code中,其监听多个Message,包括收到新文件的通知

Message “ACTION_INCOMING_FILE_CONFIRM

BluetoothOppSendFileInfo: 与BluetoothOppReceiveFileInfo功能相反,其存储了正被发送的data信息,自自身描述是:This class stores information about a single sending file It will only be used for outbound share.

BluetoothOppService: OPP 的核心类

BluetoothOppShareInfo: 自身描述:This class stores information about a single OBEX share, e.g. one object send/receive to a destination address. 存储单一对象的相关信息,不强调正在发送、接收等状态,Opp Client和Server 都能使用;

BluetoothOppTransfer: 自身描述:This class run an actual Opp transfer session (from connect target device to disconnect);这里包含发送和接口,并不是字面理解的发送

 

 BluetoothOppTransferActivity: 自身描述:Handle all transfer related dialogs;

BluetoothOppTransferAdapter: 自身描述:This class is used to represent the data for the transfer history list box. The only real work done by this class is to construct a custom view for the line items.其唯一被使用位置是在BluetoothOppTransferHistory中list出相关信息;

BluetoothOppTransferHistory:用于显示User已经完成发送或接收文件的相关弹窗;

BluetoothOppTransferInfo:自身描述:This is currently used by Application codes. This class stores information about a single OBEX transfer (operation)。实际Code没有data ,作为类似结构体使用;

BluetoothOppUtility:这个类干得事情有点杂,很难定性是专门发送,还是接收;

BluetoothShare: 类似Constants的功能,自身描述:Exposes constants used to interact with the Bluetooth Share manager's content provider.

Constants:  OPP 的相关宏定义;

TestActivity: 这是OPP 自带的测试Activity

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值