android - android 是否会在蓝牙文件接收完成时广播一个事件,如果是,那么 Intent 是什么?
问题描述
我正在尝试使用 android 广播接收器,我希望在完成 BT 文件传输后调用它(在接收文件的情况下)。
用例:设备 (A) 已与另一个启用蓝牙的设备 (B) 配对,当 B 向设备 A 发送文件时,我希望我的广播接收器执行。
有没有办法实现它?
我尝试过滤以下事件,但它似乎是默认蓝牙应用程序的私人事件,并且仅适用于在文件接收完成时推送通知而不是公开广播的BluetoothShare组件。结果,我的广播接收器没有通过实际文件传输调用真实设备,但是当我从 ADB shell 发送以下任何意图时,它在模拟器和真实设备中都可以工作。
在AndroidManifest .xml中过滤的意图:
"android.btopp.intent.extra.**BT_OPP_TRANSFER_STATUS**"
"android.btopp.intent.action.**BT_OPP_TRANSFER_DONE**"
"android.intent.action.**DOWNLOAD_COMPLETE**"
任何线索将不胜感激。谢谢
解决方案
You can monitor the Connectivity action of Bluetooth. There is a connecting action when the device begin to receive file and when its compeleted there will be a disconnecting action. You can register for ACTION_ACL_DISCONNECTED
and onReceive
take some action
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() == BluetoothDevice.ACTION_ACL_DISCONNECTED) {
}
}
}
Register receiver as follows:
IntentFileter blutoothFilter= new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED);
this.registerReceiver(mReceiver, blutoothFilter);
推荐阅读
- sql-server - 从 T-SQL 中的 json 对象获取第一个值或默认值
- python - 打印没有值的局部变量的名称
- r - 使用 rmarkdown 时保存环境出错
- c# - 是否可以区分 WPF DataGrid 上的 PreviewMouseLeftButtonDown 事件,无论它是直接来自网格还是单元格项目?
- vim - 在 VIM 中,如何避免在执行长命令后出现 hit-enter 提示?
- android - 如何创建/更新会话?(MasterCard Gateway 集成在 android 和 iOS 中)
- python - 在调用python中的bsub函数时将参数传递给bash脚本
- python - lambda 函数中的“_”是什么意思,为什么要使用它?
- html - 如何在导航栏中的图像下放置标签?
- javascript - 将一个空元素推入 javascript 数组