一鍵接入分享,有比它更優雅的嗎?

1、介紹

一個Android輕鬆集成分享的框架。java

2、框架特性

  • 目前已支持QQ、微信、微博
  • 平臺選擇性接入,避免沒用到的平臺接入致使體積增大
  • 微信分享能夠不用複寫WXEntryActivity類,框架已經幫你內部處理穩當

3、安裝

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'
}
複製代碼

4、快速上手

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

Github 開源地址:github.com/ysbing/ysha…

有任何建議和bug,歡迎你們提Issue

相關文章
相關標籤/搜索