I am developing an android application with bluetooth functionality. But i have got one problem. I am using following code
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
tv.setText("Device is not there");
setContentView(tv);
}
else
{
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
tv.setText("Device is there");
setContentView(tv);
}
I am getting error at
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
whenever i try to run that code, my application crashes by showing a message box with “Force close” button. Where is the error, i am not figuring it out yet. Kindly help.
Regards
Do you have the correct permission in your manifest?
You need to specify that your app will use Bluetooth with:
in your manifest file.
The manifest file will be named AndroidManifest.xml and visible in your project folder if using Eclipse.