I have created monthly subscription in google play console account.
Now I want to get subscription price according to my device region programmatically.
For example
If my device's region is India then I want subscription price in Indian currency
If my device's region is Sweden then I want subscription price in Sweden currency
How can I do that??
Please help me with this.
I have facing this same issue and after some search and with some other persons help I have done it.
Google provide region wise price setting for In-app purchase. Use pricing template. Just follow below steps to set region wise price using pricing template.
How to create template:
How to link this template with your Subscription SKU Id:
Now whenever user make request for active subscription price will be shows and used as per your template wise which you have already set as per your region wise. I hope some one will get help.
After follow above step please follow below code
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();
}
}