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 .......