Android 应用内计费,inventory.getPurchase在与付款不同的设备上为空
在我的应用程序中,用户可以购买广告删除,我保留此项目(无消费)。所以我在我的主要活动中有一个片段,用于检查用户是否购买了该项目Android 应用内计费,inventory.getPurchase在与付款不同的设备上为空,android,in-app-billing,Android,In App Billing,在我的应用程序中,用户可以购买广告删除,我保留此项目(无消费)。所以我在我的主要活动中有一个片段,用于检查用户是否购买了该项目 public class BillingInventoryFragment extends Fragment { // Helper billing object private IabHelper mHelper; @Override public void onCreate(Bundle savedInstanceState) { super.onCre
public class BillingInventoryFragment extends Fragment {
// Helper billing object
private IabHelper mHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
initialiseBilling();
}
private void initialiseBilling() {
if (mHelper != null) {
return;
}
// Create the helper, passing it our context and the public key to verify signatures with
mHelper = new IabHelper(getActivity(), BillingUtils.getApplicationKey());
// Enable debug logging (for a production application, you should set this to false).
mHelper.enableDebugLogging(true);
// Start setup. This is asynchronous and the specified listener will be called once setup completes.
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
@Override
public void onIabSetupFinished(IabResult result) {
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null) {
return;
}
// Something went wrong
if (!result.isSuccess()) {
Log.e(getActivity().getApplicationInfo().name, "Problem setting up in-app billing: " + result.getMessage());
return;
}
// IAB is fully set up. Now, let's get an inventory of stuff we own.
mHelper.queryInventoryAsync(iabInventoryListener());
}
});
}
/**
* Listener that's called when we finish querying the items and subscriptions we own
*/
private IabHelper.QueryInventoryFinishedListener iabInventoryListener() {
return new IabHelper.QueryInventoryFinishedListener() {
@Override
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
// Have we been disposed of in the meantime? If so, quit.
if (mHelper == null) {
return;
}
// Something went wrong
if (!result.isSuccess()) {
Log.d(TAG, String.format("result not success, result = %s", result) );
return;
}
// Do your checks here...
// Do we have the premium upgrade?
Purchase purchasePro = inventory.getPurchase(BillingUtils.SKU_PRO); // Where BillingUtils.SKU_PRO is your product ID (eg. permanent.ad_removal)
Log.d(TAG, String.format("Purchase pro = %s", purchasePro));
BillingUtils.isPro = (purchasePro != null && BillingUtils.verifyDeveloperPayload(purchasePro));
// After checking inventory, re-jig stuff which the user can access now
// that we've determined what they've purchased
BillingUtils.initialiseStuff();
}
};
}
/**
* Very important!
*/
@Override
public void onDestroy() {
super.onDestroy();
if (mHelper != null) {
mHelper.dispose();
mHelper = null;
}
}
}
一切都在一台设备上工作,但当我在第二台设备上测试时:
inventory.getPurchase(BillingUtils.SKU_PRO);
返回null
当我再次尝试在第二台设备上购买物品时,我无法购买,因为我拥有它。如果您确定您成功购买了该物品。这可能与使用的
Gmail有关。
你应该在这两台设备上使用相同的
Gmail
,因为Google
正在使用设备上注册的Gmail
识别其用户。是的,我使用相同的Gmail帐户。这就是为什么当我再次尝试在第二台设备上购买物品时,我不能,因为我已经拥有它,谷歌也知道它。这是inAppBilling
V3查询购买物品的官方方式,我在订阅式购买中面临同样的问题。你是怎么解决的?你有解决办法吗?你有解决办法吗?同样的问题。你找到解决办法了吗?同样的问题。BillingClient.queryPurchases()的文档说明:获取在应用程序中购买的所有物品的购买详细信息。此方法使用Google Play Store应用程序的缓存,而无需启动网络请求。因此,这只是设备上的一个脱机呼叫。。