如何从应用内订阅中获取订阅价格

How to get subscription price from in app subscription

我已经在 google 游戏控制台帐户中创建了月度订阅。

现在我想以编程方式根据我的设备区域获取订阅价格。

例如

如果我的设备所在地区是印度,那么我想要以印度货币表示的订阅价格

如果我的设备所在地区是瑞典,那么我需要以瑞典货币表示的订阅价格

我该怎么做?

请帮我解决这个问题。

在常规的应用内购买流程中,您查询 google 使用他们的 SKU(产品的唯一标识符。您自己设置)播放产品。此查询 returns 个完整的产品对象。这些对象包含本地价格。

我遇到了同样的问题,经过一些搜索和其他人的帮助,我已经解决了。

Google 为应用内购买提供区域价格设置。使用定价模板。只需按照以下步骤使用定价模板设置区域价格。

How to create template:

  1. 从左侧打开 google 游戏控制台和 select 设置 。 select定价模板之后。
  2. 点击顶部的新定价模板按钮。
  3. 添加您的姓名价格和select第二个选项。
  4. 现在在本地价格选项中根据您所在的地区明智地添加不同的价格。
  5. 点击底部的创建模板按钮后。

How to link this template with your Subscription SKU Id:

  1. 打开您的游戏机。 Select 您的应用->商店状态->应用内购买。
  2. Select 您的订阅项目已经创建或创建新的。
  3. 填写所有必填的相关信息。
  4. 现在,在 价格 部分,您可以看到带有下拉箭头的选项 从定价模板导入。点击它你可以看到你的创建模板。 Select 您的模板和价格将自动 link 与您的模板一起使用。

无模板selection:

在模板 selected 之后:

  1. 完成其他步骤并保存您的订阅项目后。

现在,每当用户请求有效订阅价格时,都会根据您已经根据您的模板设置的明智方式显示和使用 地区明智。我希望有人能得到帮助。

完成上述步骤后请按以下代码

private int REQ_FOR_QUERY_INVENTORY = 0;
    public static final int REQUEST_FOR_SKU_DETAIL = 1;
    public static final int REQUEST_FOR_CHECK_ACTIVE_SKU = 2;

private void updateSubscriptionPrice() {
        try {
            Log.i(TAG, "request for check Query inventory is active or not");
            REQ_FOR_QUERY_INVENTORY = REQUEST_FOR_SKU_DETAIL;
//            List<String> itemSku = new ArrayList<>();
            List<String> subSku = new ArrayList<>();
            subSku.add("subscription_id");
            subSku.add("subscription_id");
            mHelper.queryInventoryAsync(true, subSku, mQotInventoryListener);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
private IabHelper.QueryInventoryFinishedListener mQotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
    @Override
    public void onQueryInventoryFinished(IabResult result, Inventory inv) {
        try {
            Log.d(TAG, "mQotInventoryListener Query inventory finished.");
            handleQueryInventoryFinishResult(result, inv, REQ_FOR_QUERY_INVENTORY);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
};
private void handleQueryInventoryFinishResult(IabResult result, Inventory inventory, int requestForQueryInventory) {
        try {

            // Have we been disposed of in the meantime? If so, quit.
            if (mHelper == null) return;

            // Is it a failure?
            if (result.isFailure()) {
                Log.e(TAG, "mQotInventoryListener Failed to query inventory: " + result);
//                complain("Error purchasing: " + result);
//                billingCallBackListener.onError();
                return;
            }

            Log.d(TAG, "mQotInventoryListener Query inventory was successful.");

            switch (requestForQueryInventory) {
                case REQUEST_FOR_SKU_DETAIL:
                    try {
                        SkuDetails monthlySKU = inventory.getSkuDetails("subscription_id");
                        if (monthlySKU != null) {
                            String price = monthlySKU.getPrice();
                            Log.e(TAG, "SkuDetails are below......");
                            Log.i(TAG, "monthlySKU.getSku::->" + monthlySKU.getSku());
                            Log.i(TAG, "monthlySKU.getType::->" + monthlySKU.getType());
                            Log.i(TAG, "monthlySKU.getPrice: " + monthlySKU.getPrice());
                            Log.i(TAG, "monthlySKU.getPriceAmountMicros::->" + monthlySKU.getPrice());
//                            Log.i(TAG, "monthlySKU.getPriceCurrencyCode::->"+monthlySKU.get);
                            Log.i(TAG, "monthlySKU.getTitle::->" + monthlySKU.getTitle());
                            Log.i(TAG, "monthlySKU.getDescription::->" + monthlySKU.getDescription());
                            Log.i(TAG, "monthlySKU.getDescription::->" + monthlySKU.getDescription());
//                            String currencyCode = monthlySKU.getPriceCurrencyCode();
                            textview.setText(monthlySKU.getPrice().concat(" ").concat(getResources().getString(R.string.monthly_eur_1)));

                        } else {
                            Log.e(TAG, "monthlySKU details is null");
                        }

                        SkuDetails yearlySKU = inventory.getSkuDetails("subscription_id");
                        if (yearlySKU != null) {
                            String price = yearlySKU.getPrice();
                            Log.e(TAG, "yearly price : " + price);
                            textview.setText(price.concat(" ").concat(getResources().getString(R.string.yearly_eur_10)));
                        } else {
                            Log.e(TAG, "yearlySKU details is null");
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }