title: How can I get a user's country location?
body: <p>Due to <a href="https://en.wikipedia.org/wiki/General_Data_Protection_Regulation" rel="noreferrer">GDPR</a>, I am requiring to check the user's location - whether the user is from the European Union. Till now I have found these solutions -</p>
  <ol>
  <li><p><a href="https://stackoverflow.com/a/11293706/9155610">Get Country using the Phone's language configuration</a> (<strong>can misguide if the user uses English US version even though he might be from some other country</strong>).</p>
  <pre><code> String locale = context.getResources().getConfiguration().locale.getCountry();
  </code></pre>
  </li>
  <li><p><a href="https://stackoverflow.com/a/17043834/9155610">Get Location using the GPS</a> (<strong>requires the <em>location coarse</em> permission which I do not want to add especially because of Android 6.0+ runtime permissions</strong>).</p>
  <pre><code> private void getCountryCode(final Location location) {
       Helper.log(TAG, &quot;getCountryCode&quot;);
  
       AsyncTask&lt;Void, Void, String&gt; countryCodeTask = new AsyncTask&lt;Void, Void, String&gt;() {
  
           final float latitude = (float) location.getLatitude();
           final float longitude = (float) location.getLongitude();
           // Helper.log(TAG, &quot;latitude: &quot; + latitude);
           List&lt;Address&gt; addresses = null;
           Geocoder gcd = new Geocoder(mContext);
           String code = null;
  
           @Override
           protected String doInBackground(Void... params) {
               try {
                   addresses = gcd.getFromLocation(latitude, longitude, 1);
                   code = addresses.get(0).getCountryCode();
               } 
               catch (IOException e) {
                   e.printStackTrace();
               }
               return code;
           }
  
           @Override
           protected void onPostExecute(String code) {
               Helper.log(TAG, &quot;onPostExecute&quot;);
               mCountryCodeListener.returnCountryCode(code);
           }
       };
  
       if (Build.VERSION.SDK_INT &lt;= Build.VERSION_CODES.GINGERBREAD_MR1) {
           countryCodeTask.execute();
       }
       else {
           countryCodeTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
       }
   }
  </code></pre>
  </li>
  <li><p><a href="https://stackoverflow.com/a/26356108/9155610">Get Location using the SIM card or Wi-Fi</a> (<strong>can not be used on tables without SIM card or Wi-Fi, whereas my app can be used on the device without an Internet connection or Wi-Fi</strong>).</p>
  <pre><code> TelephonyManager tm = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
   String countryCodeValue = tm.getNetworkCountryIso();
  </code></pre>
  </li>
  </ol>
  <p>Is it possible to find out the location of the user if the user is from European Union region or not?</p>
  <p>I do not need the exact location and even the country will work.</p>
  <p>Is there another method which might also require location permission (not the coarse location permission will also be helpful)?</p>
  <p><sub><em>Please note that this question is not a duplicate of any other question as my case is not being solved by any other question.</em></sub></p>