在谷歌的IAB中,我可以在调用launchpurchaseflow方法之前获得产品名称和价格吗?

kev*_*inl 6 android in-app-purchase in-app-billing

我有一个程序设置一个警告对话框,询问"你想购买"TITLE"for"PRICE""

我知道Google IAB库有一个getSku()调用,但只有在购买该项目后才能使用.有没有办法在购买之前获得这两个变量?谢谢.

我可能已经看到一个查询一堆sku的项目,其中列出了所有项目,但我可能错了

kev*_*inl 1

为此找到了解决方案。首先,您需要 SKU/产品 ID。

public void getProductDetails(String sku) throws RemoteException, JSONException {
    logDebug("getProductDetails - " + sku);

    ArrayList<String>  skuList = new ArrayList<>();
    // Add the specific sku
    skuList.add(sku);

    if (sku != null) {
         Bundle querySkus = new Bundle();
         querySkus.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuList);
         Bundle skuDetails = mService.getSkuDetails(3, mContext.getPackageName(),  ITEM_TYPE_INAPP, querySkus);
         ArrayList<String> responseList = skuDetails.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST);

         for (String thisResponse : responseList) {
             SkuDetails d = new SkuDetails(thisResponse);
             logDebug("Looking at sku details: " + d);
             purchaseTitle = d.getTitle(); // these are set as variables so you can call them
             purchasePrice = d.getPrice(); // whenever you want
         }
    }
}
Run Code Online (Sandbox Code Playgroud)