Android Sharing---Call system comes with the sharing function

Source: Internet
Author: User

We used to think of the integration of the Friend Alliance and other platforms to share the function, and the integration of this thing also had to download the corresponding jar package. Of course, the sharing of these platforms is not to say what the benefits are not, at least the statistical function of others is very practical. However, sometimes we do not need redundant features, only need to be able to share the line, then we can directly use the andriod system with the sharing function to complete. Let me show you how to implement the System sharing function:

Share text messages
1 New Intent (intent.action_send); 2 intent.settype ("Text/plain"); 3 Intent.putextra (Intent.extra_text, TEXT); 4 context.startactivity (Intent.createchooser (Intent, title));

Share a single picture
1 New Intent (intent.action_send); 2 intent.settype ("Image/png"); 3 Intent.putextra (Intent.extra_stream, URI); 4 context.startactivity (Intent.createchooser (intent,title));

Here to explain, the picture file to first throughgetResourcesUri()拿到图片资源的Path,然后再转换成URI对象放入intent.putExtra()的第二个参数中。

Share multiple picture files
1 New Intent (intent.action_send_multiple); 2 Mulintent.putparcelablearraylistextra (Intent.extra_stream, imageuris); 3 mulintent.settype ("Image/jpeg"); 4 context.startactivity (Intent.createchooser (mulintent, "multi-image file sharing"));

We can create a selector, after the user has chosen more, put the URI collection, and then directly can be shared through the above code, sharing the effect and the same.

The above share, has been organized into a tool class, the code is as follows:

1  PackageHuolongluo.sharedemo;2 3 ImportAndroid.content.Context;4 Importandroid.content.Intent;5 ImportAndroid.net.Uri;6 7 Importjava.util.ArrayList;8 9 /**Ten * Created by Fire dragon Bare on 2017/11/2. One  */ A  Public classShareutil - { -  the     Private Static FinalString email_address = "[EMAIL protected]"; -  -      Public Static voidSharetext (Context context, string text, string title) -     { +Intent Intent =NewIntent (intent.action_send); -Intent.settype ("Text/plain"); + Intent.putextra (Intent.extra_text, TEXT); A context.startactivity (Intent.createchooser (Intent, title)); at     } -  -      Public Static voidShareimage (context context, Uri Uri, String title) -     { -Intent Intent =NewIntent (intent.action_send); -Intent.settype ("Image/png"); in Intent.putextra (Intent.extra_stream, URI); - context.startactivity (Intent.createchooser (Intent, title)); to     } +  -      Public Static voidSendEmail (Context context, String title) the     { *Intent Intent =NewIntent (Intent.action_sendto, Uri.parse ("mailto:" +email_address)); $ context.startactivity (Intent.createchooser (Intent, title));Panax Notoginseng     } -  the      Public Static voidSendmoreimage (context context, arraylist<uri>Imageuris, String title) +     { AIntent mulintent =NewIntent (intent.action_send_multiple); the Mulintent.putparcelablearraylistextra (Intent.extra_stream, imageuris); +Mulintent.settype ("Image/jpeg"); -Context.startactivity (Intent.createchooser (mulintent, "multi-image file sharing")); $     } $}

Android Sharing---Call system comes with the sharing function

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.