I have an issue about unregisterReceiver function. In my service, I have a function to register a mGattUpdateReceiver as follows
if (bluetoothAdapter.isEnabled()) {
Intent gattServiceIntent = new Intent(this, BluetoothLeService.class);
bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);
registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter());
}
And I release it in onDestroy function
public void onDestroy() {
if (mGattUpdateReceiver != null) {
unregisterReceiver(mGattUpdateReceiver);
}
if (mServiceConnection != null) {
unbindService(mServiceConnection);
}
}
The above process worked well when my bluetooth is turn on. However, if the bluetooth is turn off, the register function does not pass. Hence, I got the error as
Caused by: java.lang.IllegalArgumentException: Receiver not registered
Hence, I need to know the receiver (mGattUpdateReceiver) is registered or not. How to check it in Android? Thank all