微博SDK更新到11.6
This commit is contained in:
@ -13,6 +13,7 @@ import android.util.Base64;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.gh.common.Base64ImageHolder;
|
||||
import com.gh.common.constant.Config;
|
||||
import com.gh.common.util.BiCallback;
|
||||
import com.gh.common.util.EnergyTaskHelper;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
@ -25,13 +26,17 @@ import com.sina.weibo.sdk.api.ImageObject;
|
||||
import com.sina.weibo.sdk.api.TextObject;
|
||||
import com.sina.weibo.sdk.api.WebpageObject;
|
||||
import com.sina.weibo.sdk.api.WeiboMultiMessage;
|
||||
import com.sina.weibo.sdk.auth.AuthInfo;
|
||||
import com.sina.weibo.sdk.common.UiError;
|
||||
import com.sina.weibo.sdk.openapi.IWBAPI;
|
||||
import com.sina.weibo.sdk.openapi.WBAPIFactory;
|
||||
import com.sina.weibo.sdk.share.WbShareCallback;
|
||||
import com.sina.weibo.sdk.share.WbShareHandler;
|
||||
import com.sina.weibo.sdk.utils.Utility;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by khy on 2016/11/23.
|
||||
@ -48,6 +53,11 @@ public class WeiBoShareActivity extends Activity implements WbShareCallback {
|
||||
private static final String KET_TYPE = "KET_TYPE";
|
||||
private static final String KET_SUMMARY = "KET_SUMMARY";
|
||||
|
||||
private static final String WEIBO_SCOPE = (
|
||||
"email,direct_messages_read,direct_messages_write,"
|
||||
+ "friendships_groups_read,friendships_groups_write,statuses_to_me_read,"
|
||||
+ "follow_app_official_microblog," + "invitation_write");
|
||||
|
||||
private String shareUrl;
|
||||
|
||||
private String mShareStyle;
|
||||
@ -55,7 +65,7 @@ public class WeiBoShareActivity extends Activity implements WbShareCallback {
|
||||
private String mSummary;
|
||||
private String mShareType;
|
||||
|
||||
private WbShareHandler mWeiboShareAPI;
|
||||
private IWBAPI mWBAPI;
|
||||
|
||||
@NonNull
|
||||
public static Intent getWeiboShareIntent(Context context, String shareUrl, String shareIcon,
|
||||
@ -103,14 +113,14 @@ public class WeiBoShareActivity extends Activity implements WbShareCallback {
|
||||
|
||||
Utils.toast(this, R.string.share_skip);
|
||||
|
||||
mWeiboShareAPI = new WbShareHandler(this);
|
||||
mWeiboShareAPI.registerApp();
|
||||
mWBAPI = WBAPIFactory.createWBAPI(this);
|
||||
mWBAPI.registerApp(this, new AuthInfo(this, Config.WEIBO_APPKEY, "http://www.sina.com", WEIBO_SCOPE));
|
||||
|
||||
if ("NORMAL".equals(mShareStyle)) {
|
||||
if (shareIcon != null) {
|
||||
loadIconAndShare(shareIcon);
|
||||
} else {
|
||||
onWbShareFail();
|
||||
onError(new UiError(0, "", ""));
|
||||
}
|
||||
} else if ("IMAGE".equals(mShareStyle)) {
|
||||
shareImage();
|
||||
@ -120,7 +130,7 @@ public class WeiBoShareActivity extends Activity implements WbShareCallback {
|
||||
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
mWeiboShareAPI.doResultIntent(intent, this); //当前应用唤起微博分享后,返回当前应用
|
||||
mWBAPI.doResultIntent(intent, this); //当前应用唤起微博分享后,返回当前应用
|
||||
}
|
||||
|
||||
private void loadIconAndShare(String iconUrl) {
|
||||
@ -158,22 +168,37 @@ public class WeiBoShareActivity extends Activity implements WbShareCallback {
|
||||
}
|
||||
|
||||
ImageObject imageObject = new ImageObject();
|
||||
imageObject.setImageObject(bgBitmap);//设置缩略图。 注意:最终压缩过的缩略图大小不得超过 32kb。
|
||||
imageObject.setImageData(bgBitmap);//设置缩略图。 注意:最终压缩过的缩略图大小不得超过 32kb。
|
||||
|
||||
WebpageObject webObject = new WebpageObject();
|
||||
webObject.identify = Utility.generateGUID();
|
||||
webObject.identify = UUID.randomUUID().toString();
|
||||
webObject.title = "";
|
||||
webObject.description = getString(R.string.app_name);
|
||||
webObject.defaultText = getString(R.string.app_name);
|
||||
webObject.actionUrl = shareUrl;
|
||||
webObject.setThumbImage(bgBitmap);
|
||||
ByteArrayOutputStream os = null;
|
||||
try {
|
||||
os = new ByteArrayOutputStream();
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, os);
|
||||
webObject.thumbData = os.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (os != null) {
|
||||
os.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
WeiboMultiMessage weiboMessage = new WeiboMultiMessage();//初始化微博的分享消息
|
||||
weiboMessage.textObject = textObject;
|
||||
weiboMessage.imageObject = imageObject;
|
||||
weiboMessage.mediaObject = webObject;
|
||||
|
||||
mWeiboShareAPI.shareMessage(weiboMessage, false);
|
||||
mWBAPI.shareMessage(weiboMessage, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -189,14 +214,14 @@ public class WeiBoShareActivity extends Activity implements WbShareCallback {
|
||||
// 转完后重新置位
|
||||
Base64ImageHolder.INSTANCE.setImage("");
|
||||
|
||||
Bitmap compressBitmap = compressBitmap(bitmap) ;
|
||||
Bitmap compressBitmap = compressBitmap(bitmap);
|
||||
ImageObject imageObject = new ImageObject();
|
||||
imageObject.setImageObject(compressBitmap);
|
||||
imageObject.setImageData(compressBitmap);
|
||||
|
||||
WeiboMultiMessage weiboMessage = new WeiboMultiMessage();//初始化微博的分享消息
|
||||
weiboMessage.imageObject = imageObject;
|
||||
|
||||
mWeiboShareAPI.shareMessage(weiboMessage, false);
|
||||
mWBAPI.shareMessage(weiboMessage, false);
|
||||
}
|
||||
|
||||
public Bitmap compressBitmap(Bitmap bitmap) {
|
||||
@ -223,7 +248,7 @@ public class WeiBoShareActivity extends Activity implements WbShareCallback {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWbShareSuccess() {
|
||||
public void onComplete() {
|
||||
Utils.toast(this, R.string.share_success_hint);
|
||||
if ("NORMAL".equals(mShareStyle)) {
|
||||
LogUtils.uploadShareResult(ShareUtils.shareType, ShareUtils.shareEntrance.getName(), "success",
|
||||
@ -240,22 +265,7 @@ public class WeiBoShareActivity extends Activity implements WbShareCallback {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWbShareCancel() {
|
||||
Utils.toast(this, R.string.share_cancel_hint);
|
||||
if ("NORMAL".equals(mShareStyle)) {
|
||||
LogUtils.uploadShareResult(ShareUtils.shareType, ShareUtils.shareEntrance.getName(), "cancel",
|
||||
ShareUtils.shareEntity.getShareUrl(), ShareUtils.shareEntity.getShareTitle(), ShareUtils.shareEntity.getSummary(), ShareUtils.resourceId);
|
||||
if (ShareUtils.shareEntrance == ShareUtils.ShareEntrance.inviteFriends) {
|
||||
IntegralLogHelper.INSTANCE.logInviteResult("取消", "微博");
|
||||
}
|
||||
} else {
|
||||
IntegralLogHelper.INSTANCE.logInviteResult("取消", "微博");
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWbShareFail() {
|
||||
public void onError(UiError uiError) {
|
||||
Utils.toast(this, R.string.share_fail_hint);
|
||||
if ("NORMAL".equals(mShareStyle)) {
|
||||
LogUtils.uploadShareResult(ShareUtils.shareType, ShareUtils.shareEntrance.getName(), "fail",
|
||||
@ -268,4 +278,19 @@ public class WeiBoShareActivity extends Activity implements WbShareCallback {
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
Utils.toast(this, R.string.share_cancel_hint);
|
||||
if ("NORMAL".equals(mShareStyle)) {
|
||||
LogUtils.uploadShareResult(ShareUtils.shareType, ShareUtils.shareEntrance.getName(), "cancel",
|
||||
ShareUtils.shareEntity.getShareUrl(), ShareUtils.shareEntity.getShareTitle(), ShareUtils.shareEntity.getSummary(), ShareUtils.resourceId);
|
||||
if (ShareUtils.shareEntrance == ShareUtils.ShareEntrance.inviteFriends) {
|
||||
IntegralLogHelper.INSTANCE.logInviteResult("取消", "微博");
|
||||
}
|
||||
} else {
|
||||
IntegralLogHelper.INSTANCE.logInviteResult("取消", "微博");
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user