android - 如何从应用内订阅中获取订阅价格
问题描述
我在 google play 控制台帐户中创建了每月订阅。
现在我想以编程方式根据我的设备区域获取订阅价格。
例如
如果我的设备所在地区是印度,那么我想要印度货币的订阅价格
如果我的设备所在地区是瑞典,那么我想要瑞典货币的订阅价格
我怎样才能做到这一点??
请帮我解决一下这个。
解决方案
我遇到了同样的问题,经过一番搜索并在其他人的帮助下,我做到了。
谷歌为应用内购买提供区域明智的价格设置。使用定价模板。只需按照以下步骤使用定价模板设置区域明智的价格。
如何创建模板:
- 打开谷歌播放控制台并从左侧选择设置。选择定价模板后。
- 在顶部单击新定价模板按钮。
- 添加您的Name、Price并选择Tax第二个选项。
- 现在,在“本地价格”选项中根据您所在的地区添加不同的价格。
- 单击底部的CREATE TEMPLATE按钮后。
如何将此模板与您的订阅 SKU ID 链接:
- 打开您的游戏控制台。选择您的应用程序-> 商店存在-> 应用程序内购买。
- 选择已创建的订阅项目或创建新的。
- 填写所有必需的相关信息。
- 现在在“价格”部分,您可以看到带有下拉箭头的从定价模板导入的选项。单击它,您可以看到您的创建模板。选择您的模板,您的价格将自动与您的模板链接。
- 完成其他步骤并保存您的订阅项目后。
现在,每当用户请求主动订阅价格时,将根据您的模板明智地显示和使用,您已经根据您的地区明智地设置。我希望有人能得到帮助。
完成上述步骤后,请按照以下代码
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();
}
}
推荐阅读
- dart - 如何在 Dart 中将两个 4 位块转换为 1 个字节?
- c++ - 在 C++ 中将位串写入二进制文件
- static - 不同国家的github页面
- events - C#:确定下一次点击不在一个或多个确定位置时会发生什么
- javascript - 如何根据 AMP 中的下拉项目选择将用户重定向到唯一 URL?
- r - 如何使用 RMarkdown 从统计测试中获得更好的 Word 输出?
- python - 分组依据:对 2 个不同变量的条件和操作
- crm - Power Automate Flow:将 json 转换为可读的 PowerAutomate-Items
- javascript - 使用循环在 Django 模板中显示多个 Chart.js 图表
- html - 我想从网站嵌入 iframe 表