When I\'m trying to get default bluetooth adapter while i\'m NOT in Activity, but in TimerTask
(created inside Service
) by using:
B
Calling BluetoothAdapter.getDefaultAdapter()
in the UI
thread works, but is not very practical. I have tried the workaround with a fake Activity, but since I hate such workarounds, I decided to READ what the error message really says and it is nothing more than that the thread didn't call Looper.prepare()
.
So calling Looper.prepare()
just before calling BluetoothAdapter.getDefaultAdapter()
should solve the problem anywhere, not just in a UI thread.
Works fine for me so far.