Muhammad Salman Farooq
Muhammad Salman Farooq

Reputation: 1325

Android Bluetooth enable error

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

Upvotes: 0

Views: 1566

Answers (1)

sebsebmc
sebsebmc

Reputation: 112

Do you have the correct permission in your manifest? You need to specify that your app will use Bluetooth with:

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

in your manifest file. The manifest file will be named AndroidManifest.xml and visible in your project folder if using Eclipse.

Upvotes: 1

Related Questions