Programmatically Turn Off USB Storage on Android Devices

前端 未结 3 1237
说谎
说谎 2020-12-06 01:20

On many android devices, when the device is plugged into the USB port of a computer or even on some USB charging devices, the phone goes into USB Storage mode. When the devi

相关标签:
3条回答
  • 2020-12-06 01:45

    You can detect it (you have the link), but, AFAIK, you can't mount/unmount USB storage at least not with the public SDK APIs. In Honeycomb (3.0 and above), USB mass storage is no longer used to access the device's external storage, so your app and a computer can access it simultaneously.

    0 讨论(0)
  • 2020-12-06 01:49

    It blocks mass storage by using reflection on storageManger api . Storage Manager api is avaliable from sdk level -9.

    I am not able to reflect Mountservice api which can target less os level. If any one has done it please give suggestions

    0 讨论(0)
  • 2020-12-06 01:53

    A1: If current state of Sd card is SHARED it means that it has connected to PC in MSC mode, you can check this case as following:

    String state = Environment.getExternalStorageState();
    if (Environment.MEDIA_SHARED.equals(state)) {
        // Sd card has connected to PC in MSC mode
    }
    

    A2: You can force to turn off usb mass storage connection by calling:

    MountService.setUsbMassStorageEnabled(false);
    

    or

    StorageManager.disableUsbMassStorage();
    

    but unfortunately, both these API are not public accessible?!

    0 讨论(0)
提交回复
热议问题