Android calls the system to share the shared content to other applications, and does not use the pop-up window of the system's ActionBar, which is completely customized. androidactionbar

Source: Internet
Author: User

Android calls the system to share the shared content to other applications, and does not use the pop-up window of the system's ActionBar, which is completely customized. androidactionbar

When Android shares content to other apps, the pop-up window of the calling system's Dialog or ActionBar is not very free and the limit is too large. Here I provide a fully customized interface that can pop up the window, you can also customize the interface directly in Activity or Fragment. Here I show a key class code, do the encapsulation processing, I write two Demo, free source code in: http://download.csdn.net/detail/yanzhenjie1003/8565449

/*** @ Author YOLANDA * @ Time 1:03:11 on October 11 */public class ShareUtil {/*** get the application data to be displayed * @ author YOLANDA * @ param context * @ param type * @ return */public static ArrayList <ListDrawableItem> getShowData (Context context, list <ResolveInfo> 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); drawableItems. add (dialogItemEntity);} return drawableItems ;} /*** share the content via the system * @ author YOLANDA * @ param context * @ param ChooserTitle selector title * @ param packageName package name * @ param imgPathOrText image path or text *@ param type: type of the shared content */public static void exeShare (Context context, string chooserTitle, String packageName, 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); break;} intent. setPackage (packageName); intent. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK); try {context. startActivity (Intent. createChooser (intent, chooserTitle);} catch (ActivityNotFoundException e) {}}/*** get the application that supports sharing * @ author YOLANDA * @ param context * @ return */public static List <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"); break;} PackageManager pm = context. getPackageManager (); mApps = pm. queryIntentActivities (intent, PackageManager. COMPONENT_ENABLED_STATE_DEFAULT); return mApps;}/*** sharing type * @ Project SmartControl * @ Class ShareUtil. java * @ author YOLANDA * @ Time March 4, 2015 10:21:16 */public enum Type {/** Image **/Image,/** Text **/Text ;}}


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.