| 87 | } |
| 88 | |
| 89 | public boolean isAvailable(String sku) throws RemoteException, JSONException { |
| 90 | // Get available SKUs |
| 91 | ArrayList<String> skuList = new ArrayList<>(); |
| 92 | skuList.add(sku); |
| 93 | Bundle query = new Bundle(); |
| 94 | query.putStringArrayList("ITEM_ID_LIST", skuList); |
| 95 | Bundle bundle = service.getSkuDetails(IAB_VERSION, context.getPackageName(), "inapp", query); |
| 96 | Log.i(TAG, "getSkuDetails"); |
| 97 | Util.logBundle(bundle); |
| 98 | int response = (bundle == null ? -1 : bundle.getInt("RESPONSE_CODE", -1)); |
| 99 | Log.i(TAG, "Response=" + getResult(response)); |
| 100 | if (response != 0) |
| 101 | throw new IllegalArgumentException(getResult(response)); |
| 102 | |
| 103 | // Check available SKUs |
| 104 | boolean found = false; |
| 105 | ArrayList<String> details = bundle.getStringArrayList("DETAILS_LIST"); |
| 106 | if (details != null) |
| 107 | for (String item : details) { |
| 108 | JSONObject object = new JSONObject(item); |
| 109 | if (sku.equals(object.getString("productId"))) { |
| 110 | found = true; |
| 111 | break; |
| 112 | } |
| 113 | } |
| 114 | Log.i(TAG, sku + "=" + found); |
| 115 | |
| 116 | return found; |
| 117 | } |
| 118 | |
| 119 | public void updatePurchases() throws RemoteException { |
| 120 | // Get purchases |