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_MA开发者_开发问答SS_STORAGE_ENABLED,1)
The code above is not working though. Am I need to pass any intent for this?
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?!
精彩评论