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);
}
}