2016-09-16 74 views
1

我創建了一個尚未發佈的網站,因此我現在不會分享它。但它是一個使用PHP Framework Nette和Twitter Bootstrap作爲前端框架的網站。Android Working WebView 2016

我想創建簡單的Android和iOS應用程序。這兩個應用程序與webview。它在iOS上正常工作,但是,我無法在Android上開展工作。我瀏覽了很多類似的問題,但他們都沒有幫助我。

那麼,我究竟需要什麼?

  1. 地理位置訪問

  2. 顯示我的網站在網頁視圖

我的代碼:

package com.URL.URL; 

import android.app.Activity; 
import android.net.Uri; 
import android.os.Bundle; 
import android.view.Window; 
import android.webkit.GeolocationPermissions; 
import android.webkit.WebView; 
import android.webkit.WebViewClient; 
import android.webkit.WebChromeClient; 
import com.google.android.gms.appindexing.Action; 
import com.google.android.gms.appindexing.AppIndex; 
import com.google.android.gms.common.api.GoogleApiClient; 

public class MainActivity extends Activity { 

    /** 
    * ATTENTION: This was auto-generated to implement the App Indexing API. 
    * See https://g.co/AppIndexing/AndroidStudio for more information. 
    */ 


    private GoogleApiClient client; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.activity_main); 

     WebView view = (WebView) this.findViewById(R.id.webView); 


     view.getSettings().setDomStorageEnabled(true); 
     view.getSettings().setJavaScriptEnabled(true); 
     view.getSettings().setGeolocationEnabled(true); 
     view.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); 
     view.getSettings().setAppCacheEnabled(true); 
     view.getSettings().setDatabaseEnabled(true); 
     //view.getSettings().setUserAgentString("Mozilla/5.0 (Linux; U;`Android 2.0; en-us; Droid Build/ESD20) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17"); 



     view.setWebViewClient(new MyBrowser()); 
     view.setWebChromeClient(new WebChromeClient() { 
      public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { 
       callback.invoke(origin, true, false); 
      } 
     }); 

     view.loadUrl("https://www.URL.com"); 

     // ATTENTION: This was auto-generated to implement the App Indexing API. 
     // See https://g.co/AppIndexing/AndroidStudio for more information. 
     client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); 
    } 

    private class MyBrowser extends WebViewClient { 
     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      view.loadUrl(url); 
      return true; 
     } 
    } 

    @Override 
    public void onStart() { 
     super.onStart(); 

     // ATTENTION: This was auto-generated to implement the App Indexing API. 
     // See https://g.co/AppIndexing/AndroidStudio for more information. 
     client.connect(); 
     Action viewAction = Action.newAction(
       Action.TYPE_VIEW, // TODO: choose an action type. 
       "Main Page", // TODO: Define a title for the content shown. 
       // TODO: If you have web page content that matches this app activity's content, 
       // make sure this auto-generated web page URL is correct. 
       // Otherwise, set the URL to null. 
       Uri.parse("http://host/path"), 
       // TODO: Make sure this auto-generated app URL is correct. 
       Uri.parse("android-app://com.URL.URL/http/host/path") 
     ); 
     AppIndex.AppIndexApi.start(client, viewAction); 
    } 

    @Override 
    public void onStop() { 
     super.onStop(); 

     // ATTENTION: This was auto-generated to implement the App Indexing API. 
     // See https://g.co/AppIndexing/AndroidStudio for more information. 
     Action viewAction = Action.newAction(
       Action.TYPE_VIEW, // TODO: choose an action type. 
       "Main Page", // TODO: Define a title for the content shown. 
       // TODO: If you have web page content that matches this app activity's content, 
       // make sure this auto-generated web page URL is correct. 
       // Otherwise, set the URL to null. 
       Uri.parse("http://host/path"), 
       // TODO: Make sure this auto-generated app URL is correct. 
       Uri.parse("android-app://com.URL.URL/http/host/path") 
     ); 
     AppIndex.AppIndexApi.end(client, viewAction); 
     client.disconnect(); 
    } 
} 

這時候我的Android模擬器(4.4試過沒有工作, 5.1,6,7),但它工作時,我在我的舊三星下載Android版本4.4.4。

