I have a simple service for connecting Bluetooth devices, and it looks like this:
protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras(); if(!extras.containsKey("bluetoothAddress")) return; String bluetoothAddress = extras.getString("bluetoothAddress"); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if(!adapter.isEnabled()) { adapter.enable(); } BluetoothDevice device = adapter.getRemoteDevice(bluetoothAddress); device.createBond(); }
It works great, except that sometimes a pair dialog appears, and sometimes it appears in my notification bar, and I have to open it manually. Is there any way to make sure that he always appears at the front?
I tried using Google, and the only thing I can find is that if you stay in the bluetooth settings, it always appears, but that seems like an ugly solution. The reason for all this is that I work with automation and want to make sure that when I start my service, I get that the pair dialogue can just click “Pair”.
source share