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

标签 android in-app-subscription

我已在 Google Play 控制台帐户中创建了按月订阅。

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

例如

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

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

我怎样才能做到这一点?

请帮我解决这个问题。

最佳答案

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

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

How to create template:

  1. 打开 Google Play 控制台并选择左侧的设置。选择定价模板后。
  2. 点击顶部的新定价模板按钮。
  3. 添加您的名称价格,然后选择税费第二个选项。
  4. 现在,根据您所在的地区,在本地价格选项中添加不同的价格。
  5. 点击底部的创建模板按钮后。

<强> Example of pricing template

How to link this template with your Subscription SKU Id:

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

没有模板选择: enter image description here

选择模板后: enter image description here

  • 完成其他步骤并保存您的订阅项目。
  • 现在,每当用户请求有效订阅价格时,都会根据您已经根据您的模板设置的模板显示并使用价格 区域明智。我希望有人能得到帮助。

    完成上述步骤后,请按照以下代码操作

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

    关于android - 如何从应用内订阅获取订阅价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58762429/

    相关文章:

    java - 无法访问自定义ActionBar的TextView

    android - AudioCache 堆大小溢出问题请求大小 : 1053184, 最大大小:1048576

    android - 广播接收器调用了两次

    ios - Apple 在应用程序中购买的正确方式,并在 Flutter 中免费试用

    ios - 为什么每次我向 Apple 请求 latest_receipt 对象都会改变?

    android - 在 Android 应用程序中实现应用程序内购买是否需要启用实时开发者通知?

    android - ViewHolder ImageView setVisibility 重复

    android - 使用计时器更新列表 UI

    Android 购买订阅和入门价

    Android Google Play 订阅无法自动续订