ShareSdk使用心得

1. 微信和朋友圈:分享的时候设置了链接和图片,但就是不显示:

  需要指明ShareType为WEB_PAGE

2. 需要完整添加 ShareSdk 的所需要的权限,不然分享闪退,并且不报异常;网络请求也是同理,切记,不要浪。

3. 新浪微博的分享比较特殊,不直接支持 url,需要将 url 与 text 拼接起来,所以需要监听回调:

 1                 // 由于新浪微博只支持text+Image的格式,只能将URL添加在text里面
 2                 oks.setShareContentCustomizeCallback(new ShareContentCustomizeCallback() {
 3                     @Override
 4                     public void onShare(Platform platform, cn.sharesdk.framework.Platform.ShareParams paramsToShare) {
 5 
 6                         if ("SinaWeibo".equals(platform.getName())) {
 7                             paramsToShare.setText(mNews.getTitle() + ServiceCenter.getNewsUrl(mNews.getId()));
 8                             paramsToShare.setUrl(null);// 将其他平台的 url 置空
 9                         }
10                     }
11                 });

3.1 微信朋友圈分享比较特殊,只有 title,没有 text,所以需要在回调中重写朋友圈的 title,改为原本由 text 显示的内容

 1                 // 重写朋友圈的 title
 2                 oks.setShareContentCustomizeCallback(new ShareContentCustomizeCallback() {
 3                     @Override
 4                     public void onShare(Platform platform, cn.sharesdk.framework.Platform.ShareParams paramsToShare) {
 5 
 6                         Log.d("leo", "platForm:" + platform.getName());
 7 
 8                         if ("WechatMoments".equals(platform.getName())) {
 9                             paramsToShare.setTitle(mNews.getTitle());
10                         }
11                     }
12                 });

 

4. 新浪微博指定平台的分享,回调监听:

 1             Platform sinaWeibo = ShareSDK.getPlatform(SinaWeibo.NAME);
 2 
 3             sinaWeibo.setPlatformActionListener(new PlatformActionListener() {
 4 
 5                 @Override
 6                 public void onError(Platform arg0, int arg1, Throwable arg2) {
 7                     Toast.makeText(getContext(), "分享失败", Toast.LENGTH_SHORT).show();
 8                     Log.d("leo", "分享失败" + arg2);
 9                 }
10 
11                 @Override
12                 public void onComplete(Platform arg0, int arg1, HashMap<String, Object> arg2) {
13                     Toast.makeText(getContext(), "分享成功", Toast.LENGTH_SHORT).show();
14                     Log.d("leo", "分享成功");
15                 }
16 
17                 @Override
18                 public void onCancel(Platform arg0, int arg1) {
19                     Toast.makeText(getContext(), "分享取消", Toast.LENGTH_SHORT).show();
20                     Log.d("leo", "分享取消");
21                 }
22 
23             });
24 
25             sinaWeibo.share(sp);

5. Manifest 配置:

 1         <!-- shareSdk -->
 2         <activity
 3             android:name="com.mob.tools.MobUIShell"
 4             android:configChanges="keyboardHidden|orientation|screenSize"
 5             android:screenOrientation="portrait"
 6             android:theme="@android:style/Theme.Translucent.NoTitleBar"
 7             android:windowSoftInputMode="stateHidden|adjustResize" >
 8 
 9             <!-- 调用新浪原生SDK,需要注册的回调activity -->
10             <intent-filter>
11                 <action android:name="com.sina.weibo.sdk.action.ACTION_SDK_REQ_ACTIVITY" />
12 
13                 <category android:name="android.intent.category.DEFAULT" />
14             </intent-filter>
15 
16             <!-- qq&qq空间 -->
17             <intent-filter>
18                 <data android:scheme="tencent1105111708" />
19 
20                 <action android:name="android.intent.action.VIEW" />
21 
22                 <category android:name="android.intent.category.BROWSABLE" />
23                 <category android:name="android.intent.category.DEFAULT" />
24             </intent-filter>
25         </activity>
26 
27         <!-- 微信分享回调 -->
28         <activity
29             android:name="cn.baonajia.and.wxapi.WXEntryActivity"
30             android:configChanges="keyboardHidden|orientation|screenSize"
31             android:exported="true"
32             android:screenOrientation="portrait"
33             android:theme="@android:style/Theme.Translucent.NoTitleBar" />

 

posted @ 2016-01-12 11:01  鲸歌  阅读(327)  评论(0编辑  收藏  举报