Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAdapter return null, use of a promise to init Bluetooth. #42

Closed
carlosdelfino opened this issue Jun 16, 2017 · 1 comment
Closed

Comments

@carlosdelfino
Copy link

carlosdelfino commented Jun 16, 2017

I'm starting to study the plugin for use of Bluetooth.

Unfortunately I discovered that the tablet I have does not have bluetooth, so when I initialize the plugin I get an exception, since the getAdapter function returns null.

Given this I would suggest that this plugin's start point would be a 'Promise' something like:

Bluetooth.init = function() {
  return new Promise(function(resolve, reject) { 
      var bluetoothManager = utils.ad.getApplicationContext().getSystemService(android.content.Context.BLUETOOTH_SERVICE);
      adapter = bluetoothManager.getAdapter();
      if(adapter === null) {
         reject("this device not have bluetooth!");
         return;
       }
       //......
  });
}; 

And this initialization was controlled by the application, so we would have access to the 'then' and 'cath' functions to take some action so the application did not break.

@davorpeic
Copy link

Well, technically you should/could call 'init' inside or after checking isBluetoothEnabled method, which in this case should return false if no bluetooth turned on/existing.

dp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants