Accept data shared by third-party apps and shared by third-party apps

Source: Internet
Author: User

Accept data shared by third-party apps and shared by third-party apps

Some time ago, the company's project needed a requirement to accept data shared by third-party apps to their own apk. The third-party apps involved were Youtube, Amazon, and NetFlix, these apps share the current information through the sharing function. Put it bluntly, put the code on,

1. First, add the red box code to your app's AndroidManifest. xml. It must be android. intent. action. MAIN activity:

2. Then add the following code to the started activity:

 

3. Resolution:

Intent filter will tell the system program what it is going to receive. Similar to how to use ACTION_SEND to create intent, you can create an intent filter to receive intent with this operation. Use the <intent-filter> element in manifest to define an intent filter. For example, if a program can receive text, a single image of any type, or multiple images of any type.

When other programs share the above class content by creating intent and passing it to startActivity (), your program will be displayed in the intent chooser list. If you select your program, the corresponding activity (in the example above. ui. myActivity) will be started. Then you can process the content in the Code and interface.

To process the data transmitted by Intent, call getIntent () to obtain the Intent object. Once this object is obtained, you can view the data to determine what to do next. Remember, if the activity can be started from other parts of the system, such as launcher, you need to consider these situations when viewing intent.

Note:You must be extremely careful when checking the incoming data. You do not know what other programs will bring in. For example, the MIME type may be set incorrectly, or the image may be very large. Remember to process binary data in another thread instead of the UI thread.

Updating the UI can be as simple as filling EditText, or more difficult as adding an interesting filter to an image. It is up to your program to decide what will happen next.

 

I wrote my blog for the first time. I am not writing well. You can give me some suggestions. Thank you for your advice .......

 

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.