Problems with an app using bluetooth plugin

Hi there,
i’m writing a simple app to test some bluetooth calls.
I only added the support for Android.
The first tests was done with ‘ionic serve’ but the BT calls must done on a device.
So, i had two environments:

  1. IonicView
  2. 'ionic run’
    On both, running on a Samsung Tab2 10.1, the application was installed but I had the first blank page that means that something went wrong, but what?
    Is there a way to see the console.log/error messages on IonicView?
    The same for ‘ionic run’ ?
    I’m wondering why, installing the app on the device, I had not received the Warning message for the use of the bluetooth.
    Should be the cause of the problems??

Thanks

1 Like

Ok, I verified that in the platforms/android/AndroidManifest.xml there are the directives:

<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

Then I need to view the debug/error messages …

Hi all,
thanks to @gajotres I discovered that I had the error described in http://www.gajotres.net/whitelist-external-resources-and-api-calls-ionic-framework/.
Now the code goes on and I have the following:

1     778862   error    ReferenceError: bluetoothSerial is not defined
    at new <anonymous> (http://192.168.0.105:8100/js/controllers.js:50:9)
    at invoke (http://192.168.0.105:8100/lib/ionic/js/ionic.bundle.js:13012:17)
...

The code is inside the defition of the controller ( bluetoothSerial.isEnabled(…) ).
My guess is that the bluetoothSerial is global but maybe is not visible (in the context) of the controller …
Do I need to pass it inside the $scope?
Where I can defined it?

I’m playing around with try/catch and console.log() funtions.
I put the same code on app init (.run(…)) and in the first selected controller:

try {
	bluetoothSerial.isEnabled();
	console.log('app BT works!');
}
catch (err) {
	console.log('app bt not visible?!?!');
}

I found that sometimes I see the debug messages of app.js (angualr.module(‘starter’, …)) before the ones in the controller function.
When i see the messages from controller before the app messages, sometimes i see the ‘not visible’ message for controller and ‘works’ for app messages .

How can it be possible ??

I do not know if this comment is too late. The problem is bluetoothSerial global instance does not exists until after $ionicPlatform.ready is executed. I solved using $ionicPlatform.ready like this:

$ionicPlatform.ready(function() {
  bluetoothSerial.isEnabled(function () {
    console.log('bt is on!');
  }, function () {
    console.log('app bt not visible?!?!');
  });
});
1 Like