如何检查接收器是否已注册?

时间:2017-01-02 12:07:47

标签: android bluetooth broadcastreceiver bluetooth-lowenergy

我有关于unregisterReceiver功能的问题。在我的服务中,我有一个函数来注册mGattUpdateReceiver如下

if (bluetoothAdapter.isEnabled()) {
  Intent gattServiceIntent = new Intent(this, BluetoothLeService.class);
  bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);
  registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter());
}

我在onDestroy函数

中发布它
public void onDestroy() {
    if (mGattUpdateReceiver != null) {
       unregisterReceiver(mGattUpdateReceiver);
    }
    if (mServiceConnection != null) {
       unbindService(mServiceConnection);
    }
}

当我的蓝牙开启时,上述过程运作良好。但是,如果蓝牙关闭,则寄存器功能不会通过。因此,我得到了错误

Caused by: java.lang.IllegalArgumentException: Receiver not registered

因此,我需要知道接收者(mGattUpdateReceiver)是否已注册。如何在Android中查看?谢谢所有

0 个答案:

没有答案
相关问题