Android calls the system to share content to other apps, without using the system's Actionbar popup, fully customizable

Source: Internet
Author: User

Android share content to other applications, call System dialog or Actionbar pop-up windows are not too free, limited too much, here I provide a fully customizable interface, you can pop windows, or directly in the activity or fragment inside the custom interface. Here to show a key class of code, do the encapsulation processing, I write two demo, free source in: http://download.csdn.net/detail/yanzhenjie1003/8565449

/** * @author YOLANDA * @Time April 5, 2015 PM 1:03:11 */public Class Shareutil {/** * Get app data to display * @author YOLANDA * @param co ntext * @param type * @return */public static arraylist<listdrawableitem> getshowdata (context context, List<reso lveinfo> resolveinfos) {arraylist<listdrawableitem> drawableitems = new Arraylist<listdrawableitem> () ;  Packagemanager Mpackagemanager = Context.getpackagemanager (); for (int i = 0; i < resolveinfos.size (); i++) {ResolveInfo info = Resolveinfos.get (i); Listdrawableitem dialogitementity = new Listdrawableitem (Info.loadlabel (Mpackagemanager), Info.loadIcon ( Mpackagemanager));d Rawableitems.add (dialogitementity);} return drawableitems;} /** * Share content via system * @author YOLANDA * @param context * @param choosertitle selector title * @param packagename Package name * @param imgpatho Rtext picture Path or text * @param type share content types */public static void Exeshare (context context, string choosertitle, String Packagenam E, String imgpathortext, type type) {Intent Intent = new Intent (inTent. action_send); switch (type) {case Image:intent.setType ("image/*"); File Imgpath = new file (Imgpathortext); Uri uri = uri.fromfile (Imgpath); Intent.putextra (Intent.extra_stream, URI); Break;case Text:intent.setType ("text/ Plain "); Intent.putextra (Intent.extra_text, Imgpathortext); Intent.setpackage (PackageName); Intent.setflags (intent.flag_activity_new_task); try {context.startactivity ( Intent.createchooser (Intent, Choosertitle));} catch (Activitynotfoundexception e) {}}/** * get support for sharing apps * @author YOLANDA * @param context * @return */public static LIST&L T Resolveinfo> Getsharetargets (context context, type type) {list<resolveinfo> Mapps = new arraylist< Resolveinfo> (); Intent Intent = new Intent (intent.action_send, null); Intent.addcategory (Intent.category_default); Switch (type) {case Image:intent.setType ("image/*"); Break;default:intent.settype ("Text/plain"); Packagemanager pm = Context.getpackagemanager (); Mapps = Pm.queryintentactivities (Intent, Packagemanager.component_enabled_state_default); return Mapps;} /** * Share Type * @Project Smartcontrol * @Class Shareutil.java * @author YOLANDA * @Time March 4, 2015 morning 10:21:16 */public enum Ty pe{/** picture **/image,/** text **/text;}}


Android calls the system to share content to other apps, without using the system's Actionbar popup, fully customizable

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.