1

In my application, i have implement InAppBilling (V3) Feature...
if i Logged in *abc@gmail.com* account in Device A , then purchased item from my application , and then if i call getPurchase() method then it will return purchased item ..
if i Logged in Device B with same account it and if i call getPurchase() then it will not display the item which i already purchased in Device 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();
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Vaishali Sutariya
  • 5,093
  • 30
  • 32

1 Answers1

-1

Try this code

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
            }