Blame view

doc/AndroidDocument.md 8.61 KB
b58707f79   赵康   init
1
  # Gump Android SDK使用文档
5817fcc88   赵康   增加链接
2
3
4
5
6
7
  接入手册        
  V 1.5       
  2014年07月23日    
          
  快速入口:       
  [支付部分服务端回调文档](http://git.letsgame.mobi/document/gumptech-document/blob/master/ServerDocument.md)										
b58707f79   赵康   init
8
9
  
  ## 目录
2172eb633   赵康   修正链接地址
10
11
12
13
14
15
16
17
  * [第一章  接入指南](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#)        
   - [1. 导入资源工程](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#1)     
   - [2. 添加资源工程](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#2)     
   - [3. 代码实现](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#3)     
     > [1.修改AndroidManifest.xml文件](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#1-androidmanifest-xml)      
     > [2.向Gump平台索要游戏ID(GID),完成代码接入](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#2-gump-id-gid)
  * [第二章 常见问题](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#)     
   - [问题1: 如何避免混淆对SDK的影响?](http://git.letsgame.mobi/document/gumptech-document/blob/master/AndroidDocument.md#1-sdk)       
b58707f79   赵康   init
18
19
20
21
22
23
24
25
  
  
  
  
  ## 第一章  接入指南
  配置环境
  
  本接口API	适用于Android2.2以上各版本Android平台。     
04a9e9502   赵康   完成格式编辑
26
  ### 1. 导入资源工程     
b58707f79   赵康   init
27
  1.将LoginSDK资源工程拷贝到工作空间,在eclipse中的导航栏右键弹出如图1画面,选择Import导入资源工程,如图1.
04a9e9502   赵康   完成格式编辑
28
29
  ![](images/1.png)       
          图1
b58707f79   赵康   init
30
31
  
  2.导入工程后,右键此工程,在Properties->Android中选中此工程为library工程(勾选红色方框标识处)如图2。
04a9e9502   赵康   完成格式编辑
32
33
34
  ![](images/2.png)         
  			图 2        
  ### 2. 添加资源工程
b58707f79   赵康   init
35
  添加资源工程为游戏项目的 library。右键游戏项目,在Properties->Android中点击Add添加资源工程为项目工程的library,结果如图3。 
04a9e9502   赵康   完成格式编辑
36
  ![](images/3.png)       
b58707f79   赵康   init
37
  	图 3
04a9e9502   赵康   完成格式编辑
38

b58707f79   赵康   init
39
40
41
42
43
44
  注意:如果ADT版本低于14,ADT不支持jar包自动引入,请手动拷贝libs到您的工作
  空间。 
  
  Eclipse查看ADT版本号的方法: 
  Help==>About Eclips点击Android对应的图标就可以查看版本了. 
  如图,红色框部分就是ADT版本号。 
04a9e9502   赵康   完成格式编辑
45
  ![](images/4.png)       
b58707f79   赵康   init
46

04a9e9502   赵康   完成格式编辑
47
48
  ### 3. 代码实现
  #### 1、	修改AndroidManifest.xml文件
b58707f79   赵康   init
49
  	首先添加必要的权限,如下所示:
04a9e9502   赵康   完成格式编辑
50
51
  	
      <uses-permission android:name="android.permission.INTERNET" />
b58707f79   赵康   init
52
53
      <uses-permission android:name="android.permission.READ_PHONE_STATE" />
      <uses-permission android:name="android.permission.BLUETOOTH" />
04a9e9502   赵康   完成格式编辑
54
55
56
57
      <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
      <uses-permission android:name="android.permission.WRITE_SETTINGS"/>
      <uses-permission android:name="android.permission.GET_ACCOUNTS"/>
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
e96fdff45   赵康   增加系统权限
58
59
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
      <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
04a9e9502   赵康   完成格式编辑
60
      <!-- for card.io card scanning -->
b58707f79   赵康   init
61
62
63
64
65
66
      <uses-permission android:name="android.permission.CAMERA" />
      <uses-permission android:name="android.permission.VIBRATE" />
      <uses-feature android:name="android.hardware.camera" android:required="false" />
      <uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
      <!-- VERY IMPORTANT! Don't forget this permission, or in-app billing won't work. -->
      <uses-permission android:name="com.android.vending.BILLING" />
04a9e9502   赵康   完成格式编辑
67
      
b58707f79   赵康   init
68
  其次注册相应的Activity,具体如下:
04a9e9502   赵康   完成格式编辑
69
70
71
72
73
74
75
76
77
78
  
      <activity
          android:name="com.gumptech.sdk.ContainerActivity"
          android:theme="@style/container_dialog"
          android:configChanges="orientation|screenLayout" >
      </activity>
      <activity
          android:name="com.facebook.LoginActivity"
          android:theme="@android:style/Theme.Translucent.NoTitleBar" >
      </activity>
b58707f79   赵康   init
79
  	<activity
04a9e9502   赵康   完成格式编辑
80
81
82
83
          android:name="com.gumptech.sdk.PaymentActivity"
          android:configChanges="orientation|screenLayout"
          android:theme="@android:style/Theme.Translucent.NoTitleBar" >
      </activity>
91314fccb   赵康   增加activity配置
84
85
86
87
88
      <activity
              android:name="com.gumptech.sdk.ExchangeWindow"
              android:configChanges="orientation|screenLayout"
              android:theme="@style/ex_win" >
      </activity>
04a9e9502   赵康   完成格式编辑
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
      <!-- paypal -->
      <service
          android:name="com.paypal.android.sdk.payments.PayPalService"
          android:exported="false" />
  
      <activity android:name="com.paypal.android.sdk.payments.PaymentActivity" />
      <activity android:name="com.paypal.android.sdk.payments.LoginActivity" />
      <activity android:name="com.paypal.android.sdk.payments.PaymentMethodActivity" />
      <activity android:name="com.paypal.android.sdk.payments.PaymentConfirmActivity" />
      <activity android:name="com.paypal.android.sdk.payments.PayPalFuturePaymentActivity" />
      <activity android:name="com.paypal.android.sdk.payments.FuturePaymentConsentActivity" />
      <activity android:name="com.paypal.android.sdk.payments.FuturePaymentInfoActivity" />
      <activity
          android:name="io.card.payment.CardIOActivity"
          android:configChanges="keyboardHidden|orientation" />
      <activity android:name="io.card.payment.DataEntryActivity" />
      
  #### 2、	向Gump平台索要游戏ID(GID),完成代码接入
  1.调用GumpSDK前需要执行初始化。        
  若不需要分渠道      
  
      GumpSDK.init(Appid, Appkey,FacebookId);   
  如果需要定义渠道,必须使用如下方法       
  
      GumpSDK.init(Appid, Appkey,FacebookId,ChannelId);       
  2.调用GumpSDK的开始方法,将执行登录流程,需要一个Activity实例作参数       
  
      GumpSDK.start(Activity);  
  开发者需要在调用的Activity里重写onActivityResult方法以接受用户的登录结果,通常如下:    
  
  	//登录请求返回结果      
  	if (requestCode == GumpSDK.LOGIN_REQUEST_CODE) {
  		if (resultCode == RESULT_OK) {
  			int uid = data.getIntExtra("userId", -1);
  			int accountType = data.getIntExtra("accountType", -1);
  			String sessionkey = data.getStringExtra("sessionKey");
b58707f79   赵康   init
125
  				
04a9e9502   赵康   完成格式编辑
126
127
  		} else if (resultCode == RESULT_CANCELED) {
  			Toast.makeText(this, "operate be canceled", Toast.LENGTH_SHORT).show();
b58707f79   赵康   init
128
  		}
04a9e9502   赵康   完成格式编辑
129
130
131
  	}
  	
  如上将收到成功登录用的userid,此Id标识唯一用户!      
b58707f79   赵康   init
132
  3.用户绑定邮箱,并填写密码
b58707f79   赵康   init
133

04a9e9502   赵康   完成格式编辑
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
      GumpSDK.boundMail(MainActivity.this);
  开发者需要在调用的Activity里重写onActivityResult方法以接受用户的绑定结果,通常如下:   
  
      //绑定邮箱请求返回结果
  	if (requestCode == GumpSDK.BOUND_REQUEST_CODE) {
  		if (resultCode == RESULT_OK) {
  			int uid = data.getIntExtra("userId", -1);
  			int accountType = data.getIntExtra("accountType", -1);
  			String sessionkey = data.getStringExtra("sessionKey");
  		} else if (resultCode == RESULT_CANCELED) {
  			Toast.makeText(this, "operate be canceled", Toast.LENGTH_SHORT).show();
  		}
      }
  4.支付功能      
  
  	Bundle payInfo = new Bundle();
  	payInfo.putString("nick", "thi");
  	payInfo.putString("product", "元宝");
  	payInfo.putFloat("amount", 40.0f);
  	payInfo.putString("extraInfo", "This is demo!");
  	GumpSDK.pay(MainActivity.this, payInfo);
  调用pay方法时,必须穿入一个bundle对象,包含如上字段,可以设置值为空,但是字段必须全部包含,支付完成仍然通过onActivityResult回调,requestCode为GumpSDK.PAY_REQUEST_CODE,回调信息除code和msg外,还含有orderId和传入的extraInfo.
  5.注销登录      
  
  	GumpSDK.logout(Activity,GumpSDK.Callback);
  当此方法调用后,用户退出登录,并会通过callback接口通知调用程序!
  ## 第二章 常见问题      
5817fcc88   赵康   增加链接
161
  ### 问题1: 如何避免混淆对SDK的影响?       
04a9e9502   赵康   完成格式编辑
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
  解答:有些开发者对接入了SDK的程序进行混淆时,有可能会覆盖某些java
  类,导致SDK无法正常工作,解决方法如下:      
  Ø  请开发者在混淆配置文件proguard.cfg或proguard-project.txt的最后加上       
  
      -keep class com.gumptech.sdk.GumpSDK{ 
      public static final <fields>;
      public static void init(java.lang.String,java.lang.String);
      public static void init(java.lang.String,java.lang.String,java.lang.String,java.lang.String);
      public static void start(android.app.Activity);
      public static void logout(android.app.Activity);
      public static void boundMail(android.app.Activity);
      }
      -keep class com.gumptech.sdk.view.* {*;}
      -keep class com.gumptech.sdk.GumpSDK$Callback{
      	void onLogout();
      }
      -keep class  com.gumptech.sdk.GumpPreference{
      public static final <fields>;
      }
      -keep class com.facebook.** { *; }
      
      -keepattributes Signature
  使得混淆的时候不会影响SDK的命名空间。