I'm trying to add a BLE functionality to a plugin I'm working on using this link as a guide https://github.com/android/connectivity-samples/tree/master/BluetoothLeGatt/Application/src/main/java/com/example/android/bluetoothlegatt
I created all the same classes and modified the code with some of the updated methods and added them to my application. I added the code so that it is accessed through the main part of my program via a BroadcastReceiver class in the DeviceScanActivity class and picked up its intent via my main program. Although the BLE Device Screen pops up and shows some devices like the readme suggests it is usually blank. the errors 'com.atakmap.android.helloworld.plugin' is scanning too frequently' and 'could not find callback wrapper' keep showing up. I can't find a location in the four functions from the guide link to control the scan activity and I don't know what "could not find callback wrapper" means. I'd like to know what I should do from here. Perhaps there is an updated version of a tutorial to show how to use the BLE so these errors don't show up. [[[enter image description here](https://i.sstatic.net/3orn2.png)](https://i.sstatic.net/eUwZa.png)](https://i.sstatic.net/XuX6T.png) Here is my BroadcastReceiver class in my DeviceScanActivity class where I take the data from the scan
/**
* Broadcast Receiver that is responsible for getting the data back to the
* plugin.
*/
static class DeviceScanListener extends BroadcastReceiver {
private boolean registered = false;
private DeviceScanActivity.DeviceScanReceiver sdr = null;
synchronized public void register(Context context,
DeviceScanActivity.DeviceScanReceiver sdr) {
if (!registered)
context.registerReceiver(this, new IntentFilter(DSCAN_INFO ));
this.sdr = sdr;
registered = true;
}
@Override
public void onReceive(Context context, Intent intent) {
synchronized (this) {
try {
Bundle extras = intent
.getExtras();
if (extras != null) {
//ArrayList<BluetoothDevice> s = (HashMap<String, String>) extras.get("mgrsData");
ArrayList<BluetoothDevice> s = mLeDeviceListAdapter.mLeDevices;
for (int i = 0; i < mLeDeviceListAdapter.mLeDevices.size(); i++){
BluetoothDevice currb = mLeDeviceListAdapter.mLeDevices.get(i);
Log.d("mine","Stuff in the DeviceList");
Log.d("mine",String.valueOf(i));
}
if (s != null && sdr != null)
sdr.onDeviceScanReceived(s);
}
} catch (Exception ignored) {
}
if (registered) {
context.unregisterReceiver(this);
registered = false;
}
}
}
}
Here is the button that is used to start looking for BLE devices
final Button connectDevice = helloView.findViewById(R.id.connect_device);
connectDevice.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//Todo
dd1.register(getMapView().getContext(), ddr);
Intent intent = new Intent();
intent.setClassName("com.atakmap.android.helloworld.plugin",
"com.atakmap.android.helloworld.DeviceScanActivity");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("EXTRA_MESSAGE", "");
parentActivity.startActivityForResult(intent, 0);
}
});
I have tried updating the methods in the code provided in the link to ensure everything is working (replacing depreciated methods with newer ones) but I can't seem to get it to work. I expect a Screen that shows the BLE devices in the area (I have another app I made in flutter that does this and shows the BLE devices so I should see them on this app as well) but Instead a screen pops up for a few seconds with devices before going away.
I figured it out I used this website: https://android.googlesource.com/platform/development/+/7167a054a8027f75025c865322fa84791a9b3bd1/samples/BluetoothLeGatt?autodive=0%2F%2F
and this website: https://spot.pcc.edu/~mgoodman/developer.android.com/samples/BluetoothLeGatt/src/com.example.android.bluetoothlegatt/BluetoothLeService.html#l45 along with the updated documentation on BLE code on Androids website here: https://developer.android.com/develop/connectivity/bluetooth/ble/find-ble-devices here: https://developer.android.com/develop/connectivity/bluetooth/ble/connect-gatt-server#java and here: https://developer.android.com/develop/connectivity/bluetooth/ble/transfer-ble-data
To update my code and this fixed the issue, there are no longer wrapper errors or scanning to frequent errors.