Commit 842cbfbfb29e0e6de3c0c75e8233617a7da86766

Authored by 赵康
1 parent c507bd179d
Exists in master

增加文档

完善demo

Showing 6 changed files with 181 additions and 11 deletions Side-by-side Diff

... ... @@ -0,0 +1,158 @@
  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的命名空间。
0 159 \ No newline at end of file
1 1 apply plugin: 'com.android.application'
2 2  
  3 +
3 4 android {
4 5 compileSdkVersion 27
5 6 defaultConfig {
... ... @@ -17,23 +18,30 @@ android {
17 18 }
18 19 }
19 20  
20   - applicationVariants.all{
21   - variant->
22   - variant.outputs.all{
23   - outputFileName = "SDKDemo-"+variant.name+defaultConfig.versionName+".apk"
  21 + applicationVariants.all {
  22 + variant ->
  23 + variant.outputs.all {
  24 + outputFileName = "SDKDemo-" + variant.name + defaultConfig.versionName + ".apk"
24 25 }
25 26 }
  27 +
  28 + lintOptions {
  29 + abortOnError false
  30 + }
26 31 }
27 32  
28 33 dependencies {
29 34 implementation fileTree(dir: 'libs', include: ['*.jar'])
30   - implementation 'com.android.support:appcompat-v7:27.1.1'
31 35 implementation 'com.android.support.constraint:constraint-layout:1.1.3'
32 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')
37   - implementation project(':passport')
38   - implementation project(':payment')
  38 + //基础功能依赖,必须
  39 + implementation 'com.gump:base:5.0.0'
  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'
  46 +// implementation project(':payment')
39 47 }
app/proguard-rules.pro
... ... @@ -19,3 +19,4 @@
19 19 # If you keep the line number information, uncomment this to
20 20 # hide the original source file name.
21 21 #-renamesourcefileattribute SourceFile
  22 +-keep class com.gump.payment.web.* {*;}
22 23 \ No newline at end of file
... ... @@ -19,6 +19,9 @@ allprojects {
19 19 repositories {
20 20 google()
21 21 jcenter()
  22 + maven{
  23 + url "http://117.50.8.198:8081/nexus/content/repositories/sdk"
  24 + }
22 25 }
23 26 }
24 27  
1 1 -include ':app'
  2 +include ':app'
2 3 \ No newline at end of file