Commit 842cbfbfb29e0e6de3c0c75e8233617a7da86766
1 parent
c507bd179d
Exists in
master
增加文档
完善demo
Showing 6 changed files with 181 additions and 11 deletions Inline Diff
README
README.md
File was created | 1 | # Gump SDK 5 for Android接入文档 | |
2 | |||
3 | V5.0.0 | ||
4 | 2018年11月02日 | ||
5 | |||
6 | ## 版本概述 | ||
7 | |||
8 | 此版本为使用AndroidStudio开发的版本,使用aar在线依赖的方式提供sdk接入包,相对上一版本没有任何继承关系,请按此文档描述接入. | ||
9 | |||
10 | 此SDK适用android4.0以上系统. | ||
11 | |||
12 | 本SDK分为两个部分:登录和支付,请按需引用依赖包. | ||
13 | |||
14 | ## 第一章 接入指南 | ||
15 | ### 1.依赖导入 | ||
16 | 配置gradle,以下为必须项 | ||
17 | |||
18 | repositories{ | ||
19 | maven{ | ||
20 | url "http://117.50.8.198:8081/nexus/content/repositories/sdk" | ||
21 | } | ||
22 | } | ||
23 | dependencies { | ||
24 | //基础功能依赖,必须 | ||
25 | implementation 'com.gump:base:5.0.0' | ||
26 | //登录功能依赖 | ||
27 | implementation 'com.gump:Passport:5.0.0' | ||
28 | //支付功能依赖 | ||
29 | implementation 'com.gump:Payment:5.0.0' | ||
30 | } | ||
31 | |||
32 | ### 2.修改AndroidManifest.xml文件 | ||
33 | 首先添加必要的权限,如下所示: | ||
34 | |||
35 | <uses-permission android:name="android.permission.INTERNET" /> | ||
36 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | ||
37 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
38 | <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> | ||
39 | <uses-permission android:name="com.android.vending.BILLING" /> | ||
40 | |||
41 | 创建一个strings 配置如下 | ||
42 | |||
43 | <string name="app_id">your_play_games_app_id</string> | ||
44 | |||
45 | 增加play games的meta-data配置 | ||
46 | |||
47 | <meta-data | ||
48 | android:name="com.google.android.gms.games.APP_ID" | ||
49 | android:value="@string/app_id"/> | ||
50 | <meta-data | ||
51 | android:name="com.google.android.gms.version" | ||
52 | android:value="@integer/google_play_services_version"/> | ||
53 | |||
54 | ### 3.1 初始化与配置 | ||
55 | *横竖屏控制,默认为横屏,参数为false即为竖屏 | ||
56 | |||
57 | SDKAgent.getSettings().setScreenLandscape(true); | ||
58 | |||
59 | *若要使用V4版支付请设置 | ||
60 | |||
61 | SDKAgent.getSettings().setPaymentVersion(PaymentVersion.V4); | ||
62 | |||
63 | *执行初始化 | ||
64 | |||
65 | SDKAgent.init(Context,Appid,ChannelId); | ||
66 | |||
67 | ### 3.2 登录接入 | ||
68 | 构建Passport实例 | ||
69 | |||
70 | passport = new Passport.Builder().context(Context).setListener(StateListener).build(); | ||
71 | |||
72 | 其中StateListener为登录状态监听接口,需要实现如下方法 | ||
73 | |||
74 | //成功回调,成功事件类型由action枚举对象标识,player是成功返回的玩家对象 | ||
75 | void onActionSucced(Actions action, GamePlayer player) | ||
76 | //失败回调 | ||
77 | void onActionFailured() | ||
78 | |||
79 | 接下来,添加生命周期处理方法 | ||
80 | |||
81 | @Override | ||
82 | protected void onResume() { | ||
83 | super.onResume(); | ||
84 | passport.onResume(); | ||
85 | } | ||
86 | |||
87 | 处理结果返回 | ||
88 | |||
89 | @Override | ||
90 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
91 | if (!passport.onActivityResult(requestCode, resultCode, data)) | ||
92 | super.onActivityResult(requestCode, resultCode, data); | ||
93 | } | ||
94 | |||
95 | ### 3.3 支付接入 | ||
96 | 注册相应的Activity,具体如下: | ||
97 | |||
98 | <activity | ||
99 | android:name="com.gumptech.sdk.PaymentActivity" | ||
100 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | ||
101 | android:launchMode="singleTask" | ||
102 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > | ||
103 | <intent-filter> | ||
104 | <category android:name="android.intent.category.DEFAULT" /> | ||
105 | <action android:name="android.intent.action.VIEW" /> | ||
106 | <category android:name="android.intent.category.BROWSABLE" /> | ||
107 | <data | ||
108 | android:host="com.gump.sdk" | ||
109 | android:scheme="gump+游戏的appId" /> | ||
110 | </intent-filter> | ||
111 | </activity> | ||
112 | |||
113 | 三方支付调用 | ||
114 | |||
115 | Bundle payInfo = new Bundle(); | ||
116 | payInfo.putString("product", "wa2"); | ||
117 | payInfo.putFloat("amount", 0.1f); | ||
118 | payInfo.putString("extraInfo", "This is demo!"); | ||
119 | payInfo.putString("serverId", "100"); | ||
120 | payInfo.putString("roleId", "41080"); | ||
121 | Payment.pay(Activity, payInfo, PurchaseCallback); | ||
122 | |||
123 | Google IAB支付调用 | ||
124 | |||
125 | Bundle payInfo = new Bundle(); | ||
126 | payInfo.putString("product", "180010"); | ||
127 | payInfo.putFloat("amount", 0.1f); | ||
128 | payInfo.putString("extraInfo", "This is demo!"); | ||
129 | payInfo.putString("serverId", "100"); | ||
130 | payInfo.putString("roleId", "41080"); | ||
131 | Payment.launchIAP(Activity, payInfo, PurchaseCallback); | ||
132 | |||
133 | PurchaseCallback为支付状态回调接口,此接口含有3个方法 | ||
134 | |||
135 | @Override | ||
136 | public void onPurchaseCompleted(PurchaseResult result) { | ||
137 | Log.i(TAG,"purchase completed"); | ||
138 | } | ||
139 | |||
140 | @Override | ||
141 | public void onPurchaseError(int code, String msg) { | ||
142 | Log.i(TAG,"purchase error"); | ||
143 | } | ||
144 | |||
145 | @Override | ||
146 | public void onPurchaseCanceled() { | ||
147 | Log.i(TAG,"purchase canceled"); | ||
148 | } | ||
149 | |||
150 | ## 第二章 常见问题 | ||
151 | ### 问题1: 如何避免混淆对SDK的影响? | ||
152 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java | ||
153 | 类,导致SDK无法正常工作,解决方法如下: | ||
154 | Ø 请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上 | ||
155 | |||
156 | -keep class com.gump.payment.web.* {*;} | ||
157 | |||
158 | 使得混淆的时候不会影响SDK的命名空间。 |
app/build.gradle
1 | apply plugin: 'com.android.application' | 1 | apply plugin: 'com.android.application' |
2 | 2 | ||
3 | |||
3 | android { | 4 | android { |
4 | compileSdkVersion 27 | 5 | compileSdkVersion 27 |
5 | defaultConfig { | 6 | defaultConfig { |
6 | applicationId "com.gump.passport.demo" | 7 | applicationId "com.gump.passport.demo" |
7 | minSdkVersion 14 | 8 | minSdkVersion 14 |
8 | targetSdkVersion 27 | 9 | targetSdkVersion 27 |
9 | versionCode 2 | 10 | versionCode 2 |
10 | versionName "1.0.1" | 11 | versionName "1.0.1" |
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" |
12 | } | 13 | } |
13 | buildTypes { | 14 | buildTypes { |
14 | release { | 15 | release { |
15 | minifyEnabled false | 16 | minifyEnabled false |
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
17 | } | 18 | } |
18 | } | 19 | } |
19 | 20 | ||
20 | applicationVariants.all{ | 21 | applicationVariants.all { |
21 | variant-> | 22 | variant -> |
22 | variant.outputs.all{ | 23 | variant.outputs.all { |
23 | outputFileName = "SDKDemo-"+variant.name+defaultConfig.versionName+".apk" | 24 | outputFileName = "SDKDemo-" + variant.name + defaultConfig.versionName + ".apk" |
24 | } | 25 | } |
25 | } | 26 | } |
27 | |||
28 | lintOptions { | ||
29 | abortOnError false | ||
30 | } | ||
26 | } | 31 | } |
27 | 32 | ||
28 | dependencies { | 33 | dependencies { |
29 | implementation fileTree(dir: 'libs', include: ['*.jar']) | 34 | implementation fileTree(dir: 'libs', include: ['*.jar']) |
30 | implementation 'com.android.support:appcompat-v7:27.1.1' | ||
31 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' | 35 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' |
32 | testImplementation 'junit:junit:4.12' | 36 | testImplementation 'junit:junit:4.12' |
33 | androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
34 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
35 | 37 | ||
36 | implementation project(':base') | 38 | //基础功能依赖,必须 |
37 | implementation project(':passport') | 39 | implementation 'com.gump:base:5.0.0' |
38 | implementation project(':payment') | 40 | // implementation project(':base') |
41 | //登录功能依赖 | ||
42 | implementation 'com.gump:Passport:5.0.0' | ||
43 | // implementation project(':passport') | ||
44 | //支付功能依赖 | ||
45 | implementation 'com.gump:Payment:5.0.0' |
app/proguard-rules.pro
1 | # Add project specific ProGuard rules here. | 1 | # Add project specific ProGuard rules here. |
2 | # You can control the set of applied configuration files using the | 2 | # You can control the set of applied configuration files using the |
3 | # proguardFiles setting in build.gradle. | 3 | # proguardFiles setting in build.gradle. |
4 | # | 4 | # |
5 | # For more details, see | 5 | # For more details, see |
6 | # http://developer.android.com/guide/developing/tools/proguard.html | 6 | # http://developer.android.com/guide/developing/tools/proguard.html |
7 | 7 | ||
8 | # If your project uses WebView with JS, uncomment the following | 8 | # If your project uses WebView with JS, uncomment the following |
9 | # and specify the fully qualified class name to the JavaScript interface | 9 | # and specify the fully qualified class name to the JavaScript interface |
10 | # class: | 10 | # class: |
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { | 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { |
12 | # public *; | 12 | # public *; |
13 | #} | 13 | #} |
14 | 14 | ||
15 | # Uncomment this to preserve the line number information for | 15 | # Uncomment this to preserve the line number information for |
16 | # debugging stack traces. | 16 | # debugging stack traces. |
17 | #-keepattributes SourceFile,LineNumberTable | 17 | #-keepattributes SourceFile,LineNumberTable |
18 | 18 | ||
19 | # If you keep the line number information, uncomment this to | 19 | # If you keep the line number information, uncomment this to |
20 | # hide the original source file name. | 20 | # hide the original source file name. |
21 | #-renamesourcefileattribute SourceFile | 21 | #-renamesourcefileattribute SourceFile |
22 | -keep class com.gump.payment.web.* {*;} |
build.gradle
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. | 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. |
2 | 2 | ||
3 | buildscript { | 3 | buildscript { |
4 | 4 | ||
5 | repositories { | 5 | repositories { |
6 | google() | 6 | google() |
7 | jcenter() | 7 | jcenter() |
8 | } | 8 | } |
9 | dependencies { | 9 | dependencies { |
10 | classpath 'com.android.tools.build:gradle:3.2.1' | 10 | classpath 'com.android.tools.build:gradle:3.2.1' |
11 | 11 | ||
12 | 12 | ||
13 | // NOTE: Do not place your application dependencies here; they belong | 13 | // NOTE: Do not place your application dependencies here; they belong |
14 | // in the individual module build.gradle files | 14 | // in the individual module build.gradle files |
15 | } | 15 | } |
16 | } | 16 | } |
17 | 17 | ||
18 | allprojects { | 18 | allprojects { |
19 | repositories { | 19 | repositories { |
20 | google() | 20 | google() |
21 | jcenter() | 21 | jcenter() |
22 | maven{ | ||
23 | url "http://117.50.8.198:8081/nexus/content/repositories/sdk" | ||
24 | } | ||
22 | } | 25 | } |
23 | } | 26 | } |
24 | 27 | ||
25 | task clean(type: Delete) { | 28 | task clean(type: Delete) { |
26 | delete rootProject.buildDir | 29 | delete rootProject.buildDir |
27 | } | 30 | } |
28 | 31 |
settings.gradle
1 | include ':app' | 1 | include ':app' |
2 |