Discussion:
Crash when running Bluetooth example from Android Docs
Tobiah
2014-02-13 23:31:13 UTC
Permalink
I'm going through the Bluetooth docs and right off I
am having a problem. The code below is cut right from

http://developer.android.com/guide/topics/connectivity/bluetooth.html

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}

I'm setting REQUEST_ENABLE_BT to an arbitrary integer.

I tried running this on two devices, starting with
bluetooth off. On the tablet, the app crashes when checking
mBluetoothAdapter.isEnables(). On my Galaxy note 3, it
makes it past that check, but then the app crashes when
startActivityForResult() is called.

There is no output in the Logcat in either case.

Thanks for any help!

Tobiah
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+***@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
gjs
2014-02-14 06:46:44 UTC
Permalink
Hi,

On the same page -

BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
}

Regards
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+***@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Tobiah
2014-02-14 18:54:26 UTC
Permalink
Post by gjs
Hi,
On the same page -
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
}
Regards
Yeah, I knew that both devices had bluetooth and mBluetoothAdapter was not null.
I actually put that test in there afterward, and it came out false, and the
execution when on to crash as it had before.

Toby
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+***@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Tobiah
2014-02-14 19:18:33 UTC
Permalink
So I tried a third device, and finally got a trace out of Logcat.

It says I don't have the right permissions, but I did put them
into my manifest in the same place as all of my other permissions:

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

I'm not sure how else to make sure I have the right permissions.

Thanks,

Toby
Post by Tobiah
I'm going through the Bluetooth docs and right off I
am having a problem. The code below is cut right from
http://developer.android.com/guide/topics/connectivity/bluetooth.html
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
I'm setting REQUEST_ENABLE_BT to an arbitrary integer.
I tried running this on two devices, starting with
bluetooth off. On the tablet, the app crashes when checking
mBluetoothAdapter.isEnables(). On my Galaxy note 3, it
makes it past that check, but then the app crashes when
startActivityForResult() is called.
There is no output in the Logcat in either case.
Thanks for any help!
Tobiah
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+***@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Tobiah
2014-02-14 19:31:22 UTC
Permalink
Post by Tobiah
So I tried a third device, and finally got a trace out of Logcat.
It says I don't have the right permissions, but I did put them
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
I'm not sure how else to make sure I have the right permissions.
Meh, something was out of sync. I just played with the manifest a little
more and saved it again and things started working.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+***@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
pdm-tex
2014-02-14 19:22:42 UTC
Permalink
Tobiah,

This is what I used to get adapter:
mBtAdapter = (BluetoothAdapter)
this.getApplicationContext().getSystemService(BLUETOOTH_SERVICE);

Doug
Post by Tobiah
I'm going through the Bluetooth docs and right off I
am having a problem. The code below is cut right from
http://developer.android.com/guide/topics/connectivity/bluetooth.html
BluetoothAdapter mBluetoothAdapter =
BluetoothAdapter.getDefaultAdapter();
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent,
REQUEST_ENABLE_BT);
}
I'm setting REQUEST_ENABLE_BT to an arbitrary integer.
I tried running this on two devices, starting with
bluetooth off. On the tablet, the app crashes when checking
mBluetoothAdapter.isEnables(). On my Galaxy note 3, it
makes it past that check, but then the app crashes when
startActivityForResult() is called.
There is no output in the Logcat in either case.
Thanks for any help!
Tobiah
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-***@googlegroups.com
To unsubscribe from this group, send email to
android-developers+***@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+***@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Loading...