Überprüfen Sie mithilfe einer Android-Anwendung, ob Bluetooth aktiviert ist
Ich möchte mithilfe einer Android-Anwendung überprüfen, ob Bluetooth auf einem Gerät aktiviert ist. Ich habe die Methode .isEnabled verwendet. Es liegt aber ein Fehler vor. Ich fand heraus (indem ich Zeilen kommentierte), dass der Fehler in der .isEnabled-Methode liegt. Können Sie mir bitte helfen, das herauszufinden?
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();
}
}
}