6

I'm working on app that have content filtering based on user country. As far as I know, it's possible to get country on iOS via App Store. Are there any possibility to do this on Android through Google Play?

List of solutions, that are not acceptable:

  1. Locale: user might live in France, but have English locale, so this will not work.
  2. Telephony manager: what about tablets? Of if user went abroad and changed sim card?
  3. IP or geolocation: user might go abroad, so no filtering there.

My app has in-app-purchases, and I can get currency code in ISO 4217. But this this partial solution, what about Eurozone?

costello
  • 446
  • 7
  • 13
  • https://developers.google.com/maps/documentation/geocoding/start?csw=1#geocoding-request-and-response-latitudelongitude-lookup – IntelliJ Amiya May 23 '16 at 09:13
  • @IntelliJAmiya I can't use IP or geolocation. See #3 – costello May 23 '16 at 12:00
  • If you want to fetch information from the Google account, make a REST call to Google to read their profile. One of the fields in the profile is the location (I forget whether it's city or country). Authenticate via OAuth. This solution is independent of Android — works in an iOS app or a web app, too. – Kartick Vaddadi Aug 17 '16 at 13:38
  • I'm looking for the same feature, could you find any solution? – giopromolla Oct 18 '16 at 20:24

1 Answers1

-1

You can use a web service which will return the location based on the IP address of the user. Here's an example of one of the web service:

private class AsyncTaskClass extends AsyncTask<Void, JSONObject, JSONObject> {

        @Override
        protected JSONObject doInBackground(Void... params) {

            OkHttpClient client = new OkHttpClient();
            Request request = new Request.Builder()
                    .url("http://ip-api.com/json")
                    .build();

            try {
                Response response = client.newCall(request).execute();
                return new JSONObject(response.body().string());
            } catch (IOException | JSONException e) {
                e.printStackTrace();
                return null;
            }
        }

        @Override
        protected void onPostExecute(JSONObject data) {
            try {
                Log.i("Country", data.getString("country"));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
Prerak Sola
  • 9,517
  • 7
  • 36
  • 67