Android Webview页面未正确加载页面

app*_*her 7 java xml android webview

我正在尝试使用Android Studio模拟器(Nexus 5)将页面加载到Android应用程序webview中.但是,页面加载不正确并且卡在加载屏幕上.该页面确实需要GeoLocation权限,但我已经启用了它们.

下面是我的代码和应用程​​序的XML.

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");
}
Run Code Online (Sandbox Code Playgroud)

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" />
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

更新:这肯定是一个地理位置问题.我没有gps.config文件.我似乎无法找到一种具体的方法来创建一个或我需要的东西.获取位置的网站上的javascript是

navigator.geolocation.getCurrentPosition(function(location){
            setLatLng(location);
            locationLoaded = true;
            callback(lat,lng);
});
Run Code Online (Sandbox Code Playgroud)

我怎样才能在android中设置webview来传递用户的当前位置?

bon*_*nyz 5

其他用户使用这种方法,它工作正常,问题是你在模拟器上测试它.

为了在模拟器上获得有效的GPS/Location API,您可以使用该geo fix命令.

您可以使用此GUI工具轻松地在模拟器上设置假的GPS位置.

有关该geo fix命令的详细信息,请访问此处.