1

I want to turn on/off the USB mass storage in Android.

I tried the below code. It's not working. Can any one please help me in this?

To disable the Mass storage I have used this:

Settings.Secure.putInt(getcontentResolver(),Settings.Secure_MASS_STORAGE_ENABLED,0)

To enable the Mass storage I have used this:

Settings.Secure.putInt(getcontentResolver(),Settings.Secure_MASS_STORAGE_ENABLED,1)

The code above is not working though. Am I need to pass any intent for this?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Rams
  • 11
  • 1
  • 2
  • check this link [here][1] [1]: http://stackoverflow.com/questions/7396757/programmatically-turn-off-usb-storage-on-android-devices – School Boy Sep 14 '11 at 06:35

1 Answers1

2

First, you can't modify Settings.Secure.MASS_STORAGE_ENABLED even you have claimed WRITE_SETTINGS and WRITE_SECURE_SETTINGS in AndroidManifest.xml, because Settings.Secure.* only can be modified by apps in system/app, of course, read operation has not limits.

Second, I have searched the whole source code(both Gingerbread and ICS) and found that Settings.Secure.MASS_STORAGE_ENABLED has not been used currently, I am confused since Settings.Secure.ADB_ENABLED is used. please Google tell me why? will be implemented in next release?

Third, 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?!

tonykwok
  • 161
  • 2
  • 5