├── sample
├── .gitignore
├── src
│ ├── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── java
│ │ │ └── cn
│ │ │ │ └── itguy
│ │ │ │ └── allshare
│ │ │ │ └── sample
│ │ │ │ ├── SampleApplication.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── cn
│ │ │ └── itguy
│ │ │ └── allshare
│ │ │ └── sample
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── cn
│ │ └── itguy
│ │ └── allshare
│ │ └── sample
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── allshare
├── .gitignore
├── libs
│ ├── libammsdk.jar
│ └── open_sdk_r5509_lite.jar
├── src
│ └── main
│ │ ├── java
│ │ └── cn
│ │ │ └── itguy
│ │ │ └── allshare
│ │ │ ├── Callback.java
│ │ │ ├── Constants.java
│ │ │ ├── Share.java
│ │ │ ├── Content.java
│ │ │ ├── platform
│ │ │ ├── qq
│ │ │ │ ├── QQShare.java
│ │ │ │ ├── QQContent.java
│ │ │ │ └── QQEnrtyActivity.java
│ │ │ └── wx
│ │ │ │ ├── WXShare.java
│ │ │ │ ├── WXContent.java
│ │ │ │ └── WXEntryActivity.java
│ │ │ ├── AllShare.java
│ │ │ └── LogUtils.java
│ │ ├── res
│ │ └── values
│ │ │ └── strings.xml
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── LICENSE
├── gradlew.bat
├── README.md
└── gradlew
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/allshare/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample'
2 | include ':allshare'
3 |
--------------------------------------------------------------------------------
/allshare/libs/libammsdk.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/szitguy/Allshare/HEAD/allshare/libs/libammsdk.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/szitguy/Allshare/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/sample/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/szitguy/Allshare/HEAD/sample/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/allshare/libs/open_sdk_r5509_lite.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/szitguy/Allshare/HEAD/allshare/libs/open_sdk_r5509_lite.jar
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AllShare Demo
3 |
4 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/szitguy/Allshare/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/szitguy/Allshare/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/szitguy/Allshare/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/szitguy/Allshare/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/szitguy/Allshare/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/allshare/src/main/java/cn/itguy/allshare/Callback.java:
--------------------------------------------------------------------------------
1 | package cn.itguy.allshare;
2 |
3 | public interface Callback {
4 |
5 | void onSuccess();
6 |
7 | void onFailed();
8 |
9 | void onCanceled();
10 | }
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Mar 14 14:15:55 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/allshare/src/main/java/cn/itguy/allshare/Constants.java:
--------------------------------------------------------------------------------
1 | package cn.itguy.allshare;
2 |
3 | /**
4 | * Created by yelongfei490 on 2016/11/26.
5 | */
6 |
7 | public class Constants {
8 |
9 | public static final String KEY_SHARE_LISTENER = "listener";
10 | public static final String KEY_SHARE_CONTENT = "content";
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/allshare/src/main/java/cn/itguy/allshare/Share.java:
--------------------------------------------------------------------------------
1 | package cn.itguy.allshare;
2 |
3 | /**
4 | * Created by yelongfei490 on 2016/11/25.
5 | */
6 |
7 | public interface Share {
8 |
9 | int RESULT_FAILED = 0;
10 |
11 | int RESULT_SUCCESS = 1;
12 |
13 | int RESULT_CANCELD = 2;
14 |
15 | void share(Content content, Callback callback);
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/allshare/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AllShare
3 | 分享失败
4 |
5 |
6 | qqAppId
7 |
8 |
9 | wxAppId
10 |
11 | wbAppId
12 |
13 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/sample/src/test/java/cn/itguy/allshare/sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package cn.itguy.allshare.sample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test public void addition_isCorrect() throws Exception {
14 | assertEquals(4, 2 + 2);
15 | }
16 | }
--------------------------------------------------------------------------------
/sample/src/main/java/cn/itguy/allshare/sample/SampleApplication.java:
--------------------------------------------------------------------------------
1 | package cn.itguy.allshare.sample;
2 |
3 | import android.app.Application;
4 | import cn.itguy.allshare.AllShare;
5 |
6 | /**
7 | * Created by yelongfei490 on 2016/11/28.
8 | */
9 | public class SampleApplication extends Application {
10 |
11 | public static SampleApplication instance;
12 |
13 | @Override public void onCreate() {
14 | super.onCreate();
15 | instance = this;
16 |
17 | // 初始化Allshare
18 | AllShare.init(this);
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Intellij
36 | *.iml
37 | .idea/workspace.xml
38 |
39 | # Keystore files
40 | *.jks
41 |
42 | .idea/
43 |
--------------------------------------------------------------------------------
/sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/yelongfei490/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 |
13 | # When configured, Gradle will run in incubating parallel mode.
14 | # This option should only be used with decoupled projects. More details, visit
15 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
16 | # org.gradle.parallel=true
17 |
18 | BINTRAY_API_KEY=BINTRAY_API_KEY
19 | BINTRAY_USER=BINTRAY_USER
20 |
--------------------------------------------------------------------------------
/allshare/src/main/java/cn/itguy/allshare/Content.java:
--------------------------------------------------------------------------------
1 | package cn.itguy.allshare;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | /**
7 | * Created by yelongfei490 on 2016/11/25.
8 | */
9 |
10 | public abstract class Content implements Parcelable {
11 |
12 | public interface Type {
13 |
14 | int TEXT = 0;
15 |
16 | int IMAGE = 1;
17 |
18 | int LINK = 2;
19 | }
20 |
21 | private int type;
22 |
23 | public int getType() {
24 | return type;
25 | }
26 |
27 | public void setType(int type) {
28 | this.type = type;
29 | }
30 |
31 | @Override public void writeToParcel(Parcel dest, int flags) {
32 | dest.writeInt(this.type);
33 | }
34 |
35 | public Content() {
36 | }
37 |
38 | protected Content(Parcel in) {
39 | this.type = in.readInt();
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/cn/itguy/allshare/sample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package cn.itguy.allshare.sample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest {
18 | @Test public void useAppContext() throws Exception {
19 | // Context of the app under test.
20 | Context appContext = InstrumentationRegistry.getTargetContext();
21 |
22 | assertEquals("cn.itguy.allshare.sample", appContext.getPackageName());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/allshare/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/yelongfei490/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | -keep public class * extends android.app.Activity
20 |
21 | # 能够调起微信到选择好友列表,但是点击发送后无响应,请检查是否加了proguard配置,参考:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318060&token=eaabee8240cd2cfbc27bdf99e9b26507ba735023&lang=zh_CN
22 | # 微信分享库混淆配置
23 | -keep class com.tencent.mm.sdk.** {
24 | *;
25 | }
26 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Martin
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'allshare'
3 |
4 | def _applicationId = 'cn.itguy.allshare.sample'
5 | def _applicationIdBeta = 'cn.itguy.allshare.sample.beta'
6 |
7 | // 分享appId配置,package:appId对应配置,package不能用变量名来获取,只能写实际内容
8 | AllSharePlugin {
9 | qqAppIdMap = [
10 | "cn.itguy.allshare.sample": "qqAppId",
11 | "cn.itguy.allshare.sample.beta": "qqAppIdBeta"
12 | ]
13 |
14 | wxAppIdMap = [
15 | "cn.itguy.allshare.sample": "wxAppId",
16 | "cn.itguy.allshare.sample.beta": "wxAppIdBeta"
17 | ]
18 | }
19 |
20 | android {
21 | compileSdkVersion 25
22 | buildToolsVersion "25.0.2"
23 |
24 | defaultConfig {
25 | applicationId _applicationId
26 | minSdkVersion 14
27 | targetSdkVersion 25
28 | versionCode 1
29 | versionName "1.0"
30 |
31 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
32 | }
33 |
34 | productFlavors {
35 |
36 | common {
37 | }
38 |
39 | beta {
40 | applicationId _applicationIdBeta
41 | }
42 | }
43 |
44 | buildTypes {
45 |
46 | release {
47 | minifyEnabled true
48 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
49 | }
50 | }
51 |
52 | }
53 |
54 | dependencies {
55 | compile fileTree(dir: 'libs', include: ['*.jar'])
56 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
57 | exclude group: 'com.android.support', module: 'support-annotations'
58 | })
59 | compile 'com.android.support:appcompat-v7:25.3.1'
60 | testCompile 'junit:junit:4.12'
61 |
62 | // compile project(':allshare')
63 | }
64 |
--------------------------------------------------------------------------------
/allshare/src/main/java/cn/itguy/allshare/platform/qq/QQShare.java:
--------------------------------------------------------------------------------
1 | package cn.itguy.allshare.platform.qq;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.ResultReceiver;
7 | import cn.itguy.allshare.Callback;
8 | import cn.itguy.allshare.Constants;
9 | import cn.itguy.allshare.Content;
10 | import cn.itguy.allshare.Share;
11 | import java.lang.ref.WeakReference;
12 |
13 | /**
14 | * Created by yelongfei490 on 2016/11/25.
15 | */
16 |
17 | public class QQShare extends ResultReceiver implements Share {
18 |
19 | private WeakReference contextWeakRef;
20 | private Callback callback;
21 |
22 | public QQShare(Context context) {
23 | super(null);
24 | contextWeakRef = new WeakReference<>(context);
25 | }
26 |
27 | @Override public void share(Content content, Callback callback) {
28 | this.callback = callback;
29 | Context context = contextWeakRef.get();
30 | if (context != null) {
31 | context.startActivity(new Intent(context, QQEnrtyActivity.class)
32 | .putExtra(Constants.KEY_SHARE_CONTENT, content)
33 | .putExtra(Constants.KEY_SHARE_LISTENER, this));
34 | }
35 | }
36 |
37 | @Override protected void onReceiveResult(int resultCode, Bundle resultData) {
38 | if (resultCode == Share.RESULT_SUCCESS) {
39 | if (callback != null) {
40 | callback.onSuccess();
41 | }
42 | } else if (resultCode == Share.RESULT_CANCELD) {
43 | if (callback != null) {
44 | callback.onCanceled();
45 | }
46 | } else {
47 | if (callback != null) {
48 | callback.onFailed();
49 | }
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/allshare/src/main/java/cn/itguy/allshare/platform/wx/WXShare.java:
--------------------------------------------------------------------------------
1 | package cn.itguy.allshare.platform.wx;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.ResultReceiver;
7 | import cn.itguy.allshare.Callback;
8 | import cn.itguy.allshare.Constants;
9 | import cn.itguy.allshare.Content;
10 | import cn.itguy.allshare.Share;
11 | import java.lang.ref.WeakReference;
12 |
13 | /**
14 | * Created by yelongfei490 on 2016/11/25.
15 | */
16 |
17 | public class WXShare extends ResultReceiver implements Share {
18 |
19 | private WeakReference contextWeakRef;
20 | private Callback callback;
21 |
22 | public WXShare(Context context) {
23 | super(null);
24 | contextWeakRef = new WeakReference<>(context);
25 | }
26 |
27 | @Override public void share(Content content, Callback callback) {
28 | this.callback = callback;
29 | Context context = contextWeakRef.get();
30 | if (context != null) {
31 | context.startActivity(new Intent(context, WXEntryActivity.class)
32 | .putExtra(Constants.KEY_SHARE_CONTENT, content)
33 | .putExtra(Constants.KEY_SHARE_LISTENER, this));
34 | }
35 | }
36 |
37 | @Override protected void onReceiveResult(int resultCode, Bundle resultData) {
38 | if (resultCode == Share.RESULT_SUCCESS) {
39 | if (callback != null) {
40 | callback.onSuccess();
41 | }
42 | } else if (resultCode == Share.RESULT_CANCELD) {
43 | if (callback != null) {
44 | callback.onCanceled();
45 | }
46 | } else {
47 | if (callback != null) {
48 | callback.onFailed();
49 | }
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/allshare/src/main/java/cn/itguy/allshare/AllShare.java:
--------------------------------------------------------------------------------
1 | package cn.itguy.allshare;
2 |
3 | import android.content.Context;
4 | import android.content.res.Resources;
5 | import android.util.Log;
6 | import cn.itguy.allshare.platform.qq.QQContent;
7 | import cn.itguy.allshare.platform.qq.QQShare;
8 | import cn.itguy.allshare.platform.wx.WXContent;
9 | import cn.itguy.allshare.platform.wx.WXShare;
10 |
11 | /**
12 | * 分享sdk入口
13 | *
14 | * Created by yelongfei490 on 2016/11/25.
15 | */
16 | public class AllShare {
17 |
18 | private static String wxId;
19 | private static String qqId;
20 | private static String weiboId;
21 |
22 | public static void init(Context context) {
23 | Resources res = context.getResources();
24 | String packageName = context.getPackageName();
25 | wxId = context.getString(res.getIdentifier("all_share_wx_app_id", "string", packageName));
26 | qqId = context.getString(res.getIdentifier("all_share_qq_app_id", "string", packageName)).replace("tencent", "");
27 | weiboId = context.getString(res.getIdentifier("all_share_wb_app_id", "string", packageName));
28 |
29 | Log.i("AllShare", "Got wxId: " + wxId + " qqId: " + qqId + " weiboId: " + weiboId);
30 | }
31 |
32 | public static String getWxId() {
33 | return wxId;
34 | }
35 |
36 | public static String getQqId() {
37 | return qqId;
38 | }
39 |
40 | public static String getWeiboId() {
41 | return weiboId;
42 | }
43 |
44 | public static void share(Context context, Content content, Callback callback) {
45 | Share share = getShare(context, content);
46 | if (share != null) {
47 | share.share(content, callback);
48 | }
49 | }
50 |
51 | private static Share getShare(Context context, Content content) {
52 | if (content != null) {
53 | if (content instanceof QQContent) {
54 | return new QQShare(context);
55 | } else if (content instanceof WXContent) {
56 | return new WXShare(context);
57 | }
58 | }
59 | return null;
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/allshare/src/main/java/cn/itguy/allshare/platform/qq/QQContent.java:
--------------------------------------------------------------------------------
1 | package cn.itguy.allshare.platform.qq;
2 |
3 | import android.os.Parcel;
4 | import cn.itguy.allshare.Content;
5 |
6 | /**
7 | * Created by yelongfei490 on 2016/11/25.
8 | */
9 |
10 | public class QQContent extends Content {
11 |
12 | private boolean qzone;
13 | private String title;
14 | private String targetUrl;
15 | private String summary;
16 | private String imageUrl;
17 |
18 | public boolean isQzone() {
19 | return qzone;
20 | }
21 |
22 | public void setQzone(boolean qzone) {
23 | this.qzone = qzone;
24 | }
25 |
26 | public String getTitle() {
27 | return title;
28 | }
29 |
30 | public void setTitle(String title) {
31 | this.title = title;
32 | }
33 |
34 | public String getTargetUrl() {
35 | return targetUrl;
36 | }
37 |
38 | public void setTargetUrl(String targetUrl) {
39 | this.targetUrl = targetUrl;
40 | }
41 |
42 | public String getSummary() {
43 | return summary;
44 | }
45 |
46 | public void setSummary(String summary) {
47 | this.summary = summary;
48 | }
49 |
50 | public String getImageUrl() {
51 | return imageUrl;
52 | }
53 |
54 | public void setImageUrl(String imageUrl) {
55 | this.imageUrl = imageUrl;
56 | }
57 |
58 | @Override public int describeContents() {
59 | return 0;
60 | }
61 |
62 | @Override public void writeToParcel(Parcel dest, int flags) {
63 | super.writeToParcel(dest, flags);
64 | dest.writeByte(this.qzone ? (byte) 1 : (byte) 0);
65 | dest.writeString(this.title);
66 | dest.writeString(this.targetUrl);
67 | dest.writeString(this.summary);
68 | dest.writeString(this.imageUrl);
69 | }
70 |
71 | public QQContent() {
72 | }
73 |
74 | protected QQContent(Parcel in) {
75 | super(in);
76 | this.qzone = in.readByte() != 0;
77 | this.title = in.readString();
78 | this.targetUrl = in.readString();
79 | this.summary = in.readString();
80 | this.imageUrl = in.readString();
81 | }
82 |
83 | public static final Creator CREATOR = new Creator() {
84 | @Override public QQContent createFromParcel(Parcel source) {
85 | return new QQContent(source);
86 | }
87 |
88 | @Override public QQContent[] newArray(int size) {
89 | return new QQContent[size];
90 | }
91 | };
92 | }
93 |
--------------------------------------------------------------------------------
/allshare/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
14 |
15 |
20 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
39 |
40 |
46 |
47 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/allshare/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'com.jfrog.bintray'
4 |
5 | def _versionName = '1.0.5'
6 |
7 | android {
8 | compileSdkVersion 25
9 | buildToolsVersion "25.0.2"
10 |
11 | defaultConfig {
12 | minSdkVersion 14
13 | targetSdkVersion 25
14 | versionCode 1
15 | versionName _versionName
16 |
17 | consumerProguardFiles 'proguard-rules.pro'
18 |
19 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
20 |
21 | }
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 | }
29 |
30 | dependencies {
31 | compile fileTree(dir: 'libs', include: ['*.jar'])
32 | }
33 |
34 | group = "cn.itguy.allshare"
35 | version = _versionName
36 |
37 | def siteUrl = 'https://github.com/szitguy/Allshare'
38 | def gitUrl = 'https://github.com/szitguy/Allshare'
39 |
40 |
41 | install {
42 | repositories.mavenInstaller {
43 | // This generates POM.xml with proper parameters
44 | pom {
45 | project {
46 | packaging 'aar'
47 |
48 | name 'An android library aims to integrate all share platforms for more convenient using.'
49 | url siteUrl
50 |
51 | licenses {
52 | license {
53 | name 'The MIT License (MIT)'
54 | url 'http://opensource.org/licenses/MIT'
55 | }
56 | }
57 | developers {
58 | developer {
59 | id 'szitguy'
60 | name 'Martin'
61 | email 'luohuafengyue@163.com'
62 | }
63 | }
64 | scm {
65 | connection gitUrl
66 | developerConnection gitUrl
67 | url siteUrl
68 |
69 | }
70 | }
71 | }
72 | }
73 | }
74 |
75 | task sourcesJar(type: Jar) {
76 | from android.sourceSets.main.java.srcDirs
77 | classifier = 'sources'
78 | }
79 |
80 | task javadoc(type: Javadoc) {
81 | source = android.sourceSets.main.java.srcDirs
82 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
83 | }
84 |
85 | task javadocJar(type: Jar, dependsOn: javadoc) {
86 | classifier = 'javadoc'
87 | from javadoc.destinationDir
88 | }
89 | artifacts {
90 | archives javadocJar
91 | archives sourcesJar
92 | }
93 |
94 | bintray {
95 | user = BINTRAY_USER
96 | // if (project.hasProperty("KEY")) {
97 | // key = KEY
98 | // }
99 | key = BINTRAY_API_KEY
100 |
101 | configurations = ['archives']
102 | pkg {
103 | repo = "maven"
104 | name = "allshare"
105 | websiteUrl = siteUrl
106 | vcsUrl = gitUrl
107 | licenses = ["MIT"]
108 | publish = true
109 | }
110 | }
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
20 |
21 |
27 |
28 |
33 |
39 |
40 |
46 |
47 |
53 |
54 |
55 |
56 |
57 |
62 |
63 |
69 |
70 |
75 |
76 |
82 |
83 |
89 |
90 |
91 |
96 |
97 |
--------------------------------------------------------------------------------
/allshare/src/main/java/cn/itguy/allshare/platform/wx/WXContent.java:
--------------------------------------------------------------------------------
1 | package cn.itguy.allshare.platform.wx;
2 |
3 | import android.graphics.Bitmap;
4 | import android.os.Parcel;
5 | import cn.itguy.allshare.Content;
6 |
7 | /**
8 | * Created by yelongfei490 on 2016/11/25.
9 | */
10 |
11 | public class WXContent extends Content {
12 |
13 | private String title;
14 | private Bitmap thumb;
15 | private String description;
16 | private String text;
17 | private Bitmap image;
18 | private String link;
19 | private boolean timeline;
20 |
21 | public String getTitle() {
22 | return title;
23 | }
24 |
25 | public void setTitle(String title) {
26 | this.title = title;
27 | }
28 |
29 | public Bitmap getThumb() {
30 | return thumb;
31 | }
32 |
33 | public void setThumb(Bitmap thumb) {
34 | this.thumb = thumb;
35 | }
36 |
37 | public String getDescription() {
38 | return description;
39 | }
40 |
41 | public void setDescription(String description) {
42 | this.description = description;
43 | }
44 |
45 | public String getText() {
46 | return text;
47 | }
48 |
49 | public void setText(String text) {
50 | this.text = text;
51 | }
52 |
53 | public Bitmap getImage() {
54 | return image;
55 | }
56 |
57 | public void setImage(Bitmap image) {
58 | this.image = image;
59 | }
60 |
61 | public String getLink() {
62 | return link;
63 | }
64 |
65 | public void setLink(String link) {
66 | this.link = link;
67 | }
68 |
69 | public boolean isTimeline() {
70 | return timeline;
71 | }
72 |
73 | public void setTimeline(boolean timeline) {
74 | this.timeline = timeline;
75 | }
76 |
77 | @Override public int describeContents() {
78 | return 0;
79 | }
80 |
81 | @Override public void writeToParcel(Parcel dest, int flags) {
82 | super.writeToParcel(dest, flags);
83 | dest.writeString(this.title);
84 | dest.writeParcelable(this.thumb, flags);
85 | dest.writeString(this.description);
86 | dest.writeString(this.text);
87 | dest.writeParcelable(this.image, flags);
88 | dest.writeString(this.link);
89 | dest.writeByte(this.timeline ? (byte) 1 : (byte) 0);
90 | }
91 |
92 | public WXContent() {
93 | }
94 |
95 | protected WXContent(Parcel in) {
96 | super(in);
97 | this.title = in.readString();
98 | this.thumb = in.readParcelable(Bitmap.class.getClassLoader());
99 | this.description = in.readString();
100 | this.text = in.readString();
101 | this.image = in.readParcelable(Bitmap.class.getClassLoader());
102 | this.link = in.readString();
103 | this.timeline = in.readByte() != 0;
104 | }
105 |
106 | public static final Creator CREATOR = new Creator() {
107 | @Override public WXContent createFromParcel(Parcel source) {
108 | return new WXContent(source);
109 | }
110 |
111 | @Override public WXContent[] newArray(int size) {
112 | return new WXContent[size];
113 | }
114 | };
115 | }
116 |
--------------------------------------------------------------------------------
/allshare/src/main/java/cn/itguy/allshare/LogUtils.java:
--------------------------------------------------------------------------------
1 | package cn.itguy.allshare;
2 |
3 | import android.util.Log;
4 |
5 | /**
6 | * 日志工具类
7 | *
8 | * Created by yelongfei490 on 16/8/31.
9 | */
10 | public class LogUtils {
11 |
12 | private static String tag = "AllShare";
13 |
14 | private static boolean debug = true;
15 |
16 | public static void e(String msg, Object... values) {
17 | if (debug) {
18 | if (values != null && values.length > 0) {
19 | Log.e(tag, String.format(msg, values));
20 | } else {
21 | Log.e(tag, String.valueOf(msg));
22 | }
23 | }
24 | }
25 |
26 | public static void e(boolean forceLog, String msg, Object... values) {
27 | if (forceLog) {
28 | if (values != null && values.length > 0) {
29 | Log.e(tag, String.format(msg, values));
30 | } else {
31 | Log.e(tag, String.valueOf(msg));
32 | }
33 | }
34 | }
35 |
36 | public static void v(String msg, Object... values) {
37 | if (debug) {
38 | if (values != null && values.length > 0) {
39 | Log.v(tag, String.format(msg, values));
40 | } else {
41 | Log.v(tag, String.valueOf(msg));
42 | }
43 | }
44 | }
45 |
46 | public static void v(boolean forceLog, String msg, Object... values) {
47 | if (forceLog) {
48 | if (values != null && values.length > 0) {
49 | Log.v(tag, String.format(msg, values));
50 | } else {
51 | Log.v(tag, String.valueOf(msg));
52 | }
53 | }
54 | }
55 |
56 | public static void i(String msg, Object... values) {
57 | if (debug) {
58 | if (values != null && values.length > 0) {
59 | Log.i(tag, String.format(msg, values));
60 | } else {
61 | Log.i(tag, String.valueOf(msg));
62 | }
63 | }
64 | }
65 |
66 | public static void i(boolean forceLog, String msg, Object... values) {
67 | if (forceLog) {
68 | if (values != null && values.length > 0) {
69 | Log.i(tag, String.format(msg, values));
70 | } else {
71 | Log.i(tag, String.valueOf(msg));
72 | }
73 | }
74 | }
75 |
76 | public static void w(String msg, Object... values) {
77 | if (debug) {
78 | if (values != null && values.length > 0) {
79 | Log.w(tag, String.format(msg, values));
80 | } else {
81 | Log.w(tag, String.valueOf(msg));
82 | }
83 | }
84 | }
85 |
86 | public static void w(boolean forceLog, String msg, Object... values) {
87 | if (forceLog) {
88 | if (values != null && values.length > 0) {
89 | Log.w(tag, String.format(msg, values));
90 | } else {
91 | Log.w(tag, String.valueOf(msg));
92 | }
93 | }
94 | }
95 |
96 | public static void d(String msg, Object... values) {
97 | if (debug) {
98 | if (values != null && values.length > 0) {
99 | Log.d(tag, String.format(msg, values));
100 | } else {
101 | Log.d(tag, String.valueOf(msg));
102 | }
103 | }
104 | }
105 |
106 | public static void d(boolean forceLog, String msg, Object... values) {
107 | if (forceLog) {
108 | if (values != null && values.length > 0) {
109 | Log.d(tag, String.format(msg, values));
110 | } else {
111 | Log.d(tag, String.valueOf(msg));
112 | }
113 | }
114 | }
115 |
116 | public static void setTag(String tag) {
117 | LogUtils.tag = tag;
118 | }
119 |
120 | public static void setDebug(boolean debug) {
121 | LogUtils.debug = debug;
122 | }
123 |
124 | }
125 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | AllShare
2 | =======
3 |
4 | 封装常用分享平台的sdk,统一并简化各分享sdk使用,提升分享功能的开发速度
5 |
6 | 特点:
7 |
8 | 1. 简化各平台sdk集成,只需要引入一个gradle插件,然后配置相应平台的appid即可开始使用
9 | 2. 使用简单,类命名统一,见名知意
10 | 3. 各平台分享结果由统一的接口进行回调,结果简化为成功、失败、取消
11 |
12 | 说明:目前只支持了`微信`和`QQ`两个平台的分享
13 |
14 | 集成
15 | -----
16 |
17 | ### 1. 添加AllShare Gradle插件(插件中已处理AllShare库的依赖添加)
18 |
19 | ```
20 | repositories {
21 | jcenter()
22 | }
23 |
24 | dependencies {
25 | classpath 'com.android.tools.build:gradle:2.3.0'
26 | classpath 'cn.itguy:allshare-gradle-plugin:latest.release' // latest release is 1.0.7
27 | }
28 | ```
29 |
30 | ### 2. 配置各分享平台appId
31 |
32 | 以应用包名和appId对应的形式进行配置,可配多个,如:
33 |
34 | ```
35 | // AllShare配置
36 | AllSharePlugin {
37 | // qqAppId配置
38 | qqAppIdMap = [
39 | "应用包名1": "qqAppId1",
40 | "应用包名2": "qqAppId2",
41 | ]
42 | // wxAppId配置
43 | wxAppIdMap = [
44 | "应用包名1": "wxAppId1",
45 | "应用包名2": "wxAppId2",
46 | ]
47 | }
48 | ```
49 |
50 | 使用
51 | -----
52 |
53 | > 代码片段取自sample
54 |
55 | ### 1. 初始化
56 |
57 | 建议在应用的Application子类中初始化,如:
58 |
59 | ```
60 | AllShare.init(applicationContext);
61 | ```
62 |
63 | ### 2. 统一的结果回调
64 |
65 | 实现`cn.itguy.allshare.Callback`接口,如:
66 |
67 | ```
68 | private static class ShareCallback implements Callback {
69 |
70 | WeakReference contextWeakRef;
71 |
72 | public ShareCallback(Context context) {
73 | contextWeakRef = new WeakReference<>(context);
74 | }
75 |
76 | @Override public void onSuccess() {
77 | Context context = contextWeakRef.get();
78 | if (null != context) {
79 |
80 | Toast.makeText(context, "分享成功", Toast.LENGTH_SHORT).show();
81 | }
82 | }
83 |
84 | @Override public void onFailed() {
85 | Context context = contextWeakRef.get();
86 | if (null != context) {
87 |
88 | Toast.makeText(context, "分享失败", Toast.LENGTH_SHORT).show();
89 | }
90 | }
91 |
92 | @Override public void onCanceled() {
93 | Context context = contextWeakRef.get();
94 | if (null != context) {
95 |
96 | Toast.makeText(context, "取消分享", Toast.LENGTH_SHORT).show();
97 | }
98 | }
99 | }
100 | ```
101 |
102 | ### 3. 微信分享
103 |
104 | #### 分享文本
105 |
106 | ```
107 | WXContent content = new WXContent();
108 | content.setType(Content.Type.TEXT);
109 | content.setTimeline(momentCheckBox.isChecked()); // 是否分享到朋友圈
110 | content.setText(String.format("%s --- %s", ALL_SHARE_GITHUB, TITLE)); // 设置文本内容
111 | content.setDescription(DESC); // 设置描述
112 | AllShare.share(activityContext, content, new ShareCallback(this));
113 | ```
114 |
115 | #### 分享链接
116 |
117 | ```
118 | WXContent content = new WXContent();
119 | content.setType(Content.Type.LINK);
120 | content.setTimeline(momentCheckBox.isChecked()); // 是否分享到朋友圈
121 | content.setTitle(TITLE); // 设置标题
122 | content.setDescription(DESC); // 设置描述
123 | content.setLink(ALL_SHARE_GITHUB); // 设置链接
124 | content.setThumb(icon); // 设置缩略图
125 | AllShare.share(activityContext, content, new ShareCallback(this));
126 | ```
127 |
128 | #### 分享图片
129 |
130 | ```
131 | WXContent content = new WXContent();
132 | content.setType(Content.Type.IMAGE);
133 | content.setTimeline(momentCheckBox.isChecked()); // 是否分享到朋友圈
134 | content.setImage(icon); // 设置图片
135 | content.setThumb(icon); // 设置缩略图
136 | AllShare.share(activityContext, content, new ShareCallback(this));
137 | ```
138 |
139 | ### 4. QQ分享
140 |
141 | #### 分享链接
142 |
143 | ```
144 | QQContent content = new QQContent();
145 | content.setType(Content.Type.LINK);
146 | content.setImageUrl(ICON_FILE.getAbsolutePath()); // 本地or网络图片,可选
147 | content.setQzone(qzoneCheckBox.isChecked()); // 是否分享到qq空间
148 | content.setTitle(TITLE); // 设置标题
149 | content.setTargetUrl(ALL_SHARE_GITHUB); // 设置链接
150 | content.setSummary(DESC); // 设置描述,可选
151 | AllShare.share(activityContext, content, new ShareCallback(this));
152 | ```
153 |
154 | #### 分享图片
155 |
156 | ```
157 | if (qzoneCheckBox.isChecked()) {
158 | Toast.makeText(this, "Qzone不支持图片分享", Toast.LENGTH_SHORT).show();
159 | return;
160 | }
161 | QQContent content = new QQContent();
162 | content.setType(Content.Type.IMAGE);
163 | content.setImageUrl(ICON_FILE.getAbsolutePath()); // 必须为本地图片
164 | AllShare.share(activityContext, content, new ShareCallback(this));
165 | ```
166 |
167 | License
168 | -----
169 | MIT License
170 |
171 | Copyright (c) 2017 Martin
172 |
173 | Permission is hereby granted, free of charge, to any person obtaining a copy
174 | of this software and associated documentation files (the "Software"), to deal
175 | in the Software without restriction, including without limitation the rights
176 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
177 | copies of the Software, and to permit persons to whom the Software is
178 | furnished to do so, subject to the following conditions:
179 |
180 | The above copyright notice and this permission notice shall be included in all
181 | copies or substantial portions of the Software.
182 |
183 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
184 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
185 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
186 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
187 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
188 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
189 | SOFTWARE.
190 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/sample/src/main/java/cn/itguy/allshare/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package cn.itguy.allshare.sample;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.os.Bundle;
7 | import android.os.Environment;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.view.View;
10 | import android.widget.CheckBox;
11 | import android.widget.Toast;
12 | import cn.itguy.allshare.AllShare;
13 | import cn.itguy.allshare.Callback;
14 | import cn.itguy.allshare.Content;
15 | import cn.itguy.allshare.platform.qq.QQContent;
16 | import cn.itguy.allshare.platform.wx.WXContent;
17 | import java.io.File;
18 | import java.io.FileOutputStream;
19 | import java.io.IOException;
20 | import java.lang.ref.WeakReference;
21 |
22 | public class MainActivity extends AppCompatActivity {
23 |
24 | public static final String ALL_SHARE_GITHUB = "https://github.com/szitguy/Allshare";
25 |
26 | private static final String SHARE_ICON_NAME = "share.png";
27 | private static final File ICON_FILE = new File(SampleApplication.instance.getExternalFilesDir(
28 | Environment.DIRECTORY_PICTURES), SHARE_ICON_NAME);
29 | private static final String TITLE = "AllShare";
30 | private static final String DESC = "封装常用分享平台的sdk,统一并简化各分享sdk使用,提升分享功能的开发速度";
31 |
32 | CheckBox momentCheckBox;
33 | CheckBox qzoneCheckBox;
34 |
35 | private Bitmap icon;
36 |
37 | @Override protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 | setContentView(R.layout.activity_main);
40 | momentCheckBox = (CheckBox) findViewById(R.id.shareToMomentCheckBox);
41 | qzoneCheckBox = (CheckBox) findViewById(R.id.shareToQzoneCheckBox);
42 |
43 | icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
44 | if (!ICON_FILE.exists()) {
45 | try {
46 | FileOutputStream fileOutputStream = new FileOutputStream(ICON_FILE);
47 | icon.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream);
48 | fileOutputStream.close();
49 | } catch (IOException e) {
50 | e.printStackTrace();
51 | }
52 | }
53 | }
54 |
55 | /**
56 | * 微信分享文本
57 | * @param view
58 | */
59 | public void onWxShareTextButtonClick(View view) {
60 | WXContent content = new WXContent();
61 | content.setType(Content.Type.TEXT);
62 | content.setTimeline(momentCheckBox.isChecked());
63 | content.setText(String.format("%s --- %s", ALL_SHARE_GITHUB, TITLE));
64 | content.setDescription(DESC);
65 | AllShare.share(this, content, new ShareCallback(this));
66 | }
67 |
68 | /**
69 | * 微信分享链接
70 | * @param view
71 | */
72 | public void onWxShareLinkButtonClick(View view) {
73 | WXContent content = new WXContent();
74 | content.setType(Content.Type.LINK);
75 | content.setTimeline(momentCheckBox.isChecked());
76 | content.setTitle(TITLE);
77 | content.setDescription(DESC);
78 | content.setLink(ALL_SHARE_GITHUB);
79 | content.setThumb(icon);
80 | AllShare.share(this, content, new ShareCallback(this));
81 | }
82 |
83 | /**
84 | * 微信分享图片
85 | * @param view
86 | */
87 | public void onWxShareImageButtonClick(View view) {
88 | WXContent content = new WXContent();
89 | content.setType(Content.Type.IMAGE);
90 | content.setTimeline(momentCheckBox.isChecked());
91 | content.setImage(icon);
92 | content.setThumb(icon);
93 | AllShare.share(this, content, new ShareCallback(this));
94 | }
95 |
96 | /**
97 | * QQ分享链接
98 | * @param view
99 | */
100 | public void onQQShareLinkButtonClick(View view) {
101 | QQContent content = new QQContent();
102 | content.setType(Content.Type.LINK);
103 | content.setImageUrl(ICON_FILE.getAbsolutePath()); // 本地or网络图片,可选
104 | content.setQzone(qzoneCheckBox.isChecked());
105 | content.setTitle(TITLE);
106 | content.setTargetUrl(ALL_SHARE_GITHUB);
107 | content.setSummary(DESC); // 可选
108 | AllShare.share(this, content, new ShareCallback(this));
109 | }
110 |
111 | /**
112 | * QQ分享图片
113 | * @param view
114 | */
115 | public void onQQShareImageButtonClick(View view) {
116 | if (qzoneCheckBox.isChecked()) {
117 | Toast.makeText(this, "Qzone不支持图片分享", Toast.LENGTH_SHORT).show();
118 | return;
119 | }
120 | QQContent content = new QQContent();
121 | content.setType(Content.Type.IMAGE);
122 | content.setImageUrl(ICON_FILE.getAbsolutePath()); // 必须为本地图片
123 | AllShare.share(this, content, new ShareCallback(this));
124 | }
125 |
126 | private static class ShareCallback implements Callback {
127 |
128 | WeakReference contextWeakRef;
129 |
130 | public ShareCallback(Context context) {
131 | contextWeakRef = new WeakReference<>(context);
132 | }
133 |
134 | @Override public void onSuccess() {
135 | Context context = contextWeakRef.get();
136 | if (null != context) {
137 |
138 | Toast.makeText(context, "分享成功", Toast.LENGTH_SHORT).show();
139 | }
140 | }
141 |
142 | @Override public void onFailed() {
143 | Context context = contextWeakRef.get();
144 | if (null != context) {
145 |
146 | Toast.makeText(context, "分享失败", Toast.LENGTH_SHORT).show();
147 | }
148 | }
149 |
150 | @Override public void onCanceled() {
151 | Context context = contextWeakRef.get();
152 | if (null != context) {
153 |
154 | Toast.makeText(context, "取消分享", Toast.LENGTH_SHORT).show();
155 | }
156 | }
157 | }
158 |
159 | }
160 |
--------------------------------------------------------------------------------
/allshare/src/main/java/cn/itguy/allshare/platform/qq/QQEnrtyActivity.java:
--------------------------------------------------------------------------------
1 | package cn.itguy.allshare.platform.qq;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.ResultReceiver;
7 | import android.widget.Toast;
8 | import cn.itguy.allshare.AllShare;
9 | import cn.itguy.allshare.Constants;
10 | import cn.itguy.allshare.Content;
11 | import cn.itguy.allshare.LogUtils;
12 | import cn.itguy.allshare.R;
13 | import cn.itguy.allshare.Share;
14 | import com.tencent.connect.share.QQShare;
15 | import com.tencent.connect.share.QzoneShare;
16 | import com.tencent.tauth.IUiListener;
17 | import com.tencent.tauth.Tencent;
18 | import com.tencent.tauth.UiError;
19 | import java.util.ArrayList;
20 |
21 | /**
22 | * Created by yelongfei490 on 16/5/23.
23 | */
24 | public class QQEnrtyActivity extends Activity {
25 |
26 | public static final String TAG = "QQEnrtyActivity";
27 |
28 | private QQContent shareContent;
29 | private ResultReceiver listener;
30 | private Tencent api;
31 |
32 | @Override
33 | protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | Bundle bundle;
36 | boolean paramError = false;
37 | Intent intent = getIntent();
38 | if (null == intent || null == (bundle = intent.getExtras())) {
39 | LogUtils.e("%s: params is null, finish.", TAG);
40 | paramError = true;
41 | } else {
42 | bundle.setClassLoader(QQContent.class.getClassLoader());
43 | if (null == (shareContent = bundle.getParcelable(Constants.KEY_SHARE_CONTENT))) {
44 | LogUtils.e("%s: share content is null, finish.", TAG);
45 | paramError = true;
46 | } else if (null == (listener = bundle.getParcelable(Constants.KEY_SHARE_LISTENER))) {
47 | LogUtils.e("%s: result receiver is null.", TAG);
48 | } else if (null == (api = Tencent.createInstance(AllShare.getQqId(), this))) {
49 | LogUtils.e("%s: api is null, finish.", TAG);
50 | paramError = true;
51 | }
52 | }
53 | if (paramError) {
54 | Toast.makeText(this, R.string.share_failed, Toast.LENGTH_SHORT).show();
55 | finish();
56 | return;
57 | }
58 |
59 | if (shareContent.isQzone())
60 | doShareToQQZone();
61 | else
62 | doShareToQQ();
63 | }
64 |
65 | private void doShareToQQ() {
66 | int type = shareContent.getType();
67 | if (Content.Type.TEXT == type) {
68 | LogUtils.e("%s: Unsupported content, finish.", TAG);
69 | Toast.makeText(this, R.string.share_failed, Toast.LENGTH_SHORT).show();
70 | finish();
71 | return;
72 | }
73 |
74 | Bundle params = new Bundle();
75 | switch (type) {
76 | case Content.Type.LINK:
77 | params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
78 | params.putString(QQShare.SHARE_TO_QQ_TITLE, shareContent.getTitle());
79 | params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, shareContent.getTargetUrl());
80 | params.putString(QQShare.SHARE_TO_QQ_SUMMARY, shareContent.getSummary());
81 | params.putString(QQShare.SHARE_TO_QQ_IMAGE_URL, shareContent.getImageUrl());
82 | break;
83 | case Content.Type.IMAGE:
84 | params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_IMAGE);
85 | params.putString(QQShare.SHARE_TO_QQ_IMAGE_LOCAL_URL, shareContent.getImageUrl());
86 | break;
87 | }
88 | api.shareToQQ(QQEnrtyActivity.this, params, qqShareListener);
89 | }
90 |
91 | private void doShareToQQZone() {
92 | if (Content.Type.LINK != shareContent.getType()) {
93 | LogUtils.e("%s: Unsupported content, finish.", TAG);
94 | Toast.makeText(this, R.string.share_failed, Toast.LENGTH_SHORT).show();
95 | finish();
96 | return;
97 | }
98 |
99 | Bundle params = new Bundle();
100 | params.putString(QzoneShare.SHARE_TO_QQ_TITLE, shareContent.getTitle());
101 | params.putString(QzoneShare.SHARE_TO_QQ_SUMMARY, shareContent.getSummary());
102 | ArrayList imageUrls = new ArrayList<>();
103 | imageUrls.add(shareContent.getImageUrl());
104 | params.putStringArrayList(QzoneShare.SHARE_TO_QQ_IMAGE_URL, imageUrls);
105 | params.putString(QzoneShare.SHARE_TO_QQ_TARGET_URL, shareContent.getTargetUrl());
106 |
107 | api.shareToQzone(QQEnrtyActivity.this, params, qqShareListener);
108 | }
109 |
110 | IUiListener qqShareListener = new IUiListener() {
111 |
112 | @Override
113 | public void onCancel() {
114 | LogUtils.e("%s: Share canceled.", TAG);
115 | if (listener != null) {
116 | listener.send(Share.RESULT_CANCELD, null);
117 | }
118 | finish();
119 | }
120 |
121 | @Override
122 | public void onComplete(Object response) {
123 | LogUtils.e("%s: Share completed.", TAG);
124 | if (listener != null) {
125 | listener.send(Share.RESULT_SUCCESS, null);
126 | }
127 | finish();
128 | }
129 |
130 | @Override
131 | public void onError(UiError e) {
132 | LogUtils.e("%s: Share error: code=%s, msg=%s, detail=%s.", TAG, e.errorCode, e.errorMessage, e.errorDetail);
133 | if (listener != null) {
134 | listener.send(Share.RESULT_FAILED, null);
135 | }
136 | finish();
137 | }
138 | };
139 |
140 | @Override
141 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
142 | Tencent.onActivityResultData(requestCode, resultCode, data, qqShareListener);
143 | }
144 |
145 | @Override
146 | protected void onDestroy() {
147 | super.onDestroy();
148 | if (api != null) {
149 | api.releaseResource();
150 | }
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/allshare/src/main/java/cn/itguy/allshare/platform/wx/WXEntryActivity.java:
--------------------------------------------------------------------------------
1 | package cn.itguy.allshare.platform.wx;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.ResultReceiver;
7 | import android.widget.Toast;
8 | import cn.itguy.allshare.AllShare;
9 | import cn.itguy.allshare.Content;
10 | import cn.itguy.allshare.LogUtils;
11 | import cn.itguy.allshare.R;
12 | import cn.itguy.allshare.Share;
13 | import com.tencent.mm.sdk.openapi.BaseReq;
14 | import com.tencent.mm.sdk.openapi.BaseResp;
15 | import com.tencent.mm.sdk.openapi.IWXAPI;
16 | import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
17 | import com.tencent.mm.sdk.openapi.SendMessageToWX;
18 | import com.tencent.mm.sdk.openapi.WXAPIFactory;
19 | import com.tencent.mm.sdk.openapi.WXImageObject;
20 | import com.tencent.mm.sdk.openapi.WXMediaMessage;
21 | import com.tencent.mm.sdk.openapi.WXTextObject;
22 | import com.tencent.mm.sdk.openapi.WXWebpageObject;
23 |
24 | import static cn.itguy.allshare.Constants.KEY_SHARE_CONTENT;
25 | import static cn.itguy.allshare.Constants.KEY_SHARE_LISTENER;
26 |
27 | public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
28 |
29 | private static final String TAG = "WXEntryActivity";
30 |
31 | private IWXAPI wxapi;
32 | private WXContent shareContent;
33 | private ResultReceiver listener;
34 |
35 | @Override
36 | public void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | Intent intent = getIntent();
39 | wxapi = WXAPIFactory.createWXAPI(this, AllShare.getWxId(), true);
40 | boolean registered = wxapi.registerApp(AllShare.getWxId());
41 | // 若是接收结果,处理完直接finish
42 | if (wxapi.handleIntent(intent, this)) {
43 | finish();
44 | return;
45 | }
46 |
47 | Bundle bundle;
48 | boolean paramError = false;
49 | if (!registered) {
50 | LogUtils.e("%s: api is null, finish.", TAG);
51 | paramError = true;
52 | } else if (null == intent || null == (bundle = intent.getExtras())) {
53 | LogUtils.e("%s: params is null, finish.", TAG);
54 | paramError = true;
55 | } else {
56 | bundle.setClassLoader(WXContent.class.getClassLoader());
57 | if (null == (shareContent = bundle.getParcelable(KEY_SHARE_CONTENT))) {
58 | LogUtils.e("%s: share content is null, finish.", TAG);
59 | paramError = true;
60 | } else if (null == (listener = bundle.getParcelable(KEY_SHARE_LISTENER))) {
61 | LogUtils.e("%s: result receiver is null.", TAG);
62 | }
63 | }
64 | if (paramError) {
65 | Toast.makeText(this, R.string.share_failed, Toast.LENGTH_SHORT).show();
66 | finish();
67 | return;
68 | }
69 |
70 | share();
71 | }
72 |
73 | private void share() {
74 | SendMessageToWX.Req req = new SendMessageToWX.Req();
75 | WXMediaMessage msg = new WXMediaMessage();
76 | msg.setThumbImage(shareContent.getThumb());
77 | msg.title = shareContent.getTitle();
78 | msg.description = shareContent.getDescription();
79 | switch (shareContent.getType()) {
80 | case Content.Type.TEXT:
81 | msg.mediaObject = new WXTextObject(shareContent.getText());
82 | req.transaction = buildTransaction("text");
83 | break;
84 | case Content.Type.IMAGE:
85 | msg.mediaObject = new WXImageObject(shareContent.getImage());
86 | req.transaction = buildTransaction("img");
87 | break;
88 | case Content.Type.LINK:
89 | msg.mediaObject = new WXWebpageObject(shareContent.getLink());
90 | req.transaction = buildTransaction("webpage");
91 | break;
92 | }
93 | req.message = msg;
94 | req.scene = shareContent.isTimeline() ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession;
95 | wxapi.sendReq(req);
96 | }
97 |
98 | private String buildTransaction(final String type) {
99 | return (type == null) ? String.valueOf(System.currentTimeMillis()) : type + System.currentTimeMillis();
100 | }
101 |
102 | @Override
103 | protected void onNewIntent(Intent intent) {
104 | super.onNewIntent(intent);
105 | setIntent(intent);
106 | wxapi.handleIntent(intent, this);
107 | }
108 |
109 | /**
110 | * Activity resume的次数
111 | */
112 | private int resumeCount;
113 |
114 | @Override protected void onResume() {
115 | super.onResume();
116 | // resume计数
117 | resumeCount++;
118 | // 当第二次resume时,要么是分享成功或分享失败或取消分享,必需finish,onResume在onNewIntent()后调用
119 | // 这个处理可以避免某些情况下(如跳转分享前,有两个微信可供选择的对话框),用户返回本页面导致"卡屏"问题
120 | if (resumeCount > 1) {
121 | finish();
122 | }
123 | }
124 |
125 | @Override
126 | public void onReq(BaseReq req) {
127 | LogUtils.e("%s: onReq: type=%s, transaction=%s.", TAG, req.getType(), req.transaction);
128 | }
129 |
130 | @Override
131 | public void onResp(BaseResp resp) {
132 | LogUtils.e("%s: Share resp: code=%s, msg=%s, transaction=%s.", TAG, resp.errCode, resp.errStr, resp.transaction);
133 | switch (resp.errCode) {
134 | case BaseResp.ErrCode.ERR_OK:
135 | LogUtils.e("%s: Share completed.", TAG);
136 | if (listener != null) {
137 | listener.send(Share.RESULT_SUCCESS, null);
138 | }
139 | break;
140 | case BaseResp.ErrCode.ERR_USER_CANCEL:
141 | LogUtils.e("%s: Share canceled.", TAG);
142 | if (listener != null) {
143 | listener.send(Share.RESULT_CANCELD, null);
144 | }
145 | break;
146 | default:
147 | if (listener != null) {
148 | listener.send(Share.RESULT_FAILED, null);
149 | }
150 | break;
151 | }
152 | finish();
153 | }
154 |
155 | }
--------------------------------------------------------------------------------