RenniePet
RenniePet

Reputation: 11658

Programmatically switch USB between shared (disk mode) and mounted (charge only)

I have an old HTC Desire S connected to my PC with a USB cable, and am doing development work on both a PC program and an Android app. It is convenient for me to have the PC program write some test data to the Android device's SD card (needs shared mode), and then for the Android app to read this test data from the SD card (needs mounted mode, otherwise it gets a FileNotFoundException with "permission denied").

I can manually switch back and forth between the shared and mounted modes by pulling down the notification tray menu on the Android device, and using the "USB connection type" menu item.

But that's inconvenient, so my question is, are there some Android API calls I can make, so my Android app can switch the USB connection to mounted mode, read the test data, and then switch back to shared mode so it's ready for the next iteration of my PC program?

Upvotes: 1

Views: 907

Answers (1)

Chris Stratton
Chris Stratton

Reputation: 40407

Rather than toggling the USB mode back and forth, consider if it might be effective and more convenient to transfer your development test data to and from the device using the adb push and adb pull commands.

If you strongly prefer GUI interfaces, there is a file browser built atop adb push/pull in the DDMS tool, and perhaps also in whatever the Android Studio equivalent of that is.

Upvotes: 1

Related Questions