Commit 9e8388286bb79ba341ba372bb3eb3ff63e124483
1 parent
f905cc4105
Exists in
master
修改账号绑定,增加账号联动
Showing 4 changed files with 49 additions and 36 deletions Inline Diff
README.md
1 | # Gump SDK 5 for Android接入文档 | 1 | # Gump SDK 5 for Android接入文档 |
2 | 2 | ||
3 | V5.1.0 | 3 | V5.2.2 |
4 | 2019年03月18日 | 4 | 2019年06月06日 |
5 | 5 | ||
6 | ## 版本概述 | 6 | ## 版本概述 |
7 | 7 | ||
8 | 此版本为使用AndroidStudio开发的版本,使用aar在线依赖的方式提供sdk接入包,相对上一版本没有任何继承关系,请按此文档描述接入. | 8 | 此版本为使用AndroidStudio开发的版本,使用aar在线依赖的方式提供sdk接入包,相对上一版本没有任何继承关系,请按此文档描述接入. |
9 | 9 | ||
10 | 此SDK适用android4.0以上系统. | 10 | 此SDK适用android4.0以上系统. |
11 | 11 | ||
12 | 本SDK分为两个部分:登录和支付,请按需引用依赖包. | 12 | 本SDK分为两个部分:登录和支付,请按需引用依赖包. |
13 | 13 | ||
14 | ## 第一章 接入指南 | 14 | ## 第一章 接入指南 |
15 | ### 1.依赖导入 | 15 | ### 1.依赖导入 |
16 | 配置gradle,以下为必须项 | 16 | 配置gradle,以下为必须项 |
17 | 17 | ||
18 | repositories{ | 18 | repositories{ |
19 | maven{ | 19 | maven{ |
20 | url "http://117.50.8.198:8081/nexus/content/repositories/sdk" | 20 | url "http://117.50.8.198:8081/nexus/content/repositories/sdk" |
21 | } | 21 | } |
22 | } | 22 | } |
23 | dependencies { | 23 | dependencies { |
24 | //基础功能依赖,必须 | ||
25 | implementation 'com.gump:base:5.1.0' | ||
26 | //登录功能依赖 | 24 | //登录功能依赖 |
27 | implementation 'com.gump:Passport:5.1.0' | 25 | implementation 'com.gump:Passport:5.2.2' |
28 | //支付功能依赖 | 26 | //支付功能依赖 |
29 | implementation 'com.gump:Payment:5.1.0' | 27 | implementation 'com.gump:Payment:5.1.2' |
30 | } | 28 | } |
31 | 29 | ||
32 | ### 2.修改AndroidManifest.xml文件 | 30 | ### 2.修改AndroidManifest.xml文件 |
33 | 首先添加必要的权限,如下所示: | 31 | 首先添加必要的权限,如下所示: |
34 | 32 | ||
35 | <uses-permission android:name="android.permission.INTERNET" /> | 33 | <uses-permission android:name="android.permission.INTERNET" /> |
36 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> | 34 | <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> |
37 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | 35 | <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> |
38 | <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> | 36 | <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. --> |
39 | <uses-permission android:name="com.android.vending.BILLING" /> | 37 | <uses-permission android:name="com.android.vending.BILLING" /> |
40 | 38 | ||
41 | 创建一个strings 配置如下 | 39 | 创建一个strings 配置如下 |
42 | 40 | ||
43 | <string name="app_id">your_play_games_app_id</string> | 41 | <string name="app_id">your_play_games_app_id</string> |
44 | 42 | ||
45 | 增加play games的meta-data配置 | 43 | 增加play games的meta-data配置 |
46 | 44 | ||
47 | <meta-data | 45 | <meta-data |
48 | android:name="com.google.android.gms.games.APP_ID" | 46 | android:name="com.google.android.gms.games.APP_ID" |
49 | android:value="@string/app_id"/> | 47 | android:value="@string/app_id"/> |
50 | <meta-data | 48 | <meta-data |
51 | android:name="com.google.android.gms.version" | 49 | android:name="com.google.android.gms.version" |
52 | android:value="@integer/google_play_services_version"/> | 50 | android:value="@integer/google_play_services_version"/> |
53 | 51 | ||
54 | ### 3.1 初始化与配置 | 52 | ### 3.1 初始化与配置 |
55 | 53 | ||
56 | *若要使用V4版支付请设置 | 54 | *若要使用V4版支付请设置 |
57 | 55 | ||
58 | SDKAgent.getSettings().setPaymentVersion(PaymentVersion.V4); | 56 | SDKAgent.getSettings().setPaymentVersion(PaymentVersion.V4); |
59 | 57 | ||
60 | *执行初始化 | 58 | *执行初始化 |
61 | 59 | ||
62 | SDKAgent.init(Context,Appid,ChannelId); | 60 | SDKAgent.init(Context,Appid,ChannelId); |
63 | 61 | ||
64 | ### 3.2 登录接入 | 62 | ### 3.2 登录接入 |
65 | AndroidManifest.xml配置: | 63 | AndroidManifest.xml配置: |
66 | 64 | ||
67 | <activity | 65 | <activity |
68 | android:name="com.gump.gpassport.GumpLoginActivity" | 66 | android:name="com.gump.gpassport.GumpLoginActivity" |
69 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | 67 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" |
70 | android:launchMode="singleTask" | 68 | android:launchMode="singleTask" |
71 | android:screenOrientation="behind" | 69 | android:screenOrientation="behind" |
72 | android:theme="@style/Theme.AppCompat.Light.NoActionBar"/> | 70 | android:theme="@style/Theme.AppCompat.Light.NoActionBar"/> |
73 | 构建Passport实例 | 71 | 构建Passport实例 |
74 | 72 | ||
75 | passport = new Passport.Builder().context(Context).setListener(StateListener).build(); | 73 | passport = new Passport.Builder().context(Context).setListener(StateListener).build(); |
76 | 74 | ||
77 | 其中StateListener为登录状态监听接口,需要实现如下方法 | 75 | 其中StateListener为登录状态监听接口,需要实现如下方法 |
78 | 76 | ||
79 | //成功回调,成功事件类型由action枚举对象标识,player是成功返回的玩家对象 | 77 | //成功回调,成功事件类型由action枚举对象标识,player是成功返回的玩家对象 |
80 | void onActionSucced(Actions action, GamePlayer player) | 78 | void onActionSucced(Actions action, GamePlayer player) |
81 | //失败回调 | 79 | //失败回调 |
82 | void onActionFailured() | 80 | void onActionFailured() |
83 | 81 | ||
82 | Actinos枚举: | ||
83 | |||
84 | SIGN 登录 | ||
85 | SWITCH_PENDING 切换PlayGame账号,需重启游戏 | ||
86 | SWITCH 已切换甘普账号,需重新加载用户角色信息 | ||
87 | |||
84 | 接下来,添加生命周期处理方法 | 88 | 接下来,添加生命周期处理方法 |
85 | 89 | ||
86 | @Override | 90 | @Override |
87 | protected void onResume() { | 91 | protected void onResume() { |
88 | super.onResume(); | 92 | super.onResume(); |
89 | passport.onResume(); | 93 | passport.onResume(); |
90 | } | 94 | } |
91 | 95 | ||
92 | 处理结果返回 | 96 | 处理结果返回 |
93 | 97 | ||
94 | @Override | 98 | @Override |
95 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { | 99 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
96 | if (!passport.onActivityResult(requestCode, resultCode, data)) | 100 | if (!passport.onActivityResult(requestCode, resultCode, data)) |
97 | super.onActivityResult(requestCode, resultCode, data); | 101 | super.onActivityResult(requestCode, resultCode, data); |
98 | } | 102 | } |
99 | 103 | ||
100 | ### 3.3 账号绑定 | 104 | ### 3.3 账号联动 |
101 | 105 | ||
102 | passport.link(Activity); | 106 | passport.link(Activity); |
103 | 107 | ||
104 | ### 3.4 账号切换 | 108 | ### 3.4 账号切换 |
105 | 切换到系统账号 | 109 | 切换到PlayGame账号 |
110 | |||
111 | passport.switchAccount(); | ||
106 | 112 | ||
107 | passport.switchAccount(PlayerType.GamePlayer); | ||
108 | 切换gump账号 | ||
109 | 113 | ||
110 | passport.switchAccount(PlayerType.GumpPlayer); | ||
111 | ### 3.5 支付接入 | 114 | ### 3.5 支付接入 |
112 | 注册相应的Activity,具体如下: | 115 | 注册相应的Activity,具体如下: |
113 | 116 | ||
114 | <activity | 117 | <activity |
115 | android:name="com.gumptech.sdk.PaymentActivity" | 118 | android:name="com.gumptech.sdk.PaymentActivity" |
116 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" | 119 | android:configChanges="orientation|screenSize|keyboardHidden|keyboard|screenLayout" |
117 | android:launchMode="singleTask" | 120 | android:launchMode="singleTask" |
118 | android:screenOrientation="behind" | 121 | android:screenOrientation="behind" |
119 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > | 122 | android:theme="@android:style/Theme.Translucent.NoTitleBar" > |
120 | <intent-filter> | 123 | <intent-filter> |
121 | <category android:name="android.intent.category.DEFAULT" /> | 124 | <category android:name="android.intent.category.DEFAULT" /> |
122 | <action android:name="android.intent.action.VIEW" /> | 125 | <action android:name="android.intent.action.VIEW" /> |
123 | <category android:name="android.intent.category.BROWSABLE" /> | 126 | <category android:name="android.intent.category.BROWSABLE" /> |
124 | <data | 127 | <data |
125 | android:host="com.gump.sdk" | 128 | android:host="com.gump.sdk" |
126 | android:scheme="gump+游戏的appId" /> | 129 | android:scheme="gump+游戏的appId" /> |
127 | </intent-filter> | 130 | </intent-filter> |
128 | </activity> | 131 | </activity> |
129 | 132 | ||
130 | 三方支付调用 | 133 | 1)判断是否使用三方支付 |
134 | |||
135 | Payment.shouldUseCoPay(this, serverId, roleId, new ResultCallback() { | ||
136 | @Override | ||
137 | public void onResult(boolean isRisk) { | ||
138 | //isRisk==true时使用IAB支付,isRisk==false时使用三方支付 | ||
139 | } | ||
140 | }); | ||
141 | |||
142 | 2)三方支付调用 | ||
131 | 143 | ||
132 | Bundle payInfo = new Bundle(); | 144 | Bundle payInfo = new Bundle(); |
133 | payInfo.putString("product", "wa2"); | 145 | payInfo.putString("product", "wa2"); |
134 | payInfo.putFloat("amount", 0.1f); | 146 | payInfo.putFloat("amount", 0.1f); |
135 | payInfo.putString("extraInfo", "This is demo!"); | 147 | payInfo.putString("extraInfo", "This is demo!"); |
136 | payInfo.putString("serverId", "100"); | 148 | payInfo.putString("serverId", "100"); |
137 | payInfo.putString("roleId", "41080"); | 149 | payInfo.putString("roleId", "41080"); |
138 | Payment.pay(Activity, payInfo, PurchaseCallback); | 150 | Payment.pay(Activity, payInfo, PurchaseCallback); |
139 | 151 | ||
140 | Google IAB支付调用 | 152 | 3)Google IAB支付调用 |
141 | 153 | ||
142 | Bundle payInfo = new Bundle(); | 154 | Bundle payInfo = new Bundle(); |
143 | payInfo.putString("product", "180010"); | 155 | payInfo.putString("product", "180010"); |
144 | payInfo.putFloat("amount", 0.1f); | 156 | payInfo.putFloat("amount", 0.1f); |
145 | payInfo.putString("extraInfo", "This is demo!"); | 157 | payInfo.putString("extraInfo", "This is demo!"); |
146 | payInfo.putString("serverId", "100"); | 158 | payInfo.putString("serverId", "100"); |
147 | payInfo.putString("roleId", "41080"); | 159 | payInfo.putString("roleId", "41080"); |
148 | Payment.launchIAP(Activity, payInfo, PurchaseCallback); | 160 | Payment.launchIAP(Activity, payInfo, PurchaseCallback); |
149 | 161 | ||
150 | PurchaseCallback为支付状态回调接口,此接口含有3个方法 | 162 | PurchaseCallback为支付状态回调接口,此接口含有3个方法 |
151 | 163 | ||
152 | @Override | 164 | @Override |
153 | public void onPurchaseCompleted(PurchaseResult result) { | 165 | public void onPurchaseCompleted(PurchaseResult result) { |
154 | Log.i(TAG,"purchase completed"); | 166 | Log.i(TAG,"purchase completed"); |
155 | } | 167 | } |
156 | 168 | ||
157 | @Override | 169 | @Override |
158 | public void onPurchaseError(int code, String msg) { | 170 | public void onPurchaseError(int code, String msg) { |
159 | Log.i(TAG,"purchase error"); | 171 | Log.i(TAG,"purchase error"); |
160 | } | 172 | } |
161 | 173 | ||
162 | @Override | 174 | @Override |
163 | public void onPurchaseCanceled() { | 175 | public void onPurchaseCanceled() { |
164 | Log.i(TAG,"purchase canceled"); | 176 | Log.i(TAG,"purchase canceled"); |
165 | } | 177 | } |
166 | 178 | ||
167 | ## 第二章 常见问题 | 179 | ## 第二章 常见问题 |
168 | ### 问题1: 如何避免混淆对SDK的影响? | 180 | ### 问题1: 如何避免混淆对SDK的影响? |
169 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java | 181 | 解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java |
170 | 类,导致SDK无法正常工作,解决方法如下: | 182 | 类,导致SDK无法正常工作,解决方法如下: |
app/build.gradle
1 | apply plugin: 'com.android.application' | 1 | apply plugin: 'com.android.application' |
2 | 2 | ||
3 | 3 | ||
4 | android { | 4 | android { |
5 | compileSdkVersion 27 | 5 | compileSdkVersion 27 |
6 | defaultConfig { | 6 | defaultConfig { |
7 | applicationId "com.gump.passport.demo" | 7 | applicationId "com.gump.passport.demo" |
8 | minSdkVersion 15 | 8 | minSdkVersion 15 |
9 | targetSdkVersion 27 | 9 | targetSdkVersion 27 |
10 | versionCode 9 | 10 | versionCode 9 |
11 | versionName "1.0.9" | 11 | versionName "1.0.9" |
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" |
13 | vectorDrawables.useSupportLibrary = true | 13 | vectorDrawables.useSupportLibrary = true |
14 | } | 14 | } |
15 | buildTypes { | 15 | buildTypes { |
16 | release { | 16 | release { |
17 | minifyEnabled false | 17 | minifyEnabled false |
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' |
19 | } | 19 | } |
20 | } | 20 | } |
21 | 21 | ||
22 | applicationVariants.all { | 22 | applicationVariants.all { |
23 | variant -> | 23 | variant -> |
24 | variant.outputs.all { | 24 | variant.outputs.all { |
25 | outputFileName = "SDKDemo-" + variant.name + defaultConfig.versionName + ".apk" | 25 | outputFileName = "SDKDemo-" + variant.name + defaultConfig.versionName + ".apk" |
26 | } | 26 | } |
27 | } | 27 | } |
28 | 28 | ||
29 | lintOptions { | 29 | lintOptions { |
30 | abortOnError false | 30 | abortOnError false |
31 | } | 31 | } |
32 | } | 32 | } |
33 | 33 | ||
34 | dependencies { | 34 | dependencies { |
35 | implementation fileTree(dir: 'libs', include: ['*.jar']) | 35 | implementation fileTree(dir: 'libs', include: ['*.jar']) |
36 | implementation 'com.android.support:appcompat-v7:27.1.1' | 36 | implementation 'com.android.support:appcompat-v7:27.1.1' |
37 | implementation 'com.android.support:support-v4:27.1.1' | 37 | implementation 'com.android.support:support-v4:27.1.1' |
38 | implementation 'com.android.support:support-vector-drawable:27.1.1' | 38 | implementation 'com.android.support:support-vector-drawable:27.1.1' |
39 | testImplementation 'junit:junit:4.12' | 39 | testImplementation 'junit:junit:4.12' |
40 | 40 | ||
41 | //基础功能依赖,必须 | 41 | //基础功能依赖,必须 |
42 | implementation 'com.gump:base:5.1.0' | 42 | // implementation 'com.gump:base:5.1.1' |
43 | // implementation project(':base') | 43 | // implementation project(':base') |
44 | // 登录功能依赖 | 44 | // 登录功能依赖 |
45 | implementation 'com.gump:Passport:5.1.0' | 45 | implementation 'com.gump:Passport:5.2.2' |
46 | // implementation project(':passport') | 46 | // implementation project(':passport') |
47 | //支付功能依赖 | 47 | //支付功能依赖 |
48 | implementation 'com.gump:Payment:5.1.0' | 48 | implementation 'com.gump:Payment:5.1.2' |
49 | // implementation project(':payment') | 49 | // implementation project(':payment') |
50 | } | 50 | } |
51 | 51 |
app/src/main/java/com/gump/passport/demo/MainActivity.java
1 | package com.gump.passport.demo; | 1 | package com.gump.passport.demo; |
2 | 2 | ||
3 | import android.content.Intent; | 3 | import android.content.Intent; |
4 | import android.content.SharedPreferences; | 4 | import android.content.SharedPreferences; |
5 | import android.os.Bundle; | 5 | import android.os.Bundle; |
6 | import android.preference.PreferenceManager; | 6 | import android.preference.PreferenceManager; |
7 | import android.support.v7.app.AppCompatActivity; | 7 | import android.support.v7.app.AppCompatActivity; |
8 | import android.util.Log; | 8 | import android.util.Log; |
9 | import android.view.Menu; | 9 | import android.view.Menu; |
10 | import android.view.MenuItem; | 10 | import android.view.MenuItem; |
11 | import android.view.View; | 11 | import android.view.View; |
12 | import android.widget.Button; | 12 | import android.widget.Button; |
13 | import android.widget.TextView; | 13 | import android.widget.TextView; |
14 | import android.widget.Toast; | 14 | import android.widget.Toast; |
15 | 15 | ||
16 | import com.gump.PaymentVersion; | 16 | import com.gump.PaymentVersion; |
17 | import com.gump.SDKAgent; | 17 | import com.gump.SDKAgent; |
18 | import com.gump.gpassport.Actions; | 18 | import com.gump.gpassport.Actions; |
19 | import com.gump.gpassport.GamePlayer; | 19 | import com.gump.gpassport.GamePlayer; |
20 | import com.gump.gpassport.Passport; | 20 | import com.gump.gpassport.Passport; |
21 | import com.gump.gpassport.PlayerType; | ||
22 | import com.gump.gpassport.StateListener; | 21 | import com.gump.gpassport.StateListener; |
23 | import com.gump.payment.Payment; | 22 | import com.gump.payment.Payment; |
24 | import com.gump.payment.callback.PurchaseCallback; | 23 | import com.gump.payment.callback.PurchaseCallback; |
25 | import com.gump.payment.callback.ResultCallback; | 24 | import com.gump.payment.callback.ResultCallback; |
26 | 25 | ||
27 | public class MainActivity extends AppCompatActivity implements StateListener, PurchaseCallback { | 26 | public class MainActivity extends AppCompatActivity implements StateListener, PurchaseCallback { |
28 | 27 | ||
29 | private static final String TAG = "MainActivity"; | 28 | private static final String TAG = "MainActivity"; |
30 | private Passport passport; | 29 | private Passport passport; |
31 | private TextView tvInfo; | 30 | private TextView tvInfo; |
32 | private View mainLayout; | 31 | private View mainLayout; |
33 | private Button btnLogin; | 32 | private Button btnLogin; |
34 | 33 | ||
35 | private GamePlayer currentPlayer; | 34 | private GamePlayer currentPlayer; |
36 | 35 | ||
37 | private Button btnIab; | 36 | private Button btnIab; |
38 | private Button btnPay; | 37 | private Button btnPay; |
39 | private Button btnCheck; | 38 | private Button btnCheck; |
40 | 39 | ||
41 | @Override | 40 | @Override |
42 | protected void onCreate(Bundle savedInstanceState) { | 41 | protected void onCreate(Bundle savedInstanceState) { |
43 | super.onCreate(savedInstanceState); | 42 | super.onCreate(savedInstanceState); |
44 | setContentView(R.layout.activity_main); | 43 | setContentView(R.layout.activity_main); |
45 | 44 | ||
46 | tvInfo = findViewById(R.id.info); | 45 | tvInfo = findViewById(R.id.info); |
47 | mainLayout = findViewById(R.id.main_layout); | 46 | mainLayout = findViewById(R.id.main_layout); |
48 | btnLogin = findViewById(R.id.login); | 47 | btnLogin = findViewById(R.id.login); |
49 | btnLogin.setOnClickListener(new View.OnClickListener() { | 48 | btnLogin.setOnClickListener(new View.OnClickListener() { |
50 | @Override | 49 | @Override |
51 | public void onClick(View v) { | 50 | public void onClick(View v) { |
52 | passport.signIn(MainActivity.this); | 51 | passport.signIn(MainActivity.this); |
53 | } | 52 | } |
54 | }); | 53 | }); |
55 | 54 | ||
56 | btnCheck = mainLayout.findViewById(R.id.check); | 55 | btnCheck = mainLayout.findViewById(R.id.check); |
57 | btnCheck.setOnClickListener(new View.OnClickListener() { | 56 | btnCheck.setOnClickListener(new View.OnClickListener() { |
58 | @Override | 57 | @Override |
59 | public void onClick(View v) { | 58 | public void onClick(View v) { |
60 | initPay(); | 59 | initPay(); |
61 | } | 60 | } |
62 | }); | 61 | }); |
63 | btnIab = mainLayout.findViewById(R.id.iab); | 62 | btnIab = mainLayout.findViewById(R.id.iab); |
64 | btnIab.setOnClickListener(new View.OnClickListener() { | 63 | btnIab.setOnClickListener(new View.OnClickListener() { |
65 | @Override | 64 | @Override |
66 | public void onClick(View v) { | 65 | public void onClick(View v) { |
67 | Bundle payInfo = assemblePayBundle(); | 66 | Bundle payInfo = assemblePayBundle(); |
68 | Payment.launchIAP(MainActivity.this, payInfo, MainActivity.this); | 67 | Payment.launchIAP(MainActivity.this, payInfo, MainActivity.this); |
69 | } | 68 | } |
70 | }); | 69 | }); |
71 | 70 | ||
72 | btnPay = mainLayout.findViewById(R.id.pay); | 71 | btnPay = mainLayout.findViewById(R.id.pay); |
73 | btnPay.setOnClickListener(new View.OnClickListener() { | 72 | btnPay.setOnClickListener(new View.OnClickListener() { |
74 | @Override | 73 | @Override |
75 | public void onClick(View v) { | 74 | public void onClick(View v) { |
76 | Bundle payInfo = assemblePayBundle(); | 75 | Bundle payInfo = assemblePayBundle(); |
77 | Payment.pay(MainActivity.this, payInfo, MainActivity.this); | 76 | Payment.pay(MainActivity.this, payInfo, MainActivity.this); |
78 | } | 77 | } |
79 | }); | 78 | }); |
80 | 79 | ||
81 | mainLayout.findViewById(R.id.bind).setOnClickListener(new View.OnClickListener() { | 80 | /** |
81 | * gump账号联动 | ||
82 | */ | ||
83 | mainLayout.findViewById(R.id.link).setOnClickListener(new View.OnClickListener() { | ||
82 | @Override | 84 | @Override |
83 | public void onClick(View v) { | 85 | public void onClick(View v) { |
84 | passport.link(MainActivity.this); | 86 | passport.link(MainActivity.this); |
85 | } | 87 | } |
86 | }); | 88 | }); |
87 | 89 | ||
90 | /** | ||
91 | * 切换PlayGames账号 | ||
92 | */ | ||
88 | mainLayout.findViewById(R.id.switch_acc).setOnClickListener(new View.OnClickListener() { | 93 | mainLayout.findViewById(R.id.switch_acc).setOnClickListener(new View.OnClickListener() { |
89 | @Override | 94 | @Override |
90 | public void onClick(View v) { | 95 | public void onClick(View v) { |
91 | passport.switchAccount(PlayerType.GamePlayer); | 96 | passport.switchAccount(); |
92 | } | 97 | } |
93 | }); | 98 | }); |
94 | 99 | ||
95 | mainLayout.findViewById(R.id.switch_gump).setOnClickListener(new View.OnClickListener() { | ||
96 | @Override | ||
97 | public void onClick(View v) { | ||
98 | passport.switchAccount(PlayerType.GumpPlayer); | ||
99 | } | ||
100 | }); | ||
101 | |||
102 | |||
103 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); | 100 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); |
104 | boolean mode = sp.getBoolean("key_mode", true); | 101 | boolean mode = sp.getBoolean("key_mode", true); |
105 | String appId = sp.getString("key_appid", "100"); | 102 | String appId = sp.getString("key_appid", "100"); |
106 | String channel = sp.getString("key_channel", "1000"); | 103 | String channel = sp.getString("key_channel", "1000"); |
107 | String payVersion = sp.getString("key_pay_version", "V3"); | 104 | String payVersion = sp.getString("key_pay_version", "V3"); |
108 | 105 | ||
106 | /** | ||
107 | * SDK配置 | ||
108 | */ | ||
109 | SDKAgent.init(getApplicationContext(), appId, channel); | 109 | SDKAgent.init(getApplicationContext(), appId, channel); |
110 | SDKAgent.getSettings().setDebug(mode); | 110 | SDKAgent.getSettings().setDebug(mode); |
111 | SDKAgent.getSettings().setPaymentVersion(PaymentVersion.valueOf(payVersion)); | 111 | SDKAgent.getSettings().setPaymentVersion(PaymentVersion.valueOf(payVersion)); |
112 | 112 | ||
113 | /** | ||
114 | * 实例化登录功能 | ||
115 | */ | ||
113 | passport = new Passport.Builder().context(MainActivity.this).setListener(MainActivity.this).build(); | 116 | passport = new Passport.Builder().context(MainActivity.this).setListener(MainActivity.this).build(); |
114 | 117 | ||
115 | } | 118 | } |
116 | 119 | ||
117 | private Bundle assemblePayBundle() { | 120 | private Bundle assemblePayBundle() { |
118 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); | 121 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); |
119 | Bundle payInfo = new Bundle(); | 122 | Bundle payInfo = new Bundle(); |
120 | payInfo.putString("product", sp.getString("key_product", "10080")); | 123 | payInfo.putString("product", sp.getString("key_product", "10080")); |
121 | payInfo.putFloat("amount", sp.getFloat("key_amount", 0.1f)); | 124 | payInfo.putFloat("amount", sp.getFloat("key_amount", 0.1f)); |
122 | payInfo.putString("extraInfo", sp.getString("key_extra", "test")); | 125 | payInfo.putString("extraInfo", sp.getString("key_extra", "test")); |
123 | payInfo.putString("serverId", sp.getString("key_server_id", "100")); | 126 | payInfo.putString("serverId", sp.getString("key_server_id", "100")); |
124 | payInfo.putString("roleId", sp.getString("key_role_id", "41080")); | 127 | payInfo.putString("roleId", sp.getString("key_role_id", "41080")); |
125 | payInfo.putString("currency", sp.getString("key_currency", "THB")); | 128 | payInfo.putString("currency", sp.getString("key_currency", "THB")); |
126 | return payInfo; | 129 | return payInfo; |
127 | } | 130 | } |
128 | 131 | ||
129 | 132 | ||
130 | private void initPay() { | 133 | private void initPay() { |
131 | btnCheck.setEnabled(false); | 134 | btnCheck.setEnabled(false); |
132 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); | 135 | SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); |
133 | String serverId = sp.getString("key_server_id", "100"); | 136 | String serverId = sp.getString("key_server_id", "100"); |
134 | String roleId = sp.getString("key_role_id", "41080"); | 137 | String roleId = sp.getString("key_role_id", "41080"); |
135 | Payment.shouldUseCoPay(this, serverId, roleId, new ResultCallback() { | 138 | Payment.shouldUseCoPay(this, serverId, roleId, new ResultCallback() { |
136 | @Override | 139 | @Override |
137 | public void onResult(boolean isRisk) { | 140 | public void onResult(boolean isRisk) { |
138 | btnCheck.setEnabled(true); | 141 | btnCheck.setEnabled(true); |
139 | btnIab.setEnabled(isRisk); | 142 | btnIab.setEnabled(isRisk); |
140 | btnPay.setEnabled(!isRisk); | 143 | btnPay.setEnabled(!isRisk); |
141 | } | 144 | } |
142 | }); | 145 | }); |
143 | } | 146 | } |
144 | 147 | ||
145 | @Override | 148 | @Override |
146 | public boolean onCreateOptionsMenu(Menu menu) { | 149 | public boolean onCreateOptionsMenu(Menu menu) { |
147 | getMenuInflater().inflate(R.menu.main, menu); | 150 | getMenuInflater().inflate(R.menu.main, menu); |
148 | return super.onCreateOptionsMenu(menu); | 151 | return super.onCreateOptionsMenu(menu); |
149 | } | 152 | } |
150 | 153 | ||
151 | @Override | 154 | @Override |
152 | public boolean onOptionsItemSelected(MenuItem item) { | 155 | public boolean onOptionsItemSelected(MenuItem item) { |
153 | if (item.getItemId() == R.id.setting) { | 156 | if (item.getItemId() == R.id.setting) { |
154 | Intent intent = new Intent(this, SettingsActivity.class); | 157 | Intent intent = new Intent(this, SettingsActivity.class); |
155 | startActivity(intent); | 158 | startActivity(intent); |
156 | return true; | 159 | return true; |
157 | } | 160 | } |
158 | return super.onOptionsItemSelected(item); | 161 | return super.onOptionsItemSelected(item); |
159 | } | 162 | } |
160 | 163 | ||
161 | @Override | 164 | @Override |
162 | public void onResume() { | 165 | public void onResume() { |
163 | super.onResume(); | 166 | super.onResume(); |
164 | passport.onResume(); | 167 | passport.onResume(); |
165 | } | 168 | } |
166 | 169 | ||
167 | @Override | 170 | @Override |
168 | public void onActivityResult(int requestCode, int resultCode, Intent data) { | 171 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
169 | if (!passport.onActivityResult(requestCode, resultCode, data)) | 172 | if (!passport.onActivityResult(requestCode, resultCode, data)) |
170 | super.onActivityResult(requestCode, resultCode, data); | 173 | super.onActivityResult(requestCode, resultCode, data); |
171 | } | 174 | } |
172 | 175 | ||
173 | @Override | 176 | @Override |
174 | public void onActionSucced(Actions action, GamePlayer player) { | 177 | public void onActionSucced(Actions action, GamePlayer player) { |
175 | switch (action) { | 178 | switch (action) { |
176 | case SIGN: | 179 | case SIGN: |
177 | currentPlayer = player; | 180 | currentPlayer = player; |
178 | tvInfo.setText("Login succed! gump id=" + player.getId() + ",playerType=" + player.getPlayerType()); | 181 | tvInfo.setText("Login succed! gump id=" + player.getId() + ",playerType=" + player.getPlayerType()); |
179 | btnLogin.setVisibility(View.GONE); | 182 | btnLogin.setVisibility(View.GONE); |
180 | mainLayout.setVisibility(View.VISIBLE); | 183 | mainLayout.setVisibility(View.VISIBLE); |
181 | break; | 184 | break; |
182 | case SWITCH: | 185 | case SWITCH_PENDING://将要切换PlayGame账号 |
186 | tvInfo.setText("The player wanna to switch Account!"); | ||
187 | Toast.makeText(this, "The account will be switched!", Toast.LENGTH_LONG).show(); | ||
188 | break; | ||
189 | case SWITCH://账号已切换 | ||
183 | tvInfo.setText("Switch account succed! Pls reboot the game!"); | 190 | tvInfo.setText("Switch account succed! Pls reboot the game!"); |
184 | Toast.makeText(this, "The account has switched,pls reboot the Game!", Toast.LENGTH_LONG).show(); | 191 | Toast.makeText(this, "The account has switched,pls reboot the Game!", Toast.LENGTH_LONG).show(); |
185 | break; | 192 | break; |
186 | } | 193 | } |
187 | } | 194 | } |
188 | 195 | ||
189 | @Override | 196 | @Override |
190 | public void onActionFailured(Throwable e) { | 197 | public void onActionFailured(Throwable e) { |
191 | tvInfo.setText("login has error:" + e.getMessage()); | 198 | tvInfo.setText("login has error:" + e.getMessage()); |
192 | } | 199 | } |
193 | 200 | ||
194 | @Override | 201 | @Override |
195 | public void onPurchaseCompleted() { | 202 | public void onPurchaseCompleted() { |
196 | Log.i(TAG, "purchase completed"); | 203 | Log.i(TAG, "purchase completed"); |
197 | } | 204 | } |
198 | 205 | ||
199 | @Override | 206 | @Override |
200 | public void onPurchaseError(int code, String msg) { | 207 | public void onPurchaseError(int code, String msg) { |
app/src/main/res/layout/activity_main.xml
1 | <?xml version="1.0" encoding="utf-8"?> | 1 | <?xml version="1.0" encoding="utf-8"?> |
2 | <LinearLayout | 2 | <LinearLayout |
3 | xmlns:android="http://schemas.android.com/apk/res/android" | 3 | xmlns:android="http://schemas.android.com/apk/res/android" |
4 | xmlns:tools="http://schemas.android.com/tools" | 4 | xmlns:tools="http://schemas.android.com/tools" |
5 | android:layout_width="match_parent" | 5 | android:layout_width="match_parent" |
6 | android:layout_height="match_parent" | 6 | android:layout_height="match_parent" |
7 | android:orientation="vertical" | 7 | android:orientation="vertical" |
8 | tools:context=".MainActivity"> | 8 | tools:context=".MainActivity"> |
9 | 9 | ||
10 | <TextView | 10 | <TextView |
11 | android:id="@+id/info" | 11 | android:id="@+id/info" |
12 | android:layout_width="match_parent" | 12 | android:layout_width="match_parent" |
13 | android:layout_height="wrap_content" | 13 | android:layout_height="wrap_content" |
14 | android:lines="2"/> | 14 | android:lines="2"/> |
15 | 15 | ||
16 | <Button | 16 | <Button |
17 | android:id="@+id/login" | 17 | android:id="@+id/login" |
18 | android:layout_width="match_parent" | 18 | android:layout_width="match_parent" |
19 | android:layout_height="wrap_content" | 19 | android:layout_height="wrap_content" |
20 | android:text="login"/> | 20 | android:text="login"/> |
21 | 21 | ||
22 | 22 | ||
23 | <LinearLayout | 23 | <LinearLayout |
24 | android:id="@+id/main_layout" | 24 | android:id="@+id/main_layout" |
25 | android:layout_width="match_parent" | 25 | android:layout_width="match_parent" |
26 | android:layout_height="match_parent" | 26 | android:layout_height="match_parent" |
27 | android:orientation="vertical" | 27 | android:orientation="vertical" |
28 | android:visibility="gone"> | 28 | android:visibility="gone"> |
29 | 29 | ||
30 | <Button | 30 | <Button |
31 | android:id="@+id/check" | 31 | android:id="@+id/check" |
32 | android:layout_width="match_parent" | 32 | android:layout_width="match_parent" |
33 | android:layout_height="wrap_content" | 33 | android:layout_height="wrap_content" |
34 | android:text="check payemnt state"/> | 34 | android:text="check payemnt state"/> |
35 | 35 | ||
36 | <Button | 36 | <Button |
37 | android:id="@+id/bind" | 37 | android:id="@+id/link" |
38 | android:layout_width="match_parent" | 38 | android:layout_width="match_parent" |
39 | android:layout_height="wrap_content" | 39 | android:layout_height="wrap_content" |
40 | android:text="Bind Gump account"/> | 40 | android:text="Link Gump account"/> |
41 | 41 | ||
42 | <Button | 42 | <Button |
43 | android:id="@+id/switch_acc" | 43 | android:id="@+id/switch_acc" |
44 | android:layout_width="match_parent" | 44 | android:layout_width="match_parent" |
45 | android:layout_height="wrap_content" | 45 | android:layout_height="wrap_content" |
46 | android:text="Switch to games player"/> | 46 | android:text="Switch to games player"/> |
47 | 47 | ||
48 | <Button | 48 | <Button |
49 | android:id="@+id/switch_gump" | ||
50 | android:layout_width="match_parent" | ||
51 | android:layout_height="wrap_content" | ||
52 | android:text="Switch to gump player"/> | ||
53 | |||
54 | <Button | ||
55 | android:id="@+id/iab" | 49 | android:id="@+id/iab" |
56 | android:layout_width="match_parent" | 50 | android:layout_width="match_parent" |
57 | android:layout_height="wrap_content" | 51 | android:layout_height="wrap_content" |
58 | android:enabled="false" | 52 | android:enabled="false" |
59 | android:text="Iab"/> | 53 | android:text="Iab"/> |
60 | 54 | ||
61 | <Button | 55 | <Button |
62 | android:id="@+id/pay" | 56 | android:id="@+id/pay" |
63 | android:layout_width="match_parent" | 57 | android:layout_width="match_parent" |
64 | android:layout_height="wrap_content" | 58 | android:layout_height="wrap_content" |
65 | android:enabled="false" | 59 | android:enabled="false" |
66 | android:text="Payment"/> | 60 | android:text="Payment"/> |
67 | </LinearLayout> | 61 | </LinearLayout> |
68 | </LinearLayout> | 62 | </LinearLayout> |