SocialComponent
社會化元件
整合步驟
1、依賴library庫
2、給Project的build.gradle檔案新增如下程式碼:
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://dl.bintray.com/thelasterstar/maven/" }
}
}
複製程式碼
3、配製AndroidManifest.xml,新增如下程式碼:
<application
android:name=".base.BaseApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SecondActivity" />
<!--微信配置開始-->
<activity
android:name=".wxapi.WXEntryActivity"
android:exported="true" />
<activity
android:name=".wxapi.WXPayEntryActivity"
android:exported="true" />
<!--微信配置結束-->
<!--qq配置開始-->
<activity
android:name="com.tencent.tauth.AuthActivity"
android:launchMode="singleTask"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tencent1107009250" />
</intent-filter>
</activity>
<activity
android:name="com.tencent.connect.common.AssistActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<!--qq配置結束-->
</application>
複製程式碼
4、在自己的包名下新增wxapi包及裡面的所有java檔案
5、在自定義的Application中初始化
//初始化資料
SocialHelper.get().setQqAppId("1107009250")
.setWxAppId("wx2847b18acb41e535")
.setWxAppSecret("78f713b76c61a38242e63ccdb3a96d68")
.setWbAppId("2214687859")
.setWbRedirectUrl("https://github.com/fengqingxiuyi");
複製程式碼
功能詳情
各功能使用詳情,請參考MainActivity.java
例如:
/**
* 分享
*/
public void jump2Share(View view) {
ShareDataBean shareDataBean = new ShareDataBean();
HashMap<Integer, Integer> shareTypeList = new HashMap<>();
shareTypeList.put(ISocialType.SOCIAL_WX_SESSION, WXShareHelper.TYPE_WEB);
shareTypeList.put(ISocialType.SOCIAL_WX_TIMELINE, WXShareHelper.TYPE_WEB);
shareTypeList.put(ISocialType.SOCIAL_WX_MINIPROGRAM, WXShareHelper.TYPE_MINIPROGRAM);
shareTypeList.put(ISocialType.SOCIAL_QQ, QQShareHelper.TYPE_IMAGE_TEXT);
shareTypeList.put(ISocialType.SOCIAL_WB, WBShareHelper.TYPE_TEXT);
shareDataBean.shareType = shareTypeList;
shareDataBean.shareTitle = "百度一下,你就知道";
shareDataBean.shareDesc = "全球最大的中文搜尋引擎、致力於讓網民更便捷地獲取資訊,找到所求。百度超過千億的中文網頁資料庫,可以瞬間找到相關的搜尋結果。";
shareDataBean.shareImage = "https://www.baidu.com/img/bd_logo1.png";
shareDataBean.shareUrl = "https://www.baidu.com/";
shareDataBean.shareMiniType = 0; //小程式型別 - 正式版:0,測試版:1,體驗版:2
shareDataBean.shareMiniAppId = "gh_64c734bc4b8d"; //小程式AppId
shareDataBean.shareMiniPage = "pages/fitting-room/index"; //小程式頁面地址
ArrayList<SocialTypeBean> socialTypeBeans = new ArrayList<>();
socialTypeBeans.add(new SocialTypeBean(ISocialType.SOCIAL_WX_SESSION));
socialTypeBeans.add(new SocialTypeBean(ISocialType.SOCIAL_WX_TIMELINE));
socialTypeBeans.add(new SocialTypeBean(ISocialType.SOCIAL_SMS));
socialTypeBeans.add(new SocialTypeBean(ISocialType.SOCIAL_COPY));
socialTypeBeans.add(new SocialTypeBean(ISocialType.SOCIAL_REFRESH));
socialTypeBeans.add(new SocialTypeBean(ISocialType.SOCIAL_CUSTOM, "https://img.ezprice.com.tw/is/c.rimg.com.tw/s1/4/7e/29/21628111029801_843_s.jpg", "自定義圖示需要整合圖片庫"));
socialTypeBeans.add(new SocialTypeBean(ISocialType.SOCIAL_QQ));
socialTypeBeans.add(new SocialTypeBean(ISocialType.SOCIAL_WB));
socialTypeBeans.add(new SocialTypeBean(ISocialType.SOCIAL_WX_MINIPROGRAM));
socialTypeBeans.add(new SocialTypeBean(ISocialType.SOCIAL_ALIPAY));
socialTypeBeans.add(new SocialTypeBean(ISocialType.SOCIAL_COLLECTION));
socialTypeBeans.add(new SocialTypeBean(ISocialType.SOCIAL_SHOW_ALL));
SocialHelper.get().share(this, socialTypeBeans, shareDataBean, new IShareCallback() {
@Override
public void onSuccess(int socialType, String msg) {
Toast.makeText(MainActivity.this, "MainActivity onSuccess, socialType = " + socialType +", msg = " + msg, Toast.LENGTH_SHORT).show();
}
@Override
public void onError(int socialType, String msg) {
Toast.makeText(MainActivity.this, "MainActivity onError, socialType = " + socialType +", msg = " + msg, Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel(int socialType) {
Toast.makeText(MainActivity.this, "MainActivity onCancel, socialType = " + socialType, Toast.LENGTH_SHORT).show();
}
});
}
複製程式碼