0
작업을 시작할 때 블루투스 페어링 된 장치가 있는지 확인한 다음 결과에 따라 작업을 수행해야합니다. 이를 위해, 나는 다음을 수행하십시오 onResume에서동작이 블루투스 페어링 된 장치가 있는지 알아야합니다.
:
<activity
android:name=".Configuration"
android:label="@string/config_title" >
<intent-filter>
<action android:name="android.bluetooth.device.action.ACL_CONNECTED"/>
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED"/>
</intent-filter>
</activity>
하지만 여전히 : 매니페스트에
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
/**Do something if connected*/
if(action.equals("android.bluetooth.device.action.ACL_CONNECTED")) {
//Action
}
/**Do something if disconnected*/
else if (action.equals("android.bluetooth.device.action.ACL_DISCONNECTED")) {
Toast.makeText(getApplicationContext(), "No device paired", Toast.LENGTH_SHORT).show();
}
}
};
: 다음
protected void onResume() {
super.onResume();
/**Filters para comprobar el BroadcastReceiver*/
IntentFilter filter1 = new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED);
IntentFilter filter2 = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED);
this.registerReceiver(mReceiver, filter1);
this.registerReceiver(mReceiver, filter2);
, 나는 브로드 캐스트 리시버를 사용 뭔가해야하는 일을 잊어 버렸거나 무언가 틀렸어 야합니다.