0
USBがPCに接続されている場合、サービスを停止できるかどうか疑問に思っていますか?USB接続時のサービス非アクティブ化
if(intent.getAction().equals(Intent.ACTION_UMS_DISCONNECTED)) {
Intent intent2=new Intent(context,MyService.class);
context.startActivity(intent2);
}
else if (intent.getAction().equals(Intent.ACTION_UMS_CONNECTED)) {
stopService(new Intent(this, MyService.class));
}
私はこれを与えましたが、動作しませんでした。
'did not work'は良い説明です。あなたはこのコードをどのような文脈で持っていますか? – WarrenFaith