找到广播接收器动作

时间:2019-01-23 09:35:12

标签: bluetooth broadcastreceiver bluetooth-lowenergy

我正在开发用于蓝牙连接的android广播接收器

问题在于广播接收器采取了所有措施,但只采取了ACTION_FOUND。

这是意图过滤器

IntentFilter filter1 = new IntentFilter();

filter1.addAction(BluetoothDevice.ACTION_FOUND);
filter1.addAction(BluetoothDevice.ACTION_CLASS_CHANGED);
filter1.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
filter1.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);

registerReceiver(mBroadcastReceiver1, filter1);

这是广播接收器

private final BroadcastReceiver mBroadcastReceiver1 = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {

    final String action = intent.getAction();
    Log.e(TAG, "onReceive: ACTION____________come in Receiver1");
    if(BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(intent.getAction())) {
        Log.e("Action?::", action);
    }
    else if(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(intent.getAction())) {
        Log.e("Action?::", action);
    }
    else if (BluetoothDevice.ACTION_CLASS_CHANGED.equals(intent.getAction())) {
        Log.e("Action?::", action);
    }
    else if (BluetoothDevice.ACTION_FOUND.equals(intent.getAction())) {
        Log.e("Action?::", action);
    }

  }
};

这是日志

E/Now Action?::: android.bluetooth.adapter.action.DISCOVERY_STARTED
E/Now Action?::: android.bluetooth.device.action.CLASS_CHANGED
E/Now Action?::: android.bluetooth.adapter.action.DISCOVERY_FINISHED

2019-01-23 18:13:58.414 4796-4834/? W/BroadcastQueue: Permission Denial: receiving Intent { act=android.bluetooth.device.action.FOUND flg=0x10 (has extras) } to ProcessRecord{29e5269 29402:com.reziena.user.reziena_b/u0a209} (pid=29402, uid=10209) requires android.permission.ACCESS_COARSE_LOCATION due to sender com.android.bluetooth (uid 1002)
2019-01-23 18:13:58.414 5266-5534/? V/BluetoothEventManager: onReceive :: android.bluetooth.device.action.FOUND
2019-01-23 18:13:58.414 5227-5358/? D/BluetoothUtils: getBtEnabledContainers(): btContainers = []
2019-01-23 18:13:58.414 5266-5534/? V/BluetoothEventManager: onReceive :: android.bluetooth.device.action.FOUND

0 个答案:

没有答案