Android USB status monitoring (solution scheme = & quot; file & quot ;)

Source: Internet
Author: User

Learning USB status monitoring can be called tangle.

 

First: no time required (new USB-related APIs for Android)

Check and find that the USB-related content is added to Android, for example, double-click the image to enlarge it ):

 

650) this. width = 650; "border =" 0 "alt =" "src =" http://img1.51cto.com/attachment/201204/174849781.jpg "/>

OK. I like reading documents very much. Key points: installed with android devices (android-powered) connected to usb, there are two States, see the next (double-click figure can be enlarged), document Portal: http://developer.android.com/guide/topics/usb/index.html

See: http://www.eoeandroid.com/forum.php? Mod = viewthread & tid = 115776.

Note: The kiosks translation may be incorrect and should be translated as a terminal.

650) this. width = 650; "border =" 0 "alt =" "src =" http://img1.51cto.com/attachment/201204/175028685.jpg "/>

First: Peripheral mode accessory mode)

E. g.: diagnosis device or unplug a computer-connected mobile phone)

It can be used from 2.3.4. You need to introduce additional libraries and the code is different from the standard API.

Manifest file needs to be configured

Second: host mode)

Starting from android3.1

Eg: Mouse, USB flash drive, android set-top box, etc)

Of course, these new APIs are often useful. But, there are wood, there are wood, we commonly used host mode, actually 2.3.4 does not support. Okay. You can only use the old method.

 

Article 2: Do not worry or hate yourself (problems not found in the document)

 

The idea of listening to USB is to listen to the broadcast sent by the system for USB plugging. Use broadcast listening to obtain the USB status. Therefore, in Intent, find the Media-related Action information as follows (double-click the image to enlarge it ):

 

650) this. width = 650; "border =" 0 "alt =" "src =" http://img1.51cto.com/attachment/201204/175324601.jpg "/>

So Register in the manifest file), configure various actions to be listened to in the filter, as follows: (double-click the figure to enlarge)

650) this. width = 650; "border =" 0 "alt =" "src =" http://img1.51cto.com/attachment/201204/175340947.jpg "/>

However, the OnReceiver () method is not listened. Actually wood has a reaction. Later, someone told me that scheme = "file" is missing, but why? I checked the document and did not mention this. Why? What is it?

 

The third line: You need to find the answer in the source code of the contact)

 

Since the document is not explicitly stated, view the source code. Search for the keyword "ACTION_MEDIA_BAD_REMOVAL". The result is as follows: (double-click the image to enlarge it)

650) this. width = 650; "border =" 0 "alt =" "src =" http://img1.51cto.com/attachment/201204/175808219.jpg "/>

 

Obviously, when the system sends this broadcast, it adds "file: //" in front of it. Because it is added during sending, it must be added when filtering; otherwise, it cannot be filtered.

Similarly, the search keyword "ACTION_MEDIA_MOUNTED" is as follows: (double-click the image to enlarge it)

 

650) this. width = 650; "border =" 0 "alt =" "src =" http://img1.51cto.com/attachment/201204/180053218.jpg "/>

The solution to the problem is simple. Set Scheme in the Data item in the registration information to file. The Code is as follows: (double-click the figure to enlarge)

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/0T20IQ6-6.jpg "/>

Now that this is a hidden problem, let's look for another broadcast with scheme added in front of it. We searched for the keyword "sendBroadcast" and found numerous results. We continued to search for "Uri. parse ", there are only two options, that is, the option corresponding to" ACTION_MEDIA_MOUNTED. This is just an example.

This article is from the "small new column" blog, please be sure to keep this source http://mikewang.blog.51cto.com/3826268/845195

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.