我不知道我的網站是否沒有問題,因爲當我嘗試加載google.com時,它工作正常..但即使當我在我的菜單中輸入字符串「aaa」並試圖在webview中打開它,它不起作用。我在網頁視圖和瀏覽器的網站

截圖:

WebView

Web Browser

我還想添加地理位置訪問彈出窗口。

所有這些都適用於iOS,但我真的不知道如何在Android上執行此操作。我主要是Web開發人員,所以請原諒我亂碼的Android代碼,這實際上是我第一次使用Android Studio。感謝您的任何幫助!

PS:我想在應用程序中打開它,而不是作爲新的瀏覽器選項卡。

錯誤:

09-16 15:01:01.578 2390-2512/com.URL.URL E/libEGL: validate_display:99 error 3008 (EGL_BAD_DISPLAY) 
09-16 15:01:01.972 2390-2512/com.URL.URL E/chromium: [ERROR:gles2_cmd_decoder.cc(2167)] [GroupMarkerNotSet(crbug.com/242999)!:A08E32ECFE7F0000]GL ERROR :GL_INVALID_OPERATION : BackFramebuffer::Create: <- error from previous GL command 
09-16 15:01:06.059 2390-2390/com.URL.URL E/cr_LocationProvider: Caught security exception while registering for location updates from the system. The application does not have sufficient geolocation permissions. 

警告:

09-16 15:01:00.562 2390-2390/com.URL.URL W/System: ClassLoader referenced unknown path: /system/app/webview/lib/x86_64 
09-16 15:01:00.951 2390-2468/com.URL.URL W/cr_media: Requires BLUETOOTH permission 
09-16 15:01:01.116 2390-2390/com.URL.URL W/cr_AwContents: onDetachedFromWindow called when already detached. Ignoring 
09-16 15:01:01.353 2390-2390/com.URL.URL W/gralloc_ranchu: Gralloc pipe failed 
09-16 15:01:01.526 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread 
09-16 15:01:01.540 2390-2397/com.URL.URL W/art: Suspending all threads took: 9.484ms 
09-16 15:01:02.184 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread 
09-16 15:01:02.770 2390-2390/com.URL.URL W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2390 
09-16 15:01:02.933 2390-2390/com.URL.URL W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2390 
09-16 15:01:03.059 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread 
09-16 15:01:03.597 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread 
09-16 15:01:03.980 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread 
09-16 15:01:04.058 2390-2397/com.URL.URL W/art: Suspending all threads took: 26.284ms 
09-16 15:01:05.010 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread 
09-16 15:01:05.346 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread 
09-16 15:01:05.704 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread 
09-16 15:01:06.044 2390-2397/com.URL.URL W/art: Suspending all threads took: 10.006ms 
09-16 15:01:06.182 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread 
09-16 15:01:06.216 2390-2401/com.URL.URL W/art: Suspending all threads took: 8.273ms 
09-16 15:01:06.485 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread 
09-16 15:01:06.729 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread 
09-16 15:01:07.035 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread 
09-16 15:01:07.277 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread 
09-16 15:01:10.719 2390-2390/com.URL.URL W/art: Attempt to remove non-JNI local reference, dumping thread 

清單:

<uses-permission android:name="android.permission.INTERNET"/> 
    <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" /> 
+0

您是否也可以添加日誌以及日誌會告訴您爲什麼它失敗?同時希望您擁有清單文件中的所有權限 –

+0

Hello Amod,感謝您的回覆,我更新了錯誤信息,警告和清單權限。 – vohratom

+0

你可以嘗試添加引用這個鏈接http:// stackoverflow。com/questions/18372931/simple-webview-example-caught-security-exception –

回答

0

似乎與鉻 仿真器的硬件抽獎默認情況下,創建具有GPU關閉

嘗試在模擬器 中設置「gpu = on」選項,並在清單中添加「android:hardwareAccelerated =」true「

+0

你好湯姆,謝謝你的幫助。不幸的是,這仍然是一樣的結果。無論如何,我啓動的網站應用程序「正式」,所以我想創建Android應用程序的網站地址稱爲www.nearber.com。如果任何人都可以幫助我,我會更高興。謝謝! – vohratom