Android-based custom sharing

Source: Internet
Author: User

As follows:

You need to specify the five applications to be shared to the image. If the application is not installed on your mobile phone, it is displayed in gray. Click to open the application market. If the application is installed, click to open it.

Only

The main code is as follows:

 

/The *** sharing dialog box ** displays five sorted sharing apps, prompt whether to install ** program name to be shared ** @ Param program content */Public void show1__5 (final string sharecontent) {dialog = new dialog (context, R. style. DIALOG); dialog. setcontentview (R. layout. dialog_factory_share_5); Final textview TV _sina_weibo = (textview) dialog. findviewbyid (R. id. TV _sina); Final textview TV _renren = (textview) dialog. findviewbyid (R. id. TV _renren); Final textview TV _tecent_weibo = (textview) dialog. findviewbyid (R. id. TV _qq_weibo); Final textview TV _message = (textview) dialog. findviewbyid (R. id. TV _message); Final textview TV _weixin = (textview) dialog. findviewbyid (R. id. TV _weixin); final list <appinfo> export appinfos = get1_applist (); For (INT I = 0; I <export appinfos. size (); I ++) {If ("com. sina. weibo ". equals (incluappinfos. get (I ). getapppkgname () {drawable add = context. getresources (). getdrawable (R. drawable. icon_share_sinaweibo); add. setbounds (0, 0, Add. getminimumwidth (), Add. getminimumheight (); TV _sina_weibo.setcompounddrawables (ADD, null); // set the left icon TV _sina_weibo.settag (I);} If ("com. tencent. wblog ". equals (incluappinfos. get (I ). getapppkgname () {drawable add = context. getresources (). getdrawable (R. drawable. icon_pai_tecent_weibo); add. setbounds (0, 0, Add. getminimumwidth (), Add. getminimumheight (); TV _tecent_weibo.setcompounddrawables (ADD, null); // set the left icon TV _tecent_weibo.settag (I);} If ("com. android. MMS ". equals (incluappinfos. get (I ). getapppkgname () {drawable add = context. getresources (). getdrawable (R. drawable. icon_cmd_message); add. setbounds (0, 0, Add. getminimumwidth (), Add. getminimumheight (); TV _message.setcompounddrawables (ADD, null); // you can specify the left icon TV _message.settag (I);} If ("com. renren. mobile. android ". equals (incluappinfos. get (I ). getapppkgname () {drawable add = context. getresources (). getdrawable (R. drawable. icon_renren); add. setbounds (0, 0, Add. getminimumwidth (), Add. getminimumheight (); TV _renren.setcompounddrawables (ADD, null); // you can specify the left icon TV _renren.settag (I);} If ("com. tencent. mm ". equals (incluappinfos. get (I ). getapppkgname () {drawable add = context. getresources (). getdrawable (R. drawable. icon_pai_tecent_weixin); add. setbounds (0, 0, Add. getminimumwidth (), Add. getminimumheight (); TV _weixin.setcompounddrawables (ADD, null); // set the left icon TV _weixin.settag (I );}} // write the final appinfo app_sina = new appinfo ("com. sina. weibo "," com. sina. weibo. editactivity "); Final appinfo app_tx_weibo = new appinfo (" com. tencent. wblog "," com. tencent. wblog. intentproxy. tencentweibointent "); Final appinfo app_renren = new appinfo (" com. renren. mobile. android "," com. renren. mobile. android. publisher. inputpublisheractivity "); Final appinfo app_message = new appinfo (" com. android. MMS "," com. android. MMS. UI. composemessageactivity "); Final appinfo app_weixin = new appinfo (" com. tencent. mm "," com. tencent. mm. UI. tools. required imgui "); final string share = context. getstring (R. string. dialog_share1) + plain content + context. getstring (R. string. dialog_share2); listener (New onclicklistener () {@ overridepublic void onclick (view v) {setonclick (TV _sina_weibo, app_sina, share) ;}}); listener (New onclicklistener () {@ overridepublic void onclick (view v) {setonclick (TV _renren, app_renren, share) ;}}; listener (New onclicklistener () {@ overridepublic void onclick (view V) {setonclick (TV _tecent_weibo, app_tx_weibo, share) ;}}); listener (New onclicklistener () {@ overridepublic void onclick (view v) {setonclick (TV _message, app_message, share) ;}}); TV _weixin.setonclicklistener (New onclicklistener () {@ overridepublic void onclick (view v) {setonclick (TV _weixin, app_weixin, share );}}); button btn_close = (button) dialog. findviewbyid (R. id. btn_dialog_close); btn_close.setonclicklistener (New button. onclicklistener () {@ overridepublic void onclick (view v) {dialog. dismiss () ;}}); dialog. show ();}

Appinfo:

 

 

public class AppInfo {private StringAppPkgName;private StringAppLauncherClassName;private StringAppName;private DrawableAppIcon;public AppInfo() {super();}public AppInfo(String appPkgName, String appLauncherClassName) {super();AppPkgName = appPkgName;AppLauncherClassName = appLauncherClassName;}public String getAppPkgName() {return AppPkgName;}public void setAppPkgName(String appPkgName) {AppPkgName = appPkgName;}public String getAppLauncherClassName() {return AppLauncherClassName;}public void setAppLauncherClassName(String appLauncherClassName) {AppLauncherClassName = appLauncherClassName;}public String getAppName() {return AppName;}public void setAppName(String appName) {AppName = appName;}public Drawable getAppIcon() {return AppIcon;}public void setAppIcon(Drawable appIcon) {AppIcon = appIcon;}}

 

/*** Query all application information that can be shared ** @ Param context * @ return */private list <resolveinfo> getmediaapps (context) {list <resolveinfo> mapps = new arraylist <resolveinfo> (); intent = new intent (intent. action_send, null); intent. addcategory (intent. category_default); intent. settype ("text/plain"); packagemanager pmanager = context. getpackagemanager (); mapps = pmanager. queryintentactivities (intent, packagemanager. component_enabled_state_default); Return mapps;}/*** get the Application List ** @ return */private list <appinfo> get1_applist () {list <appinfo> export appinfos = new arraylist <appinfo> (); packagemanager = context. getpackagemanager (); List <resolveinfo> resolveinfos = getmediaapps (context); If (null = resolveinfos) {return NULL;} else {for (resolveinfo: resolveinfos) {appinfo = new appinfo (); appinfo. setapppkgname (resolveinfo. activityinfo. packagename); appinfo. setapplauncherclassname (resolveinfo. activityinfo. name); appinfo. setappname (resolveinfo. loadlabel (packagemanager ). tostring (); appinfo. setappicon (resolveinfo. loadicon (packagemanager); extends appinfos. add (appinfo) ;}} return response appinfos ;}

 

 

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.