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?
java android xml webview
applecrusher
source share