4

I'm developing an android application (webview). One of the functionalities is required for geolocation enabled in order to detect my current location in Google Map.

Manifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

MainActivity.java (part of the codes)

mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setGeolocationEnabled(true);  
mWebView.getSettings().setGeolocationDatabasePath(getApplicationContext().getFilesDir().getPath());
mWebView.setWebChromeClient(new GeoWebChromeClient());

public class GeoWebChromeClient extends WebChromeClient {
    @Override
    public void onGeolocationPermissionsShowPrompt(String origin,
                                                   GeolocationPermissions.Callback callback) {
        callback.invoke(origin, true, false);
    }
}

I have tested with Android 5.0 (Lollipop), the webview is working fine and Google Map can detect my current location. For Android 6.0, I'm getting an error from the logcat and the Google Map cannot detect my precise location.

> E/cr_LocationProvider: Caught security exception while registering for
> location updates from the system. The application does not have
> sufficient geolocation permissions.

Any help is much appreciated. Thanks.

  • Possible duplicate of [Android permission doesn't work even if I have declared it](http://stackoverflow.com/questions/32635704/android-permission-doesnt-work-even-if-i-have-declared-it) – Mike M. May 16 '16 at 10:00

0 Answers0