title: Insufficient geolocation permissions
body: <p>I'm working on an Android Project. Basically, I'm trying to run WebView that displays Google Maps.</p>
  
  <p>I wanted to display my own location but when I press the button for this, I get exceptions like:</p>
  
  <pre><code>11-18 17:29:56.237 7678-7678/com.example.ali.bellsolution E/LocationProvider: Caught security exception while registering for location updates from the system. The application does not have sufficient geolocation permissions.
  11-18 17:29:56.257 7678-7678/com.example.ali.bellsolution E/LocationProvider: Caught security exception while registering for location updates from the system. The application does not have sufficient geolocation permissions.
  11-18 17:29:56.260 7678-7678/com.example.ali.bellsolution E/LocationProvider: Caught security exception while registering for location updates from the system. The application does not have sufficient geolocation permissions.
  </code></pre>
  
  <p>I have added these permissions to the manifest file:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/&gt;
  </code></pre>
  
  <p><strong>MainActivity.java:</strong></p>
  
  <pre><code>package com.example.ali.bellsolution;
  
  import android.Manifest;
  import android.app.Activity;
  import android.content.pm.PackageManager;
  import android.support.v4.app.ActivityCompat;
  import android.support.v4.content.ContextCompat;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.webkit.GeolocationPermissions;
  import android.webkit.WebChromeClient;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  
  public class MainActivity extends Activity {
  
      private static final int REQUEST_FINE_LOCATION = 0;
  
      WebView myWebView;
  
      String mapPath = "https://www.google.co.uk/maps/@51.5112044,-0.2712415,14z";
  
      /**
       * WebViewClient subclass loads all hyperlinks in the existing WebView
       */
      public class GeoWebViewClient extends WebViewClient {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
              // When user clicks a hyperlink, load in the existing WebView
              view.loadUrl(url);
              return true;
          }
      }
  
  
  
      /**
       * WebChromeClient subclass handles UI-related calls
       * Note: think chrome as in decoration, not the Chrome browser
       */
      public class GeoWebChromeClient extends WebChromeClient {
          @Override
          public void onGeolocationPermissionsShowPrompt(String origin,
                                                         GeolocationPermissions.Callback callback) {
              // Always grant permission since the app itself requires location
              // permission and the user has therefore already granted it
              callback.invoke(origin, true, false);
          }
      }
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
  
  
          super.onCreate(savedInstanceState);
  
          loadPermissions(Manifest.permission.ACCESS_COARSE_LOCATION, REQUEST_FINE_LOCATION);
  
          setContentView(R.layout.activity_main);
          myWebView = (WebView) this.findViewById(R.id.mapview);
  
  
          myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
          myWebView.getSettings().setBuiltInZoomControls(true);
          myWebView.setWebViewClient(new GeoWebViewClient());
  
  
  
          myWebView.getSettings().setJavaScriptEnabled(true);
          myWebView.getSettings().setGeolocationEnabled(true);
          myWebView.setWebChromeClient(new GeoWebChromeClient());
          myWebView.loadUrl(mapPath);
  
      }
  
      @Override
      public void onBackPressed() {
          // Pop the browser back stack or exit the activity
          if (myWebView.canGoBack()) {
              myWebView.goBack();
          }
          else {
              super.onBackPressed();
          }
      }
  
  
      private void loadPermissions(String perm, int requestCode) {
          if (ContextCompat.checkSelfPermission(this, perm) != PackageManager.PERMISSION_GRANTED) {
              if (!ActivityCompat.shouldShowRequestPermissionRationale(this, perm)) {
                  ActivityCompat.requestPermissions(this, new String[]{perm}, requestCode);
              }
          }
      }
  
  
  
  }
  </code></pre>
  
  <p><strong>Manifest:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.ali.bellsolution" &gt;
  
  
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="23" /&gt;
  
  
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/&gt;
  
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="WebViewApp"
          android:supportsRtl="true"
          android:theme="@style/AppTheme" &gt;
          &lt;activity android:name=".MainActivity"
                    android:label="WebViewApp"
              &gt;
  
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>