cancel
Showing results for 
Search instead for 
Did you mean: 

MDK Extension for Native Android Bluetooth Functionalities

03-24-2022 11:07 AM
kakkem Participant
936 views 2 comments
0 Likes
SAP Managed Tags
Subscribe

Dear Experts,

I'm trying to create an extension for native android Bluetooth functionalities, I. have created Extension plugin and I'm directly calling the java class methods by importing from "@nativescript/core/application"; not created the .aar files.
Only isEnabled() is working fine with the BluetoothAdapter.ACTION_REQUEST_ENABLE intent parameter.
Others like
1. discovering device through registerBroadcastReceiver call back methods with ACTION_FOUND
2. getBondedDevices() are not working as expected.

paired devices or scanning the devices are not returning the device details.
Can you please help me to understand how can we use native android Bluetooth class methods. I have attached the code snippet for your reference.

androidApp.registerBroadcastReceiver(
android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED,
(context, intent) => {
const state = intent.getIntExtra(android.bluetooth.BluetoothAdapter.EXTRA_STATE, android.bluetooth.BluetoothAdapter.ERROR);
if(android.bluetooth.BluetoothAdapter.STATE_ON) {
const adapter = android.bluetooth.BluetoothAdapter.getDefaultAdapter();
let BTPairSet = adapter.getBondedDevices();
//alert(JSON.stringify(BTPairSet));
var setToObject = Object.assign({}, ...Array.from(BTPairSet));
//alert(JSON.stringify(setToObject));

Thanks,

Krishna

0 Likes

Accepted Solutions (0)

Answers (0)