Android检测USB挂载和从设备卸载

时间:2014-04-17 11:35:39

标签: android broadcastreceiver

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

我尝试在广播接收器中使用Intent.ACTION_UMS_CONNECTED,但它无效。

@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();
    }

0 个答案:

没有答案
相关问题