android 使用google钱包 步骤

之前整理的,放本地很容易丢..... 故上传。大牛勿喷


1、安装google paly service SDK (使用SDK Manager.exe)

2、在项目中导入google paly serviceapi,并在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 装完全了,接下来可以直接调用,具体调用方法如下:

这是运行一个demogoogle 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


 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值