Android webview page not loading correctly

I am trying to load a page into a web application of an Android application using the Android Studio emulator (Nexus 5). However, the page does not load correctly and is stuck on the loading screen. GeoLocation permissions are required for this page, but I have already enabled them.

Below is my code and XML for the application.

MainActivity.java

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); WebView webview; setContentView(R.layout.activity_main); webview = (WebView)findViewById(R.id.help_webview); //webview use to call own site webview.setWebViewClient(new WebViewClient()); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setDomStorageEnabled(true); webview.getSettings().setAllowContentAccess(true); webview.getSettings().setAllowFileAccess(true); webview.getSettings().setAppCacheEnabled(true); webview.getSettings().setAllowUniversalAccessFromFileURLs(true); webview.getSettings().setAllowContentAccess(true); webview.getSettings().setGeolocationEnabled(true); webview.getSettings().setDatabaseEnabled(true); webview.setWebChromeClient(new WebChromeClient() { public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { // callback.invoke(String origin, boolean allow, boolean remember); callback.invoke(origin, true, false); } }); webview.loadUrl("https://lit-citadel-6989.herokuapp.com"); } 

activity_main.xml

 <WebView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/help_webview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="none" android:largeHeap="true" /> 

AndroidManifest.xml

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.example.example" > <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/> <uses-permission android:name="android.permission.ACCESS_GPS" /> <uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" /> <uses-permission android:name="android.permission.ACCESS_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 

UPDATE: This is a geolocation issue. I do not have a gps.config file. It seems I can’t find a specific way to create what I need for this. Javascript on website to get location,

 navigator.geolocation.getCurrentPosition(function(location){ setLatLng(location); locationLoaded = true; callback(lat,lng); }); 

How can I set up web browsing in android to transfer the user's current location?

+7
java android xml webview
source share
3 answers

There are other users using this approach, and it works great, the problem is that you are testing this on an emulator .. p>

To get a working GPS / Location API on the emulator, you can use the geo fix command.

You can use this GUI tool to easily set a fake GPS position on your emulator.

Detailed information on the geo fix command can be found here .

+5
source share

I implemented the onConsoleMessage method (in WebChromeClient ) to find out what was happening and got an error:

 @Override public boolean onConsoleMessage(android.webkit.ConsoleMessage consoleMessage) { Log("WebConsole: " + consoleMessage.message() + " [line:" + consoleMessage.lineNumber() + "]"); return true; } WebConsole: Uncaught SyntaxError: Unexpected token function [line:1] 
+3
source share

Make sure GPS is turned on for the emulator. There is another question with a good tutorial for this: How to emulate GPS location in Android emulator?

Hope this helps.

+1
source share

All Articles