資源簡介
個人精品資源來的,公司也在用,已經是比較穩定的了。
里面已經帶有對應版本的API和Util工具類,所以下載直接就能使用。
這里使用的是v3版本的API,如果想要使用最新版本的 API請自行按照新的API函數稍微修改一下代碼參數就行了。
使用該封裝,只需要簡單的4步就能調起支付,參數等配置、new 一下,回調,注銷。
里面的接口功能齊全,具備完整的成功、失敗、錯誤回調。如果需要詳細教程,可以看我博客。http://blog.csdn.net/u013640004/article/details/78257536
1.0.3更新日志:增加對訂閱功能的支持。

代碼片段和文件信息
package?com.eyewind.puzzle.utils;
import?android.app.Activity;
import?android.content.Context;
import?android.content.Intent;
import?android.os.Bundle;
import?android.os.RemoteException;
import?com.android.vending.util.IabHelper;
import?com.android.vending.util.IabResult;
import?com.android.vending.util.Inventory;
import?com.android.vending.util.Purchase;
import?com.eyewind.framework.util.DeviceUtil;
import?java.util.ArrayList;
import?java.util.List;
/**
?*?Created?by?TJbaobao?on?2017/7/19.
?*/
public?class?GooglePlayUtil?{
????/*
????*?v1.0.1
????*?內購流程
????*?1、啟動并配置內購服務?startSetup
????*?2、確認內購服務啟動并配置完成,然后獲取商品信息(價格)?queryInventory
????*?(查詢商品的時候需要對商品進行消耗,以防止有的商品沒有消耗)
????*?3、發起購買行為?purchase
????*?(購買行為之后需要對商品進行消耗,否則無法進行下次購買,谷歌規定的,意圖是防止用戶二次誤買)
????*
????*?v1.0.2
????*?更新?針對iabHelper?dispose之后某些情況下出現IabHelper?was?disposed?of?so?it?cannot?be?used.錯誤的情況,做出了處理
????*
????*?v1.0.3
????*?增加?支持訂閱功能的使用
*?流程:
*?前面相同,發起訂閱的時候,調用purchaseSub,回調流程和內購一樣。
*?查詢訂閱當前用戶的訂閱狀態:getPurchasesSize,返回值:0沒有訂單,1有訂單,-1發生錯誤
????*/
????private?static?final?String?PUBLICKEY?=?“更變為自己的key“;
????private?static?final?String[]?ITEM_SKUS?=?new?String[]{“coins_leve1““coins_leve2““coins_leve3““coins_leve4“};//內支付的SKU
????private?static?final?String[]?SUBS_SKUS?=?new?String[]{“weekly““monthly““yearly“};//訂閱的SKU
????private?static?final?boolean?ENABLE_DEBUG?=?false;//是否Debug輸出日志模式
????private?static?final?String?LogTag?=?“MyDebug“;
????public?static?final?int?RC_REQUEST?=?10001;
????private?Context?context;
????private?IabHelper?iabHelper;
????private?OnQueryFinishedListener?onQueryFinishedListener;
????private?boolean?isStartSetup?=?false;
????private?onstartSetupFinishedListener?onstartSetupFinishedListener?;
????public?GooglePlayUtil(Context?context?OnQueryFinishedListener?onQueryFinishedListener)?{
????????this.context?=?context;
????????this.onQueryFinishedListener?=?onQueryFinishedListener;
????????iabHelper?=?new?IabHelper(contextPUBLICKEY);
????????iabHelper.enableDebugLogging(ENABLE_DEBUGLogTag);
????????startSetup();
????}
????/**
?????*?啟動并配置內購服務
?????*/
????private?void?startSetup()
????{
????????if(iabHelper!=null)
????????iabHelper.startSetup(new?MyOnIabSetupFinishedListener());
????}
????/**
?????*?配置內購服務接口
?????*/
????private?class?MyOnIabSetupFinishedListener?implements?IabHelper.OnIabSetupFinishedListener
????{
????????@Override
????????public?void?onIabSetupFinished(IabResult?result)?{
????????????if(result==null)
????????????{
????????????????if(onstartSetupFinishedListener!=null)
????????????????{
????????????????????onstartSetupFinishedListener.onSetupError();
????????????????}
????????????????return?;
????????????}
????????????if(result.isFailure())
????????????{
????????????????isStartSetup?=?false;
????????????????if(onstartSetupFinishedListener!=null)
????????????????{
????????????????????onstartSetupFinishedListener.onSetupFail(result);
???????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-07-29?19:19??googleplay\
?????目錄???????????0??2017-07-29?19:19??googleplay\aidl\
?????目錄???????????0??2017-07-29?19:19??googleplay\aidl\com\
?????目錄???????????0??2017-07-29?19:19??googleplay\aidl\com\android\
?????目錄???????????0??2017-07-29?19:19??googleplay\aidl\com\android\vending\
?????目錄???????????0??2017-07-29?19:19??googleplay\aidl\com\android\vending\billing\
?????文件???????11594??2016-09-13?18:46??googleplay\aidl\com\android\vending\billing\IInAppBillingService.aidl
?????文件???????13983??2017-10-27?17:06??googleplay\GooglePlayUtil.java
?????文件????????1782??2017-10-27?17:23??googleplay\readme.txt
?????目錄???????????0??2017-07-29?19:15??googleplay\utils\
?????文件???????24277??2017-07-25?15:48??googleplay\utils\ba
?????文件?????????984??2017-07-25?15:48??googleplay\utils\ba
?????文件????????2102??2017-07-25?15:48??googleplay\utils\IabBroadcastReceiver.java
?????文件????????1503??2017-07-25?15:48??googleplay\utils\IabException.java
?????文件???????51362??2017-10-27?15:42??googleplay\utils\IabHelper.java
?????文件????????1754??2017-07-25?15:48??googleplay\utils\IabResult.java
?????文件????????3437??2017-07-25?15:48??googleplay\utils\Inventory.java
?????文件????????2514??2017-07-25?15:48??googleplay\utils\Purchase.java
?????文件????????4993??2017-07-25?15:48??googleplay\utils\Security.java
?????文件????????2261??2017-07-25?15:48??googleplay\utils\SkuDetails.java
- 上一篇:send_mqtt.zip
- 下一篇:java項目需求文檔
評論
共有 條評論