首页 > 解决方案 > 如何从应用内订阅中获取订阅价格

问题描述

我在 google play 控制台帐户中创建了每月订阅。

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

例如

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

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

我怎样才能做到这一点??

请帮我解决一下这个。

标签: androidin-app-subscription

解决方案


我遇到了同样的问题,经过一番搜索并在其他人的帮助下,我做到了。

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

如何创建模板:

  1. 打开谷歌播放控制台并从左侧选择设置。选择定价模板后。
  2. 在顶部单击新定价模板按钮。
  3. 添加您的NamePrice并选择Tax第二个选项。
  4. 现在,在“本地价格”选项中根据您所在的地区添加不同的价格。
  5. 单击底部的CREATE TEMPLATE按钮后。

定价模板示例

如何将此模板与您的订阅 SKU ID 链接:

  1. 打开您的游戏控制台。选择您的应用程序-> 商店存在-> 应用程序内购买。
  2. 选择已创建的订阅项目或创建新的。
  3. 填写所有必需的相关信息。
  4. 现在在“价格”部分,您可以看到带有下拉箭头的从定价模板导入的选项。单击它,您可以看到您的创建模板。选择您的模板,您的价格将自动与您的模板链接。

没有模板选择: 在此处输入图像描述

选择模板后: 在此处输入图像描述

  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();
        }
    }

推荐阅读