首页 > 解决方案 > 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**"

任何线索将不胜感激。谢谢

标签: androidbluetoothbroadcastreceiver

解决方案


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);

推荐阅读