首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法购买物品回应:7:已拥有的物品

问无法购买物品回应:7:已拥有的物品
EN

Stack Overflow用户
提问于 2016-02-17 06:09:41
回答 2查看 4.1K关注 0票数 1

我正在测试我的Android应用程序,并面对“无法购买的项目(回复:7:项目已经拥有)”。该项目是“托管应用程序中的产品”类型。我做了一些研究,发现这个(http://developer.android.com/google/play/billing/api.html#managed):

代码语言:javascript
复制
Managed in-app products are items that have their ownership information tracked and managed
by Google Play. When a user purchases a managed in-app item, Google Play stores the
purchase information for each item on a per-user basis. This enables you to later query
Google Play at any time to restore the state of the items a specific user has purchased.
This information is persistent on the Google Play servers even if the user uninstalls the
application or if they change devices.

If you are using the Version 3 API, you can also consume managed items within your
application. You would typically implement consumption for items that can be purchased
multiple times (such as in-game currency, fuel, or magic spells). Once purchased, a managed
item cannot be purchased again until you consume the item, by sending a consumption request
to Google Play. To learn more about in-app product consumption, see Consuming Items.

...

You can use the consumption mechanism to track the user's ownership of in-app products.

In Version 3, all in-app products are managed. This means that the user's ownership of all
in-app item purchases is maintained by Google Play, and your application can query the
user's purchase information when needed. When the user successfully purchases an in-app
product, that purchase is recorded in Google Play. Once an in-app product is purchased, it
is considered to be "owned". In-app products in the "owned" state cannot be purchased from
Google Play. You must send a consumption request for the "owned" in-app product before
Google Play makes it available for purchase again. Consuming the in-app product reverts it
to the "unowned" state, and discards the previous purchase data.

我怎样才能在代号为“发送消费请求”?

EN

回答 2

Stack Overflow用户

发布于 2016-02-17 08:49:42

假设你使用的是谷歌在安卓SDK中提供的IabHelper.java。以下是这条道路:

代码语言:javascript
复制
Android_SDK\sdk\extras\google\play_billing\samples\TrivialDrive\src\com\example\android\trivialdrivesample\util

下面是初始化应用程序计费、查询google播放的用户购买和消费的代码。

  1. 初始化应用程序中的计费。 /* base64EncodedPublicKey应该是应用程序的公钥(从Google控制台获得)。*/ IabHelper mHelper =新IabHelper(this,base64EncodedPublicKey);//检查应用程序内计费是否支持。支持mHelper.startSetup(新的IabHelper.OnIabSetupFinishedListener() {@覆盖公共无效onIabSetupFinished(IabResult结果)){ if (result.isSuccess()) { // app内计费。现在,queryInventoryAsync将用户是否已经购买。ArrayList productIDs =新的ArrayList();// ITEM_SKU ->名称: google console productIDs.add(ITEM_SKU);mHelper.queryInventoryAsync(true,productIDs,mReceivedInventoryListener);}->{ // ->不受设备}}支持;
  2. 查询用户的购买 mReceivedInventoryListener =新的IabHelper.QueryInventoryFinishedListener() {公开无效的onQueryInventoryFinished(IabResult结果,库存){ if (result.isSuccess()) { //,如果已经购买了布尔值hasPurchase =inventory.hasPurchase(ITEM_SKU),则为真;//在这里启用或禁用您的应用程序特性. /*如何消费采购*/首先,从库存购买获得购买= inventory.getPurchase(ITEM_SKU);//消费购买mHelper.consumeAsync(购买,mConsumeFinishedListener);}{ //未能查询google是否购买。};
  3. 购买消耗的侦听器 mConsumeFinishedListener =新的IabHelper.OnConsumeFinishedListener() {@覆盖公共无效onConsumeFinished(购买购买,IabResult结果){ if (result.isSuccess()) { //已消费。}{ //购买未消耗。};
票数 3
EN

Stack Overflow用户

发布于 2016-02-17 15:40:37

使用

代码语言:javascript
复制
Purchase.getInAppPurchase().wasPurchased(String sku)

如果该项目是托管项目,并且已经购买,它将返回true。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35449142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档