mercredi 6 juillet 2016

Running BLE in background on Android

Where I'm Currently At:

I would like to be able to run Bluetooth in my app in the background on android. I have read various guides and understand the idea of creating an intent service (something like android.app.IntentService and extending it, overwriting the onHandleIntent with your desired behaviour) however, I don't understand how that would interract with my existing behaviour? So for example, I currently call:

...
var bluetoothManager = utils.ad.getApplicationContext().getSystemService(android.content.Context.BLUETOOTH_SERVICE);
adapter = bluetoothManager.getAdapter();
adapter.startLeScan(Bluetooth._scanCallback)
...

(this is in JavaScript, using the nativescript runtime, so don't worry about it looking a bit wierd.)

Where I'm trying to get to:

I would like to being able to scan for and reconnect to paired devices in the background and recieve (store in SQLite) GATT Characteristic updates.

Question:

So how do I create this functionality in the type of service that can be run in the background as described above?

Aucun commentaire:

Enregistrer un commentaire