安卓使用谷歌钱包步骤
之前整理的,放本地很容易丢..... 故上传。大牛勿喷
1、安装google paly service SDK (使用SDK Manager.exe)
2、在项目中导入google paly service的api,并在androidmanifest 内添加<meta-dataandroid:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
3、创建proguard异常(原文:To prevent ProGuard from stripping away required classes, add the following lines in the <project_directory>/proguard-project.txt file:)
在PROGUARD-project.txt加入
-keep class * extends java.util.ListResourceBundle { protected Object[][] getContents();}-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable { publicstatic final ***NULL;}-keepnames @com.google.android.gms.common.annotation.KeepName class *-keepclassmembernames class * { @ccom.google.android.gms.common.annotation.KeepName *;}-keepnames class *implements android.os.Parcelable { public static final ** CREATOR;}
以上步骤就把google paly service 装完全了,接下来可以直接调用,具体调用方法如下:
这是运行一个demo(google wallet)
https://developers.google.com/commerce/wallet/instant-buy/android/quickstart#next_steps
这是api帮助文档
https://developers.google.com/commerce/wallet/instant-buy/android/reference/packages
这个就是把google wallet服务放到自己的项目中
https://developers.google.com/commerce/wallet/instant-buy/android/tutorial
步骤:
1、下载google的图片,必须要用的,这个是其中一个
<ImageButton xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="48dp" android:minWidth="200dp" android:background="@drawable/wallet_button_background" android:contentDescription="@string/wallet_buy_with_google_wallet" android:src="@drawable/wallet_button_buy_with_foreground" />
这个属性非常重要一定要的android:minWidth="200dp" google规定的,不然无法通过审核
2、初始化wallet client
@Override
Public void onCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
...
mWalletClient = new WalletClient(mActivity, environment, accountName, WalletConstants.THEME_HOLO_LIGHT, connectionCallbackListener,
connectionFailedListener);
...
}
@Override
public void onStart(){
super.onStart();
mWalletClient.connect();
}
new WalletClient(
mActivity, environment, accountName, WalletConstants.THEME_HOLO_LIGHT, connectionCallbackListener, connectionFailedListener);
参数详解:
mActivity 我的理解,这里可以填写this
Environment 这里只能填写两个值的其中一个:WalletConstants.ENVIRONMENT_PRODUCTION 、 WalletConstants.ENVIRONMENT_SANDBOX
官方建议,测试的时候填写 WalletConstants.ENVIRONMENT_SANDBOX
这是api的解释,没看懂
accountName :这里写的是google账户的邮箱
WalletConstants.THEME_HOLO_LIGHT
解释:Theme constant passed to the constructor of WalletClient to use Holo Light theme for Wallet on Android OS withSDK_INT >= HONEYCOMB.
看不懂
connectionCallbackListener: 这个是实现了 com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks这个接口的类的实例,直接new ConnectionCallbacks()就ok了
Android calls the methods of this object to notify the app when it connects and disconnects with Google Play Services.
这个是通知app什么时候链接(断开链接)google play service
connectionFailedListener: 这是实现了 com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener这个接口的类的实例,直接new 就行了
https://developers.google.com/commerce/wallet/instant-buy/android/tutorial
上一篇: 开发谷歌插件(三)
下一篇: 谷歌钱包:对中国的启示