queryPurchases() 与 queryPurchaseHistoryAsync() 为了 'restore' 功能?
queryPurchases() vs queryPurchaseHistoryAsync() in order to 'restore' functionality?
我正在使用 Play Billing Library 来触发和管理购买,这反过来又解锁了应用内的额外功能。这部分正在工作。
但是,'restore'购买的最佳方式是什么。例如,购买了该应用程序的人购买了新的 phone。登录到 Play 商店,下载我的应用程序,然后发现正在显示 'upgrade' 的付款屏幕。 iOS 对此有一个特定的方法,但我不知道 Android。
我的想法是查询Play商店,确认该账号之前是否成功购买过该商品,如果是的话我会调用app内的本地升级功能。
看来有两种相似的方法。但是在这种情况下我应该使用哪一个呢?用户在哪里擦除 phone 或购买了新的?
queryPurchases()
?或者 queryPurchaseHistoryAsync()
?
根据文档 queryPurchases
使用 Play 商店应用程序缓存获取结果,而 queryPurchaseHistoryAsync
实际上检查购买 AP 以获取最近的购买。因此,在您的情况下,您应该检查 Async
方法。
queryPurchases
Get purchases details for all the items bought within your app. This method uses a cache of Google Play Store app without initiating a network request.
queryPurchaseHistoryAsync
Returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed.
此外,请务必查看文档。它建议Cache purchase details on your servers
。
https://developer.android.com/google/play/developer-api.html#practices
你应该使用 queryPurchases
。这将为您提供每个 SKU 的所有当前活动(non-consumed、non-cancelled、non-expired)购买。
queryPurchaseHistoryAsync
不会满足您的需求,因为它只会为您提供每个 SKU 最近 购买的列表。它们可能已经过期、被取消或被消耗掉,而且无法判断。因此,此响应不能用于告知要在您的应用中应用哪些购买。
据我所知,queryPurchaseHistoryAsync
的唯一有效用途是向用户提供他们的购买历史记录列表。有点古怪。
另请注意:queryPurchases
是同步的,因此在大多数情况下它需要在某种后台工作线程中是 运行。我 运行 我在 AsyncTask
.
我知道有点晚了,但这是我自己发现的。分享我的答案让其他人受益。
所以我了解到 queryPurchases()
在您的设备上本地缓存,但在您调用 queryPurchaseHistoryAsync()
时更新
我从这个 Whosebug 答案中发现 here
所以我的解决方案是,当我想在新设备上恢复购买或重新安装我的应用程序时。调用 queryPurchaseHistoryAsync()
然后在回调 onPurchaseHistoryResponse()
中调用 queryPurchases()
并在 PurchasesResult
的 List<Purchase>
内查看用户过去购买的任何购买状态。
如果有预期购买,您的应用可以授予他们过去购买的权利。
已针对 BillingClient 的最新版本更新了文档。 queryPurchases()
已弃用。另请注意,queryPurchases()
仅 returned 由当前设备进行的购买,因此该方法不会通知您的方案有新的擦除 phone。要获得准确的信息,请使用异步调用。
queryPurchasesAsync()
将为所提供的 sku 类型 return 所有活动订阅和未使用的 one-time Purchase
对象。它从本地播放服务缓存中获取购买,因此不能保证缓存将包含在您的“新phone”场景中从另一台设备购买的内容,并且不能保证缓存在您的“已擦除phone”场景。
queryPurchaseHistoryAsync()
将为每个与提供的 sku 类型匹配的 sku 发出网络请求和 return 最近的 PurchaseHistory
对象,即使已取消或使用也是如此。
另外,为您现在知道要购买的 sku 使用适当的 BillingFlowParams and BillingFlowParams.SubscriptionUpdateParams 执行升级调用 launchBillingFlow()
。
我正在使用 Play Billing Library 来触发和管理购买,这反过来又解锁了应用内的额外功能。这部分正在工作。
但是,'restore'购买的最佳方式是什么。例如,购买了该应用程序的人购买了新的 phone。登录到 Play 商店,下载我的应用程序,然后发现正在显示 'upgrade' 的付款屏幕。 iOS 对此有一个特定的方法,但我不知道 Android。
我的想法是查询Play商店,确认该账号之前是否成功购买过该商品,如果是的话我会调用app内的本地升级功能。
看来有两种相似的方法。但是在这种情况下我应该使用哪一个呢?用户在哪里擦除 phone 或购买了新的?
queryPurchases()
?或者 queryPurchaseHistoryAsync()
?
根据文档 queryPurchases
使用 Play 商店应用程序缓存获取结果,而 queryPurchaseHistoryAsync
实际上检查购买 AP 以获取最近的购买。因此,在您的情况下,您应该检查 Async
方法。
queryPurchases
Get purchases details for all the items bought within your app. This method uses a cache of Google Play Store app without initiating a network request.
queryPurchaseHistoryAsync
Returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed.
此外,请务必查看文档。它建议Cache purchase details on your servers
。
https://developer.android.com/google/play/developer-api.html#practices
你应该使用 queryPurchases
。这将为您提供每个 SKU 的所有当前活动(non-consumed、non-cancelled、non-expired)购买。
queryPurchaseHistoryAsync
不会满足您的需求,因为它只会为您提供每个 SKU 最近 购买的列表。它们可能已经过期、被取消或被消耗掉,而且无法判断。因此,此响应不能用于告知要在您的应用中应用哪些购买。
据我所知,queryPurchaseHistoryAsync
的唯一有效用途是向用户提供他们的购买历史记录列表。有点古怪。
另请注意:queryPurchases
是同步的,因此在大多数情况下它需要在某种后台工作线程中是 运行。我 运行 我在 AsyncTask
.
我知道有点晚了,但这是我自己发现的。分享我的答案让其他人受益。
所以我了解到 queryPurchases()
在您的设备上本地缓存,但在您调用 queryPurchaseHistoryAsync()
我从这个 Whosebug 答案中发现 here
所以我的解决方案是,当我想在新设备上恢复购买或重新安装我的应用程序时。调用 queryPurchaseHistoryAsync()
然后在回调 onPurchaseHistoryResponse()
中调用 queryPurchases()
并在 PurchasesResult
的 List<Purchase>
内查看用户过去购买的任何购买状态。
如果有预期购买,您的应用可以授予他们过去购买的权利。
已针对 BillingClient 的最新版本更新了文档。 queryPurchases()
已弃用。另请注意,queryPurchases()
仅 returned 由当前设备进行的购买,因此该方法不会通知您的方案有新的擦除 phone。要获得准确的信息,请使用异步调用。
queryPurchasesAsync()
将为所提供的 sku 类型 return 所有活动订阅和未使用的 one-time Purchase
对象。它从本地播放服务缓存中获取购买,因此不能保证缓存将包含在您的“新phone”场景中从另一台设备购买的内容,并且不能保证缓存在您的“已擦除phone”场景。
queryPurchaseHistoryAsync()
将为每个与提供的 sku 类型匹配的 sku 发出网络请求和 return 最近的 PurchaseHistory
对象,即使已取消或使用也是如此。
另外,为您现在知道要购买的 sku 使用适当的 BillingFlowParams and BillingFlowParams.SubscriptionUpdateParams 执行升级调用 launchBillingFlow()
。