Accept data shared by third-party apps

Source: Internet
Author: User

Some time ago the company project needed a need: to accept data from third-party apps to its own apk, the third-party app involved was: Youtube/amazon/netflix, which shared the current information through the sharing function. Nonsense less say, on the code,

1. First add the code of the red box to the androidmanifest.xml of your app, and be sure to Android.intent.action.MAIN activity:

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

3. Analysis:

Intent Filter tells the system what the program is going to receive. Just like in front of how to create intent with Action_send , create a intent filter to receive intent with this operation . Use the <intent-filter> element in manifest to define a intent filter. For example, if a program can receive text, any type of single picture, or more than one type of picture.

When other programs share the above class capacity by creating intent and then passing it to startactivity (), your program will appear in the Intent Chooser list, if the user chooses your program, The corresponding activity (. Ui.myactivity in the example above) will be started. Then it's up to you to work with the content in the code and the interface.

To process the data passed by intent, first call Getintent () to get the intent object. Once you have this object, you can decide what to do next by looking at the data. Remember that 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: to check the incoming data with extra care, you don't know what other programs are passing in. For example, it is possible to set the wrong MIME type, or the picture may be very large. Also remember to process the binary data in another thread instead of the UI thread.

Updating the UI can be as simple as filling a edittext, or it might be harder to add an interesting filter to a picture. Your program will decide what happens next.

I am the first time to write a blog, write bad, we can give suggestions, thank you for your advice ....

Accept data shared by third-party apps

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.