Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android检测设备的USB装载和卸载_Android_Broadcastreceiver - Fatal编程技术网

Android检测设备的USB装载和卸载

Android检测设备的USB装载和卸载,android,broadcastreceiver,Android,Broadcastreceiver,我想检测从我的设备上安装或卸载USB的时间 我曾尝试使用广播接收器中连接的Intent.ACTION_UMS_,但不起作用 @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_UMS_CONNECTED)) { Toast.makeText(context, "mounted usb", Toast.LEN

我想检测从我的设备上安装或卸载USB的时间

我曾尝试使用广播接收器中连接的Intent.ACTION_UMS_,但不起作用

@Override public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_UMS_CONNECTED)) {
        Toast.makeText(context, "mounted usb", Toast.LENGTH_LONG).show();
    } else if (intent.getAction().equals(Intent.ACTION_UMS_DISCONNECTED)) {
        Toast.makeText(context, "Un-mounted usb", Toast.LENGTH_LONG).show();
    }

嗨,尼克,欢迎来到堆栈溢出。如果您能更具体地说明出现了什么问题,并可能向我们展示一些您尝试过的代码,那么它将帮助人们向您提供建议。例如,您提到Intent.ACTION_UMS_CONNECTED not working-向我们展示代码块及其产生的错误如何?为什么它不工作?你能把日志寄出去吗?和logt这是广播接收器onreceive方法中的我的代码。我也在我的活动中注册了接收者@重写ReceiveContext上下文上的public void,Intent Intent{ifintent.getAction.equalsIntent.ACTION_UMS_已连接{Toast.makeTextcontext,挂载usb,Toast.LENGTH_LONG.show;}否则ifintent.getAction.equalsIntent.ACTION_UMS_已断开{Toast.makeTextcontext,Un-mounted usb,Toast.LENGTH_LONG.show;}@Nik将代码编辑成您的原始问题会更有帮助-我已经为您解决了这个问题,但是您可能需要检查换行符和缩进是否正确,因为我不熟悉Java.ya它是否正确。thanks@BiscuitBaker