Blame view

README.md 5.37 KB
842cbfbfb   赵康   增加文档
1
  # Gump SDK 5 for Android接入文档
f905cc410   赵康   SDK has update to...
2
3
  V5.1.0  
  2019年03月18日
842cbfbfb   赵康   增加文档
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  
  ## 版本概述
  
  此版本为使用AndroidStudio开发的版本,使用aar在线依赖的方式提供sdk接入包,相对上一版本没有任何继承关系,请按此文档描述接入.
  
  此SDK适用android4.0以上系统.
  
  本SDK分为两个部分:登录和支付,请按需引用依赖包.
  
  ## 第一章  接入指南
  ### 1.依赖导入
  配置gradle,以下为必须项
  
      repositories{
          maven{
          	url "http://117.50.8.198:8081/nexus/content/repositories/sdk"
      	}
      }
      dependencies {
  		//基础功能依赖,必须
f905cc410   赵康   SDK has update to...
24
          implementation 'com.gump:base:5.1.0'
842cbfbfb   赵康   增加文档
25
  		//登录功能依赖
f905cc410   赵康   SDK has update to...
26
          implementation 'com.gump:Passport:5.1.0'
842cbfbfb   赵康   增加文档
27
  		//支付功能依赖
f905cc410   赵康   SDK has update to...
28
          implementation 'com.gump:Payment:5.1.0'
842cbfbfb   赵康   增加文档
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
      }
  
  ### 2.修改AndroidManifest.xml文件
  首先添加必要的权限,如下所示:
  
      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
      <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. -->
      <uses-permission android:name="com.android.vending.BILLING" />
  
  创建一个strings 配置如下
  
  	<string name="app_id">your_play_games_app_id</string>
  
  增加play games的meta-data配置
  
  	<meta-data
         android:name="com.google.android.gms.games.APP_ID"
         android:value="@string/app_id"/>
      <meta-data
         android:name="com.google.android.gms.version"
         android:value="@integer/google_play_services_version"/>
  
  ### 3.1 初始化与配置    
842cbfbfb   赵康   增加文档
54
55
56
57
58
59
60
61
62
63
  
  *若要使用V4版支付请设置
  
      SDKAgent.getSettings().setPaymentVersion(PaymentVersion.V4);
  
  *执行初始化     
  
  	SDKAgent.init(Context,Appid,ChannelId);
  
  ### 3.2 登录接入
f905cc410   赵康   SDK has update to...
64
65
66
67
68
69
70
71
  AndroidManifest.xml配置: 
  
  	<activity
              android:name="com.gump.gpassport.GumpLoginActivity"
              android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout"
              android:launchMode="singleTask"
              android:screenOrientation="behind"
              android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
842cbfbfb   赵康   增加文档
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  构建Passport实例
  	
  	passport = new Passport.Builder().context(Context).setListener(StateListener).build();  
  
  其中StateListener为登录状态监听接口,需要实现如下方法
  	
  	//成功回调,成功事件类型由action枚举对象标识,player是成功返回的玩家对象
  	void onActionSucced(Actions action, GamePlayer player)
  	//失败回调
  	void onActionFailured()
  
  接下来,添加生命周期处理方法
  
  	@Override
      protected void onResume() {
          super.onResume();
          passport.onResume();
      }
  
  处理结果返回
  
  	@Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          if (!passport.onActivityResult(requestCode, resultCode, data))
              super.onActivityResult(requestCode, resultCode, data);
      }
f905cc410   赵康   SDK has update to...
98
99
100
101
102
103
104
105
106
107
108
109
  ### 3.3 账号绑定
    
  	passport.link(Activity);
  
  ### 3.4 账号切换
  切换到系统账号
  
  	passport.switchAccount(PlayerType.GamePlayer);
  切换gump账号
  
  	passport.switchAccount(PlayerType.GumpPlayer);
  ### 3.5 支付接入
842cbfbfb   赵康   增加文档
110
111
112
113
114
115
  注册相应的Activity,具体如下:
      
      <activity
          android:name="com.gumptech.sdk.PaymentActivity"
          android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout"
          android:launchMode="singleTask"
f905cc410   赵康   SDK has update to...
116
  		android:screenOrientation="behind"
842cbfbfb   赵康   增加文档
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
          android:theme="@android:style/Theme.Translucent.NoTitleBar" >
          <intent-filter>
              <category android:name="android.intent.category.DEFAULT" />
              <action android:name="android.intent.action.VIEW" />
              <category android:name="android.intent.category.BROWSABLE" />
              <data
                  android:host="com.gump.sdk"
                  android:scheme="gump+游戏的appId" />
          </intent-filter>
      </activity>
  
  三方支付调用
  
  	Bundle payInfo = new Bundle();
      payInfo.putString("product", "wa2");
      payInfo.putFloat("amount", 0.1f);
      payInfo.putString("extraInfo", "This is demo!");
      payInfo.putString("serverId", "100");
      payInfo.putString("roleId", "41080");
      Payment.pay(Activity, payInfo, PurchaseCallback);
  
  Google IAB支付调用
  
  	Bundle payInfo = new Bundle();
      payInfo.putString("product", "180010");
      payInfo.putFloat("amount", 0.1f);
      payInfo.putString("extraInfo", "This is demo!");
      payInfo.putString("serverId", "100");
      payInfo.putString("roleId", "41080");
      Payment.launchIAP(Activity, payInfo, PurchaseCallback);
  
  PurchaseCallback为支付状态回调接口,此接口含有3个方法  
  
      @Override
      public void onPurchaseCompleted(PurchaseResult result) {
          Log.i(TAG,"purchase completed");
      }
  
      @Override
      public void onPurchaseError(int code, String msg) {
          Log.i(TAG,"purchase error");
      }
  
      @Override
      public void onPurchaseCanceled() {
          Log.i(TAG,"purchase canceled");
      }
  
  ## 第二章 常见问题      
  ### 问题1: 如何避免混淆对SDK的影响?       
  解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java
  类,导致SDK无法正常工作,解决方法如下:      
  Ø  请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上       
  
      -keep class com.gump.payment.web.* {*;}
      
  使得混淆的时候不会影响SDK的命名空间。