How to set USB connection mode?

I am writing an application that should dump data on an SD card, and then another application on a PC that should read data when the device is connected to a computer (in disk mode). My HTC Legend has a dialog box to choose between: Charge only, HTC Sync, Disk drive ..

Is it possible to set the mode with which the device connects to the PC, or at least the intention to ask the user to switch the mode?

+4
source share
5 answers

I did not find a way to configure the mode programmatically, but I believe that you can call up the settings menu programmatically, causing the same activity that the system calls from the notification area. Unfortunately, this is similar to the manufacturer's specifics: on my phone it is com.htc.android.psclient.SwitchUsbSettings .

0
source

On HTC devices, open the ConnectToPC service (while USB is not connected) in “Application Management” (ICS - it may also apply to Gingerbread, I don’t remember) and click “Clear data”. Then plug in the USB drive again and you should have the option "Don't ask again." Select the desired mode, check the box and accept.

0
source

CompanionLink does this when you request USB synchronization in your Android application: it cleans the data to SD, then exports the SD as storage ("drive") on the USB device, and then expects the user to manually signal the android when completed PC using SD and then turn off SD export to USB again. Although the CompanionLink application can be very frustrating, at least that part is (pretty much) reliable.

Unfortunately, I do not know the technical details, it is quite possible that I need to find out them in one of these months. If you can't get any relevance to Android docs, perhaps you could explore what CompanionLink does for android to implement this. The sequence described above is when it is configured to synchronize via USB from a PC to the desktop (PC).

Aside, it seems that the reason for this highly complicated process is that accessing the SD SD card directly and at least the currently used FAT FS card can only support one client: the phone itself or USB. imo would be extremely helpful if shared access to the SD was possible, but that would probably require deep android changes.

0
source

For those who have this problem with the HTC One M8, it’s a bit off the wall, but it makes you think outside the box. The USB connection led to charging the device, which was.

The solution is a combination of another USB cable by uninstalling an application called Battery Doctor (which apparently likes to manage everything around your battery) and setting up a USB network - turn on Smart Network Sharing ... Apparently, unconnected ... but this combination connected to MobileGo for Android to manage and backup files, contacts and settings.

Hope this helps someone.

0
source

Yes. In Android, there is a way to change the behavior of the USB device mode when the device is connected to a PC. I used Motorola Milestone [running 2.1] and I was able to switch between the following modes: PC Suite [developed by Motorola], MemoryCardAccess and Charge. If you need to access the phone’s memory, I think you should enable “USB debugging mode” on your device. Not sure though, I think it might be convenient!

-1
source

Source: https://habr.com/ru/post/1335962/


All Articles