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