I have a WebView that opens a URL that requires access to the user's location. It can determine the location when using Google Chrome outside the app, but in the app, it says I am not allowing the application to use location. Currently I have added
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
to my Manifest, and in my Class, I have:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webViewActivity);
WebView webView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient());
webSettings.setAllowUniversalAccessFromFileURLs(true);
webSettings.setDomStorageEnabled(true);
webSettings.setGeolocationEnabled(true)
Am I missing something? Thank you for your help.
You have to import
android.webkit.GeolocationPermissions.Callback
andandroid.webkit.WebChromeClient
just to Set the Geolocation permission state for the supplied origin by callingcallback.invoke(origin, true, false);
inonGeolocationPermissionsShowPrompt
method ofWebChromeClient
like belowCode
and you have to add 2 manifest permission's as
Hope it works.