开发者

How to turn off USB mass storage programmatically in Android?

开发者 https://www.devze.com 2023-04-04 13:23 出处:网络
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?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消