一個Android輕鬆集成分享的框架。java
dependencies {
implementation 'com.ysbing.yshare:yshare:1.0.0'
implementation 'com.ysbing.yshare:qq:1.0.0'
implementation 'com.ysbing.yshare:wechat:1.0.0'
implementation 'com.ysbing.yshare:weibo:1.0.0'
}
複製代碼
android {
defaultConfig {
......
manifestPlaceholders = [
YSHARE_QQ_APPID : "123456",//騰訊開放平臺註冊應用獲得的appId
YSHARE_WECHAT_APPID : "wxdbf987654321",//微信開放平臺註冊的appId
YSHARE_WEIBO_APPKEY : "123456789",//新浪微博開放平臺註冊的appKey
YSHARE_WEIBO_REDIRECT_URL: "https://www.baidu.com/",//新浪微博開放平臺第三方應用受權回調頁地址,默認爲`http://`
YSHARE_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"//新浪微博開放平臺第三方應用 scope,多個 scope 用逗號分隔
]
}
}
複製代碼
配置全局分享參數,也能夠對單獨分享另外設置android
YShareConfig shareConfig = YShareConfig.get();
shareConfig.shareTitle = "我是標題";
shareConfig.shareUrl = "https://www.baidu.com/";
shareConfig.shareDes = "我是描述";
shareConfig.imageUrl = Uri.parse(
"https://www.baidu.com/img/bd_logo1.png");
YShare.Companion.setShareConfig(shareConfig);
複製代碼
進行分享,詳細能夠參考實例工程git
YShareConfig shareConfig = YShareConfig.get();
shareConfig.imageUrl = Uri.parse("asset:///share_image.png");
shareConfig.justImage = true;
YShare shareUtil = new YShare(this, shareConfig);
shareUtil.shareToWxFriends();
shareUtil.setShareListener(new YShareListener() {
@Override
public void onShare(@NonNull YShareConfig.ShareChannel shareChannel, @NonNull YShareConfig.ShareResult shareResult, @Nullable Bundle data) {
String log = "shareChannel:" + shareChannel + ",shareResult:" + shareResult;
Log.i("yshare_info", log);
Toast.makeText(MainActivity.this, log, Toast.LENGTH_SHORT).show();
}
});
複製代碼
若是你的工程涉及到微信登錄,須要複寫WXEntryActivity,而後繼承YWXEntryActivity,manifest的寫法以下圖: github