i'm trying create class sequentially performs bluetooth tasks without user intervention aside starting process. in class external event calls overridden method "executecentral" there calls setup() enable , request permissions. if complete initialize() method called , waits 1 second before calling bluetooth initialize() executed in edt. if runs without exception calls startscanning() waits 1 second before calling bluetooth startscan() in edt. after scanning has started waits 10 seconds before calling bluetooth stopscan() in edt.
i recreated project clean setup , used "downloader" in codename 1 settings. compiles , runs, reports exception on "bluetooth not initialized"
any idea on doing wrong? i'm under impression calls must done in edt.
the single form btdemo compiles , executes each task separate user initiated event.
public class uitaskbluetoothex extends com.crumptech.library.mobile.ui.tasks.uitaskbluetooth { protected bluetooth bt = new bluetooth(); protected map devices = new hashmap(); public uitaskbluetoothex() { super(); } @override public string getreplacement() { return "uitaskbluetoothex"; } protected void showdebug(string message) { display.getinstance().callserially(new runnable() { @override public void run() { uiapplication.showdebug("uitaskbluetoothex " + message); completed(result(false)); } }); } @override protected void executecentral() { bt = new bluetooth(); try { setup(); initialize(); } catch (exception e) { showdebug(e.getmessage()); } } protected void setup() throws ioexception { if (!bt.isenabled()) { bt.enable(); } if (!bt.haspermission()) { bt.requestpermission(); } } protected void initialize() { timer timer = new timer(); timer.schedule(new timertask() { @override public void run() { display.getinstance().callserially(new runnable() { @override public void run() { try { if (!bt.isinitialized()) { bt.initialize(true, false, "shopmylocalstores"); } startscanning(); } catch (exception e) { showdebug(e.getmessage()); } } }); } }, 1000); } protected void startscanning() { timer timer = new timer(); timer.schedule(new timertask() { @override public void run() { display.getinstance().callserially(new runnable() { @override public void run() { try { if (!bt.isscanning()) { bt.startscan(new actionlistener() { @override public void actionperformed(actionevent evt) { try { jsonobject res = (jsonobject) evt.getsource(); if (res.getstring("status").equals("scanresult")) { if (!devices.containskey(res.getstring("address"))) { devices.put(res.getstring("address"), res); } } } catch (jsonexception e) { } } }, null, true, bluetooth.scan_mode_low_power, bluetooth.match_mode_sticky, bluetooth.match_num_max_advertisement, bluetooth.callback_type_all_matches); stopscanning(); } } catch (exception e) { showdebug(e.getmessage()); } } }); } }, 1000); } protected void stopscanning() { try { timer timer = new timer(); timer.schedule(new timertask() { @override public void run() { display.getinstance().callserially(new runnable() { @override public void run() { try { if (bt.isscanning()) { bt.stopscan(); } } catch (exception e) { showdebug(e.getmessage()); } showresults(); } }); } }, 10000); } catch (exception e) { } } protected void showresults() { timer timer = new timer(); timer.schedule(new timertask() { @override public void run() { display.getinstance().callserially(new runnable() { @override public void run() { string text = ""; iterator = devices.entryset().iterator(); while (it.hasnext()) { map.entry pair = (map.entry) it.next(); text += (pair.getkey() + " = " + pair.getvalue() + "\r\n"); } uiapplication.showdebug(text); completed(result(true)); } }); } }, 1000); }
}
it looks methods aren't supported on ios. these throw ioexceptions if called on ios. limitation baked cordova plugin ported. these methods literally return "unsupported operation" inside plugin. i'm not sure if these omissions of plugin, or if can't supported. list of methods unsupported on ios are:
- isenabled()
- enable()
- disable()
- mtu()
- requestconnectionpriority()
- haspermission()
- requestpermission()
- islocationenabled()
- requestlocation()
i have marked these in javadocs bluetooth class identify them. we'll have here clean ... perhaps exception not best thing.
in case, test app failing because call isenabled() , initialize() inside same try/catch block. isenabled throws exception never gets initialize() , tests aren't run.
i have adapted code own test case, , made modification, , appears run fine.
Comments
Post a Comment