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