5
기본적으로 여기 2 가지를 시도 중입니다. 내 블루투스 장치가 특정 장치에 연결될 때 토스트를 시작하려고합니다 (특정 블루투스 이름인지 확인해야합니다). 그 특정 블루투스 장치에 연결될 때 건배. 내 블루투스가 특정 블루투스 장치에 연결되지 않은 경우 축배를 보여주고 싶습니다. 여기 내 코드는 : manifest.xml에 Android : 연결된 블루투스 기기의 이름을 찾는 방법은 무엇입니까?
<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();
}
}
}
를 확장 연결이 끊긴 경우에도 작동하지만 연결 축배는 결코 작동하지 않습니다.
THanks 내가 이것을 점검하고 답장 할 것입니다. –
감사합니다. –