[Android] share

Source: Internet
Author: User

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/>} 

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.