This section describes how to implement the sharing function in your own applications and how to add your programs to the sharing list.
For example, if you want to share an image on campus.
This is what we want to do. At the same time, we will add our own applications to the sharing list.
The code for calling out the "Sharing Method" is as follows:
Intent intent = new intent (intent. action_send); </P> <p> intent. settype ("text/plain"); <br/> intent. putextra (intent. extra_subject, "share"); <br/> intent. putextra (intent. extra_text, "something to share with you! "); <Br/> startactivity (intent. createchooser (intent, gettitle ()));
How can I add my own applications to this sharing list?
The answer is actually quite simple. You only need to add the following code between the activity tags in the androidmanifest. xml configuration file:
<Intent-filter> <br/> <action Android: Name = "android. intent. action. send "> <br/> </Action> <br/> <category Android: Name =" android. intent. category. default "> <br/> </Category> <br/> <data Android: mimetype = "text/plain"> <br/> </data> <br/> </intent-filter>
Note: It is best to test the above program on a real machine, and the simulator cannot see the effect!
In addition, some users may not want to display these applications. For example, if you want to send text messages or emails, you can obtain the sharing list first and then filter the list by yourself.
Get the sharing list Code:
Public list <resolveinfo> getsharetargets () {<br/> List <resolveinfo> mapps = new arraylist <resolveinfo> (); <br/> intent = new intent (intent. action_send, null); <br/> intent. addcategory (intent. category_default); <br/> intent. settype ("text/plain"); <br/> packagemanager PM = This. getpackagemanager (); <br/> mapps = PM. queryintentactivities (intent, packagemanager. component_enabled_state_default); </P> <p> return mapps; <br/>}