Проверьте, включен ли Bluetooth с помощью приложения Android
Я хочу проверить, включен ли Bluetooth на устройстве с помощью приложения Android. Я использовал метод .isEnabled. Но есть ошибка. Я выяснил (комментируя строки), что ошибка в методе .isEnabled. Можете ли вы помочь мне выяснить это?
final BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String status = "Bluetooth";
if(bluetooth != null) {
if (bluetooth.isEnabled()) {
String mydeviceaddress = bluetooth.getAddress();
String mydevicename = bluetooth.getName();
status = ("Address "+ mydeviceaddress + " Name" + mydevicename);
Toast.makeText(getApplicationContext(), "" + status + "", Toast.LENGTH_LONG).show();
} else {
status = ("Bluetooth not enabled");
Toast.makeText(getApplicationContext(), "" + status + "", Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(getApplicationContext(), "" + status + "", Toast.LENGTH_LONG).show();
}
}
}