5
基本上我在這裏嘗試2件事,我試圖開始祝酒,當我的藍牙設備連接到一個特定的設備(所以需要檢查,如果這是特定的藍牙名稱),如果這是特定的設備,然後我想顯示當連接到特定的藍牙設備時舉杯祝酒。當我的藍牙與特定的藍牙設備斷開連接時,我也想顯示敬酒。 這裏是我的代碼: 中的manifest.xmlAndroid:如何找出連接的藍牙設備的名稱?
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<receiver android:name=".MyBluetoothReceiver" >
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED" />
<action android:name="android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED" />
</intent-filter>
</receiver>
類代碼:
公共類MyBluetoothReceiver擴展廣播接收器{
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "RECEIVER CALLED!!", Toast.LENGTH_LONG).show();
if(intent.getAction().equals(
"android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED")){
// code for Bluetooth connect
Toast.makeText(context, "CONNECTED!!", Toast.LENGTH_LONG).show();
}
if(intent.getAction().equals(
"android.bluetooth.device.action.ACL_DISCONNECTED")){
//code for Bluetooth disconnect;
Toast.makeText(getApplicationContext(),"DISCONNECTED",Toast.LENGTH_LONG).show();
}
}
}
在我的代碼即時通訊正常,甚至舉杯讓接收器,稱爲土司爲斷開連接也工作,但連接烤麪包從未工作。
請讓我知道爲什麼連敬酒不工作,當連接到一個特定的設備如何使此代碼的工作(我不想顯示這個土司所有設備)
謝謝,我會檢查這個和回覆.. –
謝謝他的工作:) –