java - Android BluetoothLeAdvertiser not working when used by Nativescript -
i trying create nativescript application allow me send bluetooth low energy advertisements. there no nativescript plugins enable this, have gone ahead , created java library (will add swift library later, that's beside point) should enable advertising.
after creating plugin , integrating java library typescript, see that, although startadvertising() method being called, advertisements not being sent (they weren't showing on ble sniffer.)
because advertising happens in java code, can't find way debug (for instance, can't success/fail message callback, since can't toast outside of activity, or can't print message console).
i wondering if provide insight why advertisements not sending, or method of debugging java code allow me debug it.
ble advertiser library
//imports... class advertiser { public string startadvertising(int manufacturerid, byte[] payload, int duration){ //acquire instance of bluetoothleadvertiser bluetoothadapter btadapter = bluetoothadapter.getdefaultadapter(); bluetoothleadvertiser leadvertiser = btadapter.getbluetoothleadvertiser(); advertisesettings settings = new advertisesettings.builder() .settimeout(duration) .setconnectable(false) .setadvertisemode(advertisesettings.advertise_mode_low_latency) .settxpowerlevel(advertisesettings.advertise_tx_power_high) .build(); advertisedata data = new advertisedata.builder() .setincludedevicename(false) .setincludetxpowerlevel(false) .addmanufacturerdata(manufacturerid, payload) .build(); advertisecallback callback = new advertisecallback() { @override public void onstartsuccess(advertisesettings settingsineffect) { super.onstartsuccess(settingsineffect); } @override public void onstartfailure(int errorcode) { super.onstartfailure(errorcode); } }; leadvertiser.startadvertising(settings, data, callback); return "method finished."; } } jsintegrator.js
module.exports = { startadvertising: function(manufacturerid, payload, timeout=5000) { var advertiser = new com.nslibs.moble.advertiser(); console.log("result of startadvertising: " + advertiser.startadvertising( manufacturerid, payload, timeout)); //prints result of startadvertising: methodfinished } } tsintegrator.ts
export function startadvertising( manufacturerid: number, tosend: number[], timeout?: number); mainclass.ts
import * ble "my-ble-plugin"; export class main{ foo(){ ble.startadvertising(2, [4,6,8]); } }
consider making last leadvertiser.startadvertising(settings, data, callback); call in javascript, implementing interface in javascript so:
new full.package.name.advertisecallback({ onstartsuccess: (settingsineffect) => { ... }, onstartfailure: (code) => { ... } ) doing gives control on code implement, e.g. can console log want in callbacks, or debug them vscode/chrome devtools.
Comments
Post a Comment