USB 플러그가 뽑혀있을 때 실행중인 서비스를 중지하려고합니다.USB 장치가 분리되었을 때 서비스 중지
내 활동 onCreate
내부에 나는뿐만 아니라 호출되고있는 다른 intent filter
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
</intent-filter>
그리고이 intent filter
이 그 action
if (getIntent().getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
Log.d(TAG, "************** USB unplugged stopping service **********");
Toast.makeText(getBaseContext(), "usb was disconneced", Toast.LENGTH_LONG).show();
stopService(new Intent(this, myService.class));
} else {
init();
}
을 위해 그리고 내 manifest
내부의 의도를 확인합니다.
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>
그러나 분리가 호출되지 않습니다.
이 좋아,하지만 활동이있을 때 어떤 일이 발생 백그라운드에서, 또는 파괴되고 있습니까? – user1940676
수신자를 서비스에 등록하십시오.) – Dediqated
활동에서 브로드 캐스트 리시버를 시작하지 않으려면 AndroidManifest.xml에 정의하십시오. – msh