Android Third party login, share (SHARESDK, friends) _android

Source: Internet
Author: User
Tags getmessage openid prepare throwable

Prepare for the project below, write a demo of third party login and share. Use the SHARESDK and the Alliance respectively to achieve.

First of all, I feel the use of both, personal feeling sharesdk better than the league, but where? Fortunately, the artificial service. In the process of integration encountered a variety of problems, but the sharesdk of human Services to do a good job, to answer questions, to provide solutions to the problem!
Next on the code (this article uses the Android Studio development, SHARESDK version v2.7.7, Friend League version v6.0.0):

First, use SHARESDK (SHARESDK version v2.7.7) to integrate:

1, to go to the official website:http://www.mob.com/ registered account, add applications, download the SDK, respectively, to Sina, micro-letter, QQ open Platform registration application, get key. Get ready for this, let's get started!
2, add the following permissions in the manifest file:

<uses-permission android:name= "Android.permission.GET_TASKS"/>
 <uses-permission android:name= " Android.permission.INTERNET "/>
 <uses-permission android:name=" Android.permission.ACCESS_WIFI_STATE " >
 <uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/>
 < Uses-permission android:name= "Android.permission.CHANGE_WIFI_STATE"/>
 <uses-permission android:name= " Android.permission.WRITE_EXTERNAL_STORAGE "/>
 <uses-permission android:name=" android.permission.READ_ Phone_state "/>
 <uses-permission android:name= android.permission.MANAGE_ACCOUNTS"/>
 < Uses-permission android:name= "Android.permission.GET_ACCOUNTS"/>
 <!--bluetooth to share the required permissions-->
 < Uses-permission android:name= "Android.permission.BLUETOOTH"/>
 <uses-permission android:name= " Android.permission.BLUETOOTH_ADMIN "/>

3, continue to add the activity of information, * * Note here Tencent behind the AppID to maintain and you configure the QQ appid consistent * *:

 &lt;!--call QQ, need to register the callback activity--&gt; &lt;activity android:name= "Com.mob.tools.MobUIShell" Android:theme= "@android: Style/theme.translucent.notitlebar "android:configchanges=" Keyboardhidden|orientation|screensize "Android: screenorientation= "Portrait" android:windowsoftinputmode= "Statehidden|adjustresize" &gt; &lt;intent-filter&gt; ;d ata android:scheme= "tencent100371282"/&gt; &lt;action android:name= "Android.intent.action.VIEW"/&gt; &lt;cat Egory android:name= "Android.intent.category.BROWSABLE"/&gt; &lt;category android:name= " Android.intent.category.DEFAULT "/&gt; &lt;/intent-filter&gt; &lt;!--call Sina Native SDK, need to register the callback activity--&gt; &lt;intent-f ilter&gt; &lt;action android:name= "Com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY"/&gt; &lt;category Ame= "Android.intent.category.DEFAULT"/&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;!--invoke micro-letters that require registered callback activity-- &gt; &lt;!--micro-credit sharing callback--&gt; &lt;activity android:name= ". Wxapi. Wxentryactivity "ANdroid:theme= "@android: Style/theme.translucent.notitlebar" android:configchanges= "keyboardhidden|orientation|
 ScreenSize "android:exported=" true "android:screenorientation=" Portrait "/&gt;

4, to the assets directory under the Sharesdk.xml directory to modify the ready QQ, micro-letter, micro-blog key.
Note here: 4.1, the Assets folder is in the root directory of main.
4.2, QQ and qzone use of the same AppID, Appkey
4.3, micro-letter and Friends Circle, collection using the same AppId, Appsecret
4.4, Micro-bo remove configuration Appkey, Appsecret, but also need to configure
Redirecturl= "Http://sns.whalecloud.com/sina2/callback"
The value of RedirectURL is consistent with the authorization callback page at the microblogging application information

