Ich versuche zu überprüfen, wenn mein Gerät mit einem Auto verbunden ist. Ich gehe davon aus dem Auto wirkt wie ein Bluetooth-Headset, deshalb habe ich den folgenden Code in meiner Tätigkeit onCreate verwendet:Bluetooth-Verbindung mit dem Auto
// Get the default adapter
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {
public void onServiceConnected(int profile, BluetoothProfile proxy) {
Time today = new Time(Time.getCurrentTimezone());
today.setToNow();
if (profile == BluetoothProfile.HEADSET) {
mBluetoothHeadset = (BluetoothHeadset) proxy;
LogginUtil.logString("BluetoothApp", "Headset event called at " + today.format("%k:%M:%S") + " - " + profile);
} else {
LogginUtil.logString("BluetoothApp", "Other event called at " + today.format("%k:%M:%S") + " - " + profile);
}
}
public void onServiceDisconnected(int profile) {
if (profile == BluetoothProfile.HEADSET) {
mBluetoothHeadset = null;
Time today = new Time(Time.getCurrentTimezone());
today.setToNow();
LogginUtil.logString("BluetoothApp", "Headset event disconnected at " + today.format("%k:%M:%S"));
}
}
};
// Establish connection to the proxy.
mBluetoothAdapter.getProfileProxy(getApplicationContext(), mProfileListener, BluetoothProfile.HEADSET);
Wenn ich die Anwendung zu starten, mit Bluetooth ein und aus, bekomme ich folgende Ausgabe:
Headset event called at "current time" - 1
Wenn ich mein Gerät mit dem Auto Pairing bekomme ich genau die gleiche Leistung:
Headset event called at "current time" - 1
Was muß ich tun, um zu erkennen, dass das Gerät aktiv über bluetooth verbunden ist mit das Auto?
Vielen Dank im Voraus, und lassen Sie mw wissen, wenn Sie etwas anderes benötigen.
EDIT KLARSTELLUNG
Nur für den Fall meiner Frage in falsch verstanden. Ich möchte benachrichtigt werden (nur ein Protokoll), wenn das Gerät über Bluetooth mit Bluetooth verbunden wird. Ist so etwas möglich?
Haben Sie versucht, nur mit einem normalen Bluetooth-Headset verbinden? – bernlim
Entschuldigung, lesen Sie einfach Ihre Frage vollständig, aber versuchen Sie definitiv mit nur einem normalen Bluetooth-Headset zuerst, wenn es weiterhin Komplikationen gibt. – bernlim
Nein, das Ziel des Spiels ist es, mit einem Bluetooth-fähigen Auto zu verbinden. Wenn der obige Code für diesen Zweck falsch ist, zeigen Sie bitte e in die richtige Richtung :), @bernlim – Lunchbox