0

I'm developing an android app that needs a BT connection. After reading the Android Developers page, the given method such us isEnabled() doesn't work. The error is cannot resolve symbol isEnabled. The imported library is android.bluetooth.BluetoothAdapter. In the manifest file, following the instructions of the Android page, I also have inserted the permission to Bluetooth, BT admin and fine location. The code:

public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null) { Log.i("Fallo","Dispositivo sin bluetooth"); } if (!bluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } } 

1 Answer 1

1

You are creating your BluetoothAdapter object outside the onCreate method. Put everything inside the onCreate curly brackets.

Sign up to request clarification or add additional context in comments.

2 Comments

still one error in startActivityForResult(enableIntent, REQUEST_ENABLE_BT show same error in REQUEST_ENABLE_BT
Check this out: stackoverflow.com/questions/8188277/… This is not related with the initial question,though.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.