【问题标题】:Android InAppBilling, is there any possibility to detect getPurchased item from different device with same google accountAndroid InAppBilling,是否有可能从具有相同谷歌帐户的不同设备检测到 getPurchased 项目
【发布时间】:2014-10-10 09:58:39
【问题描述】:

在我的应用程序中,我实现了 InAppBilling (V3) 功能...
如果我在 Device A 中登录 *abc@gmail.com* 帐户,然后购买 我的应用程序中的项目,然后如果我调用getPurchase() 方法 然后它将退回购买的物品..
如果我登录 设备 B 使用相同的帐户,如果我致电getPurchase(),则不会 显示我在设备A中已经购买的商品..

private void checkownedItems() {
    try {
        Bundle ownedItems = mService.getPurchases(3, getPackageName(),"inapp", null);

        if (ownedItems.getInt("RESPONSE_CODE") == 0) {
            ArrayList < String > ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
            ArrayList < String > purchaseDataList = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
            ArrayList < String > signatureList = ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE");
            String continuationToken = ownedItems.getString("INAPP_CONTINUATION_TOKEN");

            if (purchaseDataList.size() > 0) {
                // Item(s) owned

                for (int i = 0; i < purchaseDataList.size(); ++i) {
                    String purchaseData = purchaseDataList.get(i);
                    //  String signature = signatureList.get(i); // Note
                    // signatures
                    // do not
                    // appear to
                    // work with
                    // android.test.purchased
                    // (silly
                    // google)
                    String sku = ownedSkus.get(i);

                    Log.e("----->>", purchaseData + " --- " + " --- " + sku);
                }
            } else {
                // Item(s) not owned

                Toast.makeText(this, "No any Item is purchased",
                Toast.LENGTH_SHORT).show();
            }
        } else {
            // Error checking owned items
        }
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

【问题讨论】:

  • 如果设备上设置的使用 google play 的主要 gmail 帐户相同,那么它将起作用。因此,当您执行 getPurchase() 时,您将返回购买项目的详细信息,并且您需要验证开发人员有效负载以确保项目的有效性。
  • 是的,我可以从 getPurchase() 获得购买的物品,但如果我使用不同的设备和同一个帐户,那么我不能
  • @Vaishali 我认为它包含安全场景,根据我的观点,您不能一次使用 2 台设备来执行此操作。
  • 我不会同时检查这两个...有可能在不同的时间进行吗?
  • @Vaishali 我认为它可能会起作用,但谷歌帐户必须在两个设备上相同。

标签: android in-app-purchase in-app-billing in-app


【解决方案1】:

试试这个代码

for (int i = 0; i < purchaseDataList.size(); ++i) {
                String purchaseData = purchaseDataList.get(i);
                // String signature = signatureList.get(i);

                JSONObject jo = new JSONObject(purchaseData);

                String skuId = jo.getString("productId");
                int purchaseState = -1;
                if (jo.getString("purchaseState").length() > 0) {
                    purchaseState = Integer.parseInt(jo
                            .getString("purchaseState"));
                } else {
                    purchaseState = -1;
                }
                System.out.println("skuId::" + skuId + " purchaseState"
                        + purchaseState);
                InApp.addPurchasedItem(rootContext, skuId, purchaseState);
                valueMap = new HashMap<String, String>();
                valueMap.put("productId", listOfProductId.get(i));
                valueMap.put("isProductPurchased", ""
                        + ((purchaseState == 0) ? "true" : "false"));
                hashListGotProudctList.add(valueMap);

                // do something with this purchase information
                // e.g. display the updated list of products owned by
                // user
            }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-21
    • 1970-01-01
    • 2015-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多