5, to add a micro-letter callback
5.1. Create a package named "Wxapi" below the package name
5.2, the demo in the "Wxentryactivity" put in, note that this class does not need to move, do not need to manually call!!
! [Wxentryactivity's Location] (http://img.blog.csdn.net/20161015153103561)

6, to write code.
Prepare Publicstaticdata.java in advance:

Package com.example.lql.sharesdk.utils;


Import Com.umeng.socialize.UMShareAPI;

Import Cn.sharesdk.framework.ShareSDK;

public class Publicstaticdata {public
  static sharesdk mysharesdk;
  public static Umshareapi Mshareapi;
}

6.0 initialization
publicstaticdata.mysharesdk= new Sharesdk ();
PublicStaticData.myShareSDK.initSDK (Getapplicationcontext ());
6.1, open the sharing panel

/** * @param title * @param text content * @param picurl Picture Link * * QQ and QQ space settings Share link use settitleurl (); * Set Title: Settitle * Content: SetText * Set network Picture: Oks.setimageurl ("yun_qi_img/owwplzo_638x960.jpg"); * Set Local Picture://oks.setimagepath ("/sdcard/test.jpg");/ensure that the picture exists under SDcard * * The micro-letter * URL is used only in micro-letters (including friends and friends) * Oks.seturl ("http:// Qq.com "); * *
  private void Showshare (String title,string text,string picurl) {
    onekeyshare OKs = new Onekeyshare ();
    Turn off SSO licensing
    oks.disablessowhenauthorize ();
    Oks.settitle (title);
    Oks.settext (text);
    if (picurl!=null) {
      oks.setimageurl (picurl);
    }
    Start sharing GUI
    oks.show (this);
  }

6.2. Share to the designated platform (use micro-letters and microblogs here for example)

/** * Micro-trust in micro-credit sharing, you need to set the Setsharetype attribute, which should be noted here * @param title * @param content * @param picurl * @par Am Titleurl * platform.share_text (share text), Platform.share_image (share picture), Platform.share_webpage (share the page, both graphic sharing), Platform.share_music (sharing audio), Platform.share_video (sharing video), Platform.share_apps (sharing apps, only micro-trust support), Platform.share_file (share file  , only micro-letter support) Platform.share_emoji (share expression, only micro-letter support)/public static void Sharewx (String title,string content,string picurl,string
    Titleurl) {type= "share";
    Wechat.shareparams sp=new wechat.shareparams ();
    Sp.settitle (title);
    Sp.settext (content); if (titleurl!=null) {sp.settitleurl (Titleurl);//Title Hyperlink} if (Picurl!=null) {sp.setimageurl (Picurl);
    Picture address} sp.setsharetype (platform.share_image);
    Sp.seturl ("http://qq.com");
    Platform WX = PublicStaticData.myShareSDK.getPlatform (wechat.name); Wx. Setplatformactionlistener (Mplatformactionlistener);
  Set up Share event callback//execute graphic sharing wx.share (SP); }
  /** * Share to micro-Bo * @param text content * @param picurl network picture (the document shows that the sharing of the picture needs to be approved, the test is not required to reflect)
  /public static void Sharesina (String Text,string picurl) {
    type= "share";
    Sinaweibo.shareparams sp = new Sinaweibo.shareparams ();
    Sp.settext (text);
    if (picurl!=null) {
      sp.setimageurl (picurl);
    }
    Platform Weibo = PublicStaticData.myShareSDK.getPlatform (sinaweibo.name);
    Weibo.setplatformactionlistener (Mplatformactionlistener); Set up Share event callback
//execute graphic sharing
    weibo.share (sp);
  

6.3 Third-party login

  /** * Login * @param name login mode (qq.name, Wechat.name, sinaweibo.name)/public
  static void login (String name) {
    type= "l Ogin ";
    Platform mplatform = sharesdk.getplatform (name);
    Mplatform.setplatformactionlistener (Mplatformactionlistener);
    Mplatform.authorize ()//individually authorized, OnComplete return hashmap is empty
    mplatform.showuser (null);/authorize and obtain user information
  }

6.4 Login and share callback (here to share and login to use a listener)

  public static Platformactionlistener mplatformactionlistener= new Platformactionlistener () {@Override public V
        OID OnComplete (Platform Platform, int i, hashmap&lt;string, object&gt; HashMap) {if (Type.equals ("login")) {
        LOG.E ("OnComplete", "Login Successful"); LOG.E ("OpenID", Platform.getdb (). GetUserID ())//Get the OpenID log.e after login ("username", Platform.getdb (). GetUserName ());
      Get the user's nickname}else{log.e ("OnComplete", "share success"); } @Override public void OnError (Platform Platform, int i, throwable throwable) {log.e ("OnError", thro
      Wable.tostring () + "");
      if (type.equals ("login")) {LOG.E ("OnError", "Login Failed" +throwable.tostring ());
      }else{log.e ("OnError", "Sharing Failure" +throwable.tostring ()); @Override public void OnCancel (Platform Platform, int i) {if (Type.equals ("login")) {LOG.E (
      "OnCancel", "Login cancellation");
      }else{log.e ("OnCancel", "share cancellation");

 }
    }
  };

7, so that the use of SHARESDK integration common three types of login to share the completion of the whole process did not encounter serious problems, the overall experience effect is not bad. On the overall code Sharesdkutils.java:

Package com.example.lql.sharesdk.utils;
Import Android.content.Context;

Import Android.util.Log;

Import Java.util.HashMap;
Import Cn.sharesdk.framework.Platform;
Import Cn.sharesdk.framework.PlatformActionListener;
Import Cn.sharesdk.framework.ShareSDK;
Import Cn.sharesdk.sina.weibo.SinaWeibo;
Import Cn.sharesdk.tencent.qq.QQ;
Import Cn.sharesdk.tencent.qzone.QZone;
Import Cn.sharesdk.wechat.favorite.WechatFavorite;
Import Cn.sharesdk.wechat.friends.Wechat;

Import cn.sharesdk.wechat.moments.WechatMoments; /** * Created by LQL on 2016/10/14.

  * * Public class Sharesdkutils {private static String type= ""; /** * Share to micro-Bo * @param text content * @param picurl network image (can be added after auditing)/public static void Sharesina (String text,string picur
    L,context context) {type= "share";
    Sinaweibo.shareparams sp = new Sinaweibo.shareparams ();
    Sp.settext (text);
    if (picurl!=null) {sp.setimageurl (Picurl);
   } Platform Weibo = PublicStaticData.myShareSDK.getPlatform (sinaweibo.name); Weibo.setplatformactionlistener (Mplatformactionlistener);
  Set up Share event callback//execute graphic sharing weibo.share (SP); /** * Share to QQ space * @param title * @param content * @param picurl picture * @param titleurl title link/public static V
    OID Shareqzone (String title,string content,string picurl,string titleurl) {type= "share";
    Qzone.shareparams sp = new Qzone.shareparams ();
    Sp.settitle (title);
    Sp.settext (content);
    if (titleurl!=null) {sp.settitleurl (Titleurl);//Title Hyperlink} if (Picurl!=null) {sp.setimageurl (Picurl);
    } Platform Qzone = PublicStaticData.myShareSDK.getPlatform (qzone.name); Qzone. Setplatformactionlistener (Mplatformactionlistener);
  Set up Share event callback//execute graphic sharing qzone.share (SP); /** * QQ * @param title * @param content * @param picurl * @param titleurl/public static void Shareqq (String tit
    le,string content,string picurl,string titleurl) {type= "share"; Qq. Shareparams sp=new QQ.
    Shareparams ();
   Sp.settitle (title); Sp.settext (content);
    if (titleurl!=null) {sp.settitleurl (Titleurl);//Title Hyperlink} if (Picurl!=null) {sp.setimageurl (Picurl);
    Platform QQ = PublicStaticData.myShareSDK.getPlatform (qq.name); QQ. Setplatformactionlistener (Mplatformactionlistener);
  Set up Share event callback//execute graphic sharing qq.share (SP); /** * Collection * @param title * @param content * @param picurl * @param titleurl/public static void Sharewxf (String ti
    tle,string content,string picurl,string titleurl) {type= "share";
    Wechatfavorite.shareparams sp=new wechatfavorite.shareparams ();
    Sp.settitle (title);
    Sp.settext (content);
    if (titleurl!=null) {sp.settitleurl (Titleurl);//Title Hyperlink} if (Picurl!=null) {sp.setimageurl (Picurl);
    } sp.setsharetype (Platform.share_image);
    Sp.seturl ("http://www.163.com/");
    Platform QQ = PublicStaticData.myShareSDK.getPlatform (wechatfavorite.name); QQ. Setplatformactionlistener (Mplatformactionlistener); Set up Share event callback
    Execute picture and text sharing qq.share (SP); /** * Friends Circle * @param title * @param content * @param picurl * @param titleurl/public static void Sharewxm (String
    title,string content,string picurl,string titleurl) {type= "share";
    Wechatmoments.shareparams sp=new wechatmoments.shareparams ();
    Sp.settitle (title);
    Sp.settext (content);
    if (titleurl!=null) {sp.settitleurl (Titleurl);//Title Hyperlink} if (Picurl!=null) {sp.setimageurl (Picurl);
    } sp.setsharetype (Platform.share_image);
    Sp.seturl ("http://www.sina.com.cn");
    Platform QQ = PublicStaticData.myShareSDK.getPlatform (wechatmoments.name); QQ. Setplatformactionlistener (Mplatformactionlistener);
  Set up Share event callback//execute graphic sharing qq.share (SP); /** * @param title * @param content * @param picurl * @param titleurl * platform.share_text (share text), Platform.sha Re_image (share picture), Platform.share_webpage (share the page, share the text), Platform.share_music (share audio), Platform.share_video (Share video), Platform.share_apps (Share application, onlyMicro-letter support), Platform.share_file (share file, only micro-letter support) Platform.share_emoji (share expression, only micro-letter support)/public static void Sharewx (String title,
    String content,string picurl,string titleurl) {type= "share";
    Wechat.shareparams sp=new wechat.shareparams ();
    Sp.settitle (title);
    Sp.settext (content);
    if (titleurl!=null) {sp.settitleurl (Titleurl);//Title Hyperlink} if (Picurl!=null) {sp.setimageurl (Picurl);
    } sp.setsharetype (Platform.share_image);
    Sp.seturl ("http://qq.com");
    Platform WX = PublicStaticData.myShareSDK.getPlatform (wechat.name); Wx. Setplatformactionlistener (Mplatformactionlistener);
  Set up Share event callback//execute graphic sharing wx.share (SP);
    /** * Login/public static void login (String name) {type= "login";
    Platform mplatform = sharesdk.getplatform (name);
    Mplatform.setplatformactionlistener (Mplatformactionlistener); Mplatform.authorize ()//individually authorized, OnComplete return hashmap is empty mplatform.showuser (null);/authorize and obtain user information} public static platfor MactionlisteNER mplatformactionlistener= New Platformactionlistener () {@Override public void OnComplete (Platform Platform, in
        t i, hashmap&lt;string, object&gt; HashMap) {if (Type.equals ("login")) {LOG.E ("OnComplete", "Login succeeded"); LOG.E ("OpenID", Platform.getdb (). GetUserID ())//Get the OpenID log.e after login ("username", Platform.getdb (). GetUserName ());
      Get the user's nickname}else{log.e ("OnComplete", "share success"); } @Override public void OnError (Platform Platform, int i, throwable throwable) {log.e ("OnError", thro
      Wable.tostring () + "");
      if (type.equals ("login")) {LOG.E ("OnError", "Login Failed" +throwable.tostring ());
      }else{log.e ("OnError", "Sharing Failure" +throwable.tostring ()); @Override public void OnCancel (Platform Platform, int i) {if (Type.equals ("login")) {LOG.E (
      "OnCancel", "Login cancellation");
      }else{log.e ("OnCancel", "share cancellation");
}
    }
  };
 }

Use in activity

String picurl= "Yun_qi_img/owwplzo_638x960.jpg";
        Case r.id.openshare://Open the sharing panel and directly invoke the method written above Showshare ("Sharesdk test", "SHARESDK test", Picurl);
      Break
        Case R.ID.QQLOGIN://QQ Login Sharesdkutils.login (qq.name);
      Break
        Case r.id.wxlogin://Micro-letter login Sharesdkutils.login (wechat.name);
      Break
        Case r.id.sinalogin://Micro-Blog Login sharesdkutils.login (sinaweibo.name);
      Break
        Case r.id.wxlike://Collection sharing (micro-letters need to have pictures) sharesdkutils.sharewxf ("micro-credit collection sharing test title SHARESDK", "micro-credit collection sharing test content sharesdk", picurl,null);
      Break Case r.id.wxfriendsshare://friend Circle Share (micro letter needs to have pictures) sharesdkutils.sharewxm ("Friend Circle sharing test title sharesdk", "Friends circle sharing test Content sharesdk", Picurl,
        NULL);
      Break
        Case r.id.wxshare://micro-letter sharing (micro-letter needs to have pictures) sharesdkutils.sharewx ("micro-credit sharing test title SHARESDK", "micro-credit sharing test content sharesdk", picurl,null);
      Break
        Case r.id.sinashare://microblogging sharing Sharesdkutils.sharesina ("Sina sharing Test Sharesdk", null,mainactivity.this);
      Break Case R.id.qzoneshare://Space Sharesdkutils.shareqzone ("Qzone share test title sharesdk", "Qzone share test Content sharesdk", picurl,null);
      Break
        Case R.ID.QQSHARE://QQ sharesdkutils.shareqq ("Qzone share test title sharesdk", "Qzone share test Content sharesdk", picurl,null);
 Break

Second, the use of the Alliance to integrate (AU version v6.0.0 (lite)):

1, here omitted registration, download the SDK, the process of preparing the key, directly from the integration start.
2. Permission:

&lt;uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/&gt; &lt;uses-permission android:name= "Android.permission.ACCESS_WIFI_STATE"/&gt; &lt;uses-permission android:name= "android.permission.READ_PHONE_ State "/&gt; &lt;uses-permission android:name=" Android.permission.WRITE_EXTERNAL_STORAGE "/&gt; &lt;uses-permission Android:name= "Android.permission.READ_EXTERNAL_STORAGE"/&gt; &lt;uses-permission android:name= " Android.permission.INTERNET "/&gt; &lt;uses-permission android:name= Android.permission.READ_LOGS"/&gt; &lt; Uses-permission android:name= "Android.permission.CALL_PHONE"/&gt; &lt;uses-permission android:name= " Android.permission.ACCESS_FINE_LOCATION "/&gt; &lt;uses-permission android:name=" Android.permission.ACCESS_COARSE _location "/&gt; &lt;uses-permission android:name=" Android.permission.GET_TASKS "/&gt; &lt;uses-permission android: Name= "Android.permission.SET_DEBUG_APP"/&gt; &lt;uses-permission android:name= "Android.permission.SYSTEM_ALERT_" Window "/&gt;
&lt;uses-permission android:name= "Android.permission.GET_ACCOUNTS"/&gt; &lt;uses-permission android:name= " Android.permission.USE_CREDENTIALS "/&gt; &lt;uses-permission android:name=" Android.permission.MANAGE_ACCOUNTS "

 &gt;

3, Add activity information (use micro-Bo version here, Sina Weibo does not need to callback activity) * * Note here Tencent AppID to maintain and you configure the QQ appid consistent * *:
 

&lt;!--################## #添加UmengAppkey ######################--&gt; &lt;meta-data android:name= "Umeng_appkey" Android:value= "577c404367e58e6b1f001a40" &gt; &lt;/meta-data&gt; &lt;!--invoke micro-letters that need to register the callback activity--&gt; &lt;activity Android:name= ". Wxapi. Wxentryactivity "android:configchanges=" Keyboardhidden|orientation|screensize "android:exported=" true "Android:
screenorientation= "Portrait" Android:theme= "@android: Style/theme.translucent.notitlebar"/&gt; &lt;!--call QQ--&gt; &lt;activity android:name= "com.tencent.tauth.AuthActivity" android:launchmode= "Singletask" True "&gt; &lt;intent-filter&gt; &lt;action android:name=" Android.intent.action.VIEW "/&gt; &lt;category Android:name= "Android.intent.category.DEFAULT"/&gt; &lt;category android:name= "Android.intent.category.BROWSABLE" "/&gt; &lt;data android:scheme=" tencent100424468 "/&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activ ity android:name= "Com.tencent.connect.common.aSsistactivity "android:screenorientation=" Portrait "Android:theme=" @android: Style/theme.translucent.notitlebar "

 android:configchanges= "Orientation|keyboardhidden|screensize"/&gt;

4, on the code:

4.0 initialization:

    Platformconfig.setweixin ("WX282305CC871B77BC", "bdf0b6e3ff283ec29a12abf40ff62c1a");
    Platformconfig.setsinaweibo ("170221996", "75314930606f946864ee0d7aeecc46ed");
    Config.redirect_url = "Http://sns.whalecloud.com/sina2/callback";//Your Sina backend callback address
    Platformconfig.setqqzone (" 1105747496 "," Evhtbi0p5ndpuniz ");
    Umshareapi.get (this);

4.1 Open Sharing Panel

 New ShareAction (Mainactivity.this). Withtext ("Test ah Test ah").
            withtitle ("Test ah Test ah")
            . Withmedia (New Umimage ( Mainactivity.this, Picurl))           . Setdisplaylist (Share_media. Sina,share_media. Qq,share_media. Weixin,share_media. Qzone,share_media. Weixin_circle,share_media. Weixin_favorite)
            . Setcallback (Umsharelistener). open ();

4.2 Share to the top platform

  /** * Share * @param mactivity * @param title * @param context content * @param sharetype sharing method * Share_media. Weixin_favorite * Share_media. Weixin_circle * Share_media. Weixin * Share_media. SINA * Share_media. QZONE * Share_media. QQ * @param picurl picture address
  /public static void Sharepic (activity mactivity,string title,string Context,share_media Shar Etype,string picurl) {
    umengshare.myactivity=mactivity;
    if (picurl!=null) {
      new ShareAction (mactivity). Setplatform (Sharetype). Withtext (Context
          ).
          Withtitle ( title)
          . Withmedia (New Umimage (Mactivity,picurl)).
          Setcallback (Umsharelistener)
          . Share ();
    } else{
      New ShareAction (mactivity). Setplatform (Sharetype). Withtext (Context
          ).
          Withtitle (title)
          . Setcallback (Umsharelistener)
          . Share ();
    }
  

4.3 Share listener callback

 /** * Sharing monitor
  /public static Umsharelistener Umsharelistener = new Umsharelistener () {
    @Override public
    void on Result (Share_media platform) {
      log.d ("Plat", "Platform" +platform);
      Toast.maketext (myactivity, platform + "sharing success", Toast.length_short). Show ();
    @Override public
    void OnError (Share_media platform, Throwable t) {
      toast.maketext (Myactivity,platform +) sharing failed ", Toast.length_short). Show ();
      if (t!=null) {
        log.d ("Throw", "Throw:" +t.getmessage ());
      }
    @Override public
    void OnCancel (Share_media platform) {
      Toast.maketext (Myactivity,platform + "Share Canceled", Toast.length_short). Show ();
    }
  ;

4.4 Login

  /** * Third-party login * @param mactivity * @param type login mode * Share_media. QQ * Share_media. Weixin * Share_media. SINA *
  /public static void Umenglogin (activity mactivity,share_media type) {
    umengshare.myactivity=mactivity;
    Publicstaticdata.mshareapi = Umshareapi.get (mactivity);
    PublicStaticData.mShareAPI.doOauthVerify (Mactivity,type, Umauthlistener);
  }

4.5 Login Callback

  /** * Third-party login monitor
  /public static Umauthlistener Umauthlistener = new Umauthlistener () {
    @Override public
    void on Complete (Share_media platform, int action, map<string, string> data) {
      Toast.maketext (myactivity, "authorized success", Toast.length_short). Show ();
      LOG.E ("Data", data.tostring ());
    }
    @Override public
    void OnError (Share_media platform, int action, Throwable t) {
      toast.maketext (myactivity, "Authorization failed ", Toast.length_short). Show ();
      LOG.E ("Data", t.tostring () + "");
    }

    @Override public
    void OnCancel (Share_media platform, int action) {
      toast.maketext (myactivity, "Turn off Authorization", Toast.length_short). Show ();
      LOG.E ("Data", "Turn off Authorization");
    }
  ;

5. In some low-end mobile phone may appear QQ no callback situation, need to add the following code in the activity:

  /** * Friend League QQ Login required callback in some low-end mobile phone login after the callback, need this method * @param requestcode * @param * * @param data * * *
  @Override
  Prot ected void Onactivityresult (int requestcode, int resultcode, Intent data) {
    Super.onactivityresult (Requestcode, ResultCode, data);
    Umshareapi.get (This). Handleqqerror (Mainactivity.this,requestcode,umauthlistener);
    PublicStaticData.mShareAPI.onActivityResult (Requestcode, ResultCode, data);
  }

6, the same is no callback, this is a micro-letter, need to add code in the wxentryactivity:

  @Override
  protected void handleintent (Intent Intent) {

    Mwxhandler.setauthlistener (new Umauthlistener () {
      @Override public
      void OnComplete (Share_media platform, int action, map<string, string> data) {
        LOG.E ("Umwxhandler Fsdfsdfs" +data.tostring ());
      }

      @Override public
      void OnError (Share_media platform, int action, Throwable t) {
        log.e ("Umwxhandler Fsdfsdfs", T.tostring ());
      }

      @Override public
      void OnCancel (Share_media platform, int action) {
        log.e ("Umwxhandler Fsdfsdfs", "OnCancel") ;
      }
    });
    Super.handleintent (intent);
  }

7, so that the use of friends and allies to integrate common three types of login to share the completion of the way. On the overall code Umengshare.java:

Package com.example.lql.sharesdk.utils; Import Android.
Manifest;
Import android.app.Activity;
Import Android.os.Build;
Import Android.support.v4.app.ActivityCompat;
Import Android.util.Log;

Import Android.widget.Toast;
Import com.umeng.socialize.ShareAction;
Import Com.umeng.socialize.UMAuthListener;
Import Com.umeng.socialize.UMShareAPI;
Import Com.umeng.socialize.UMShareListener;
Import Com.umeng.socialize.bean.SHARE_MEDIA;

Import Com.umeng.socialize.media.UMImage;

Import Java.util.Map; /** * Created by LQL on 2016/10/15.


  * * Public class Umengshare {private static activity myactivity; /** * Share * @param mactivity * @param title * @param context content * @param sharetype sharing method * Share_media. Weixin_favorite * Share_media. Weixin_circle * Share_media. Weixin * Share_media. SINA * Share_media. QZONE * Share_media. QQ * @param picurl picture address/public static void Sharepic (activity mactivity,string title,string Context,share_media Sharet Ype,string picurl) {Umengshare.myactivity=mactivity; if (picurl!=null) {new ShareAction (mactivity). Setplatform (Sharetype). Withtext (context). withtitl
    E (title). Withmedia (New Umimage (Mactivity,picurl)). Setcallback (Umsharelistener). Share (); }else{new ShareAction (mactivity). Setplatform (Sharetype). Withtext (context). Withtitle (title
    ). Setcallback (Umsharelistener). Share (); }/** * Third-party login * @param mactivity * @param type Login method * Share_media. QQ * Share_media. Weixin * Share_media.
    SINA */public static void Umenglogin (activity mactivity,share_media type) {umengshare.myactivity=mactivity;
    Publicstaticdata.mshareapi = Umshareapi.get (mactivity);
  PublicStaticData.mShareAPI.doOauthVerify (Mactivity,type, Umauthlistener); /** * Third-party login monitor/public static Umauthlistener Umauthlistener = new Umauthlistener () {@Override public voi D OnComplete (Share_media platform, int action, map&lt;string, StrinG&gt; data) {Toast.maketext (myactivity, "authorized Success", Toast.length_short). Show ();
    LOG.E ("Data", data.tostring ());  @Override public void OnError (Share_media platform, int action, Throwable t) {Toast.maketext (myactivity,
      "Authorization Failed", Toast.length_short). Show ();
    LOG.E ("Data", t.tostring () + ""); @Override public void OnCancel (Share_media platform, int action) {toast.maketext (myactivity, "Turn off authorization", to Ast.
      Length_short). Show ();
    LOG.E ("Data", "close Authorization");

  }
  }; /** * Sharing monitor/public static Umsharelistener Umsharelistener = new Umsharelistener () {@Override public void onre
      Sult (Share_media platform) {LOG.D ("plat", "Platform" +platform);
    Toast.maketext (myactivity, platform + "sharing success", Toast.length_short). Show (); @Override public void OnError (Share_media platform, Throwable t) {toast.maketext (Myactivity,platform + "
      Share failure, Toast.length_short. Show (); if (t!=null) {log.d ("throw", "Throw:" +T.getmessage ()); @Override public void OnCancel (Share_media platform) {toast.maketext (Myactivity,platform + "Share Canceled"
    , Toast.length_short). Show ();
}
  };


 }

Use in activity:

 Case r.id.openshareumeng://Share panel new ShareAction (mainactivity.this). Withtext ("Test ah Test ah"). Withtitle ("Test Ah test "). Withmedia (New Umimage (Mainactivity.this, Picurl)). Setdisplaylist (Share_media. Sina,share_media. Qq,share_media. Weixin,share_media. Qzone,share_media. Weixin_circle,share_media.
        Weixin_favorite). Setcallback (Umsharelistener). open ();
      Break Case R.ID.QQLOGINUMENG://QQ Login Umengshare.umenglogin (mainactivity.this,share_media.
        QQ);
      Break Case r.id.wxloginumeng://Micro-letter login Umengshare.umenglogin (Mainactivity.this,share_media.
        Weixin);
      Break Case r.id.sinaloginumeng://Weibo login Umengshare.umenglogin (Mainactivity.this,share_media.
        SINA);
      Break Case r.id.wxlikeumeng://Collection sharing (micro-letters need to have pictures) umengshare.sharepic (mainactivity.this, "Test Collection", "Test Favorites", Share_media.
        Weixin_favorite,picurl);
      Break Case r.id.wxfriendsshareumeng://friend Circle Share (micro letter needs to have pictures) Umengshare.sharePic (mainactivity.this, "Test Friends Circle", "test the circle of Friends", Share_media.
        Weixin_circle,picurl);
      Break Case r.id.wxshareumeng://micro-letter sharing (micro-letters need to have pictures) umengshare.sharepic (mainactivity.this, "Test sharing", "Test sharing content", Share_media.
        Weixin,picurl);
      Break Case r.id.sinashareumeng://Weibo share umengshare.sharepic (mainactivity.this, "Test Weibo", "Test microblogging content", Share_media.
        Sina,null);
      Break Case r.id.qzoneshareumeng://Space Umengshare.sharepic (mainactivity.this, "Test Space", "Test space content", Share_media.
        Qzone,null);
      Break Case R.id.qqshareumeng://qq Umengshare.sharepic (mainactivity.this, "Test QQ", "Test QQ content", Share_media.
        Qq,null);

 Break

Finally, the two ways are integrated well, the small partners to quickly use it. My ability is effective, if the bug is purely normal! Recommended use of sharesdk!

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.