Android webview不会加载我的URL,但会加载其他URL。

时间:2022-09-04 08:09:50

I have a webiew app on android which loads some websites but not the one I need it to.

我在android上有一个webiew应用,它可以加载一些网站,但不是我需要的那个。

I have no idea if this is a problem with the website host or something I can do in my app. Basically I have an online portfolio I'm making for university and I want to make myself look better by building it into an app. The portfolio site includes a mobile version so it's already set up for that and works fine in the chrome browser on my phone.

我不知道如果这是一个问题的网站主机或东西我能做在我的应用程序。基本上,我有一个在线投资组合我大学,我想让自己看起来更好通过构建成一个应用程序。投资组合网站包括一个移动版本所以它已经建立和发挥的作用很好,在我的手机上的chrome浏览器。

It used to work with an old site and it loads google so I know I have the internet permission right. Not sure if it's something to do with my new site or I just need to change something to make it work.

它曾经和一个旧网站一起工作,它加载谷歌,所以我知道我有互联网权限。不确定这是否与我的新网站有关,或者我只是需要改变一些东西来让它工作。

In the chrome browser it looks as it should, which isn't good at the moment because I wanted to do this first before I added content to it. This is how it looks. (Can't post a screenshot directly as I don't have enough rep, sorry)

在chrome浏览器中,它看起来应该是这样的,现在还不太好,因为我想在添加内容之前先做这个。这就是它的样子。(因为我没有足够的代表,所以不能直接发布截图,抱歉)

Here is my main app code:

这是我的主要应用代码:

package com.broadbentstudios;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.parse.ParseAnalytics;

@SuppressLint("SetJavaScriptEnabled")
public class ParseStarterProjectActivity extends Activity {

    WebView webView;
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        webView = (WebView) findViewById(R.id.mainWebView);
        webView.setBackgroundColor(0x00000000);
        webView.setHorizontalScrollBarEnabled(false);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.loadUrl("http://www.broadbentstudios.com/");

        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url);
                return true;
            }                
        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webView!=null && webView.canGoBack()) {
            webView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }        
    {
        ParseAnalytics.trackAppOpenedInBackground(getIntent());
    }       
}

Screenshot of my site when using my app with the code above.

在使用我的应用程序和上面的代码时,我的网站截图。

Here is the logcat.

这是logcat。

04-12 18:51:45.686: D/PowerManagerService(1196): acquireWakeLockInternal: lock=903227323, flags=0x1, tag="LocationManagerService", ws=WorkSource{1000 com.qualcomm.location}, uid=1000, pid=1196
04-12 18:51:45.686: D/PowerManagerService(1196): acquireWakeLockInternal: lock=662236910, flags=0x1, tag="LocationManagerService", ws=WorkSource{10013 com.google.android.gms}, uid=1000, pid=1196
04-12 18:51:45.687: D/PowerManagerService(1196): acquireWakeLockInternal: lock=531027438, flags=0x1, tag="LocationManagerService", ws=WorkSource{10013 com.google.android.gms}, uid=1000, pid=1196
04-12 18:51:45.687: D/PowerManagerService(1196): releaseWakeLockInternal: lock=959227632 [LocationManagerService], flags=0x0
04-12 18:51:45.687: D/PowerManagerService(1196): releaseWakeLockInternal: lock=546372682 [LocationManagerService], flags=0x0
04-12 18:51:45.688: D/PowerManagerService(1196): releaseWakeLockInternal: lock=662236910 [LocationManagerService], flags=0x0
04-12 18:51:45.688: D/PowerManagerService(1196): releaseWakeLockInternal: lock=531027438 [LocationManagerService], flags=0x0
04-12 18:51:45.689: D/PowerManagerService(1196): releaseWakeLockInternal: lock=197382963 [LocationManagerService], flags=0x0
04-12 18:51:45.689: D/PowerManagerService(1196): releaseWakeLockInternal: lock=903227323 [LocationManagerService], flags=0x0
04-12 18:51:45.734: I/LibraryLoader(28664): Time to load native libraries: 34 ms (timestamps 2209-2243)
04-12 18:51:45.734: I/LibraryLoader(28664): Expected native library version number "",actual native library version number ""
04-12 18:51:45.747: V/WebViewChromiumFactoryProvider(28664): Binding Chromium to main looper Looper (main, tid 1) {24dd5d0b}
04-12 18:51:45.747: I/LibraryLoader(28664): Expected native library version number "",actual native library version number ""
04-12 18:51:45.747: I/chromium(28664): [INFO:library_loader_hooks.cc(108)] Chromium logging enabled: level = 0, default verbosity = 0
04-12 18:51:45.757: I/BrowserStartupController(28664): Initializing chromium process, singleProcess=true
04-12 18:51:45.758: W/art(28664): Attempt to remove local handle scope entry from IRT, ignoring
04-12 18:51:45.768: W/AudioManagerAndroid(28664): Requires BLUETOOTH permission
04-12 18:51:45.769: W/chromium(28664): [WARNING:resource_bundle.cc(304)] locale_file_path.empty()
04-12 18:51:45.770: I/chromium(28664): [INFO:aw_browser_main_parts.cc(63)] Load from apk succesful, fd=59 off=45928 len=3221
04-12 18:51:45.770: I/chromium(28664): [INFO:aw_browser_main_parts.cc(76)] Loading webviewchromium.pak from, fd:60 off:390788 len:1143511
04-12 18:51:45.775: D/libEGL(28664): loaded /vendor/lib/egl/libEGL_adreno.so
04-12 18:51:45.776: D/libEGL(28664): loaded /vendor/lib/egl/libGLESv1_CM_adreno.so
04-12 18:51:45.788: D/libEGL(28664): loaded /vendor/lib/egl/libGLESv2_adreno.so
04-12 18:51:45.803: I/Adreno-EGL(28664): <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.BF.1.1.1.C2.05.00.00.046.002_msm8974_LA.BF.1.1.1.C2__release_AU ()
04-12 18:51:45.803: I/Adreno-EGL(28664): OpenGL ES Shader Compiler Version: E031.25.03.00
04-12 18:51:45.803: I/Adreno-EGL(28664): Build Date: 01/06/15 Tue
04-12 18:51:45.803: I/Adreno-EGL(28664): Local Branch: mybranch6793908
04-12 18:51:45.803: I/Adreno-EGL(28664): Remote Branch: quic/LA.BF.1.1.1.c2
04-12 18:51:45.803: I/Adreno-EGL(28664): Local Patches: NONE
04-12 18:51:45.803: I/Adreno-EGL(28664): Reconstruct Branch: AU_LINUX_ANDROID_LA.BF.1.1.1.C2.05.00.00.046.002 +  NOTHING
04-12 18:51:45.868: W/chromium(28664): [WARNING:data_reduction_proxy_settings.cc(328)] SPDY proxy OFF at startup
04-12 18:51:45.890: W/art(28664): Attempt to remove local handle scope entry from IRT, ignoring
04-12 18:51:45.895: W/AwContents(28664): onDetachedFromWindow called when already detached. Ignoring
04-12 18:51:45.917: E/QCOMSysDaemon(28750): Can't open /dev/block/platform/msm_sdcc.1/by-name/bootselect: (No such file or directory)
04-12 18:51:45.917: I/QCOMSysDaemon(28750): Starting qcom system daemon
04-12 18:51:45.917: E/Diag_Lib(28750):  Diag_LSM_Init: Failed to open handle to diag driver, error = 2
04-12 18:51:45.917: E/QCOMSysDaemon(28750):  Diag_LSM_Init failed : 0
04-12 18:51:45.953: D/OpenGLRenderer(28664): Render dirty regions requested: true
04-12 18:51:45.956: D/Atlas(28664): Validating map...
04-12 18:51:45.962: E/com.parse.push(28664): successfully subscribed to the broadcast channel.
04-12 18:51:45.963: D/PowerManagerService(1196): acquireWakeLockInternal: lock=553909931, flags=0x1, tag="Intent { act=com.google.android.c2dm.intent.REGISTRATION flg=0x10 pkg=com.broadbentstudios cmp=com.broadbentstudios/com.parse.GcmBroadcastReceiver (has extras) }", ws=null, uid=10221, pid=28664
04-12 18:51:45.992: I/OpenGLRenderer(28664): Initialized EGL, version 1.4
04-12 18:51:45.997: D/OpenGLRenderer(28664): Enabling debug mode 0
04-12 18:51:46.009: D/PowerManagerService(1196): releaseWakeLockInternal: lock=553909931 [Intent { act=com.google.android.c2dm.intent.REGISTRATION flg=0x10 pkg=com.broadbentstudios cmp=com.broadbentstudios/com.parse.GcmBroadcastReceiver (has extras) }], flags=0x0
04-12 18:51:46.029: I/Timeline(28664): Timeline: Activity_idle id: android.os.BinderProxy@19326283 time:33412539
04-12 18:51:46.030: D/PowerManagerService(1196): releaseWakeLockInternal: lock=110279535 [ActivityManager-Launch], flags=0x0
04-12 18:51:46.038: I/ActivityManager(1196): Displayed com.broadbentstudios/.ParseStarterProjectActivity: +864ms
04-12 18:51:46.038: I/Timeline(1196): Timeline: Activity_windows_visible id: ActivityRecord{3eff1853 u0 com.broadbentstudios/.ParseStarterProjectActivity t1645} time:33412548
04-12 18:51:46.055: D/ForegroundUtils(4725): Foreground changed, PID: 4813 UID: 10182 foreground: false
04-12 18:51:46.055: D/ForegroundUtils(4725): Foreground UID/PID combinations:
04-12 18:51:46.055: D/ForegroundUtils(4725): UID: 10221 PID: 28664
04-12 18:51:46.386: D/AbstractMetricsFactoryImpl(28721): record : No data points in metrics event
04-12 18:51:46.637: W/BindingManager(28664): Cannot call determinedVisibility() - never saw a connection for the pid: 28664
04-12 18:51:47.134: I/chromium(28664): [INFO:CONSOLE(0)] "'webkitIDBRequest' is deprecated. Please use 'IDBRequest' instead.", source:  (0)
04-12 18:51:47.422: I/chromium(28664): [INFO:CONSOLE(1)] "HARD RESET!!", source: http://www.broadbentstudios.com/application/_output/pb.out.front.js?v=7 (1)
04-12 18:51:47.440: I/chromium(28664): [INFO:CONSOLE(1)] "Uncaught TypeError: Cannot read property 'clear' of null", source: http://www.broadbentstudios.com/application/_output/pb.out.front.js?v=7 (1)
04-12 18:51:48.338: D/audio_hw_primary(253): out_standby: enter: stream (0xb5801780) usecase(1: low-latency-playback)

Any help would be great, even if it's just so I know if it's my app or the site that is causing the problems.

任何帮助都是很好的,即使只是为了让我知道是我的应用还是网站导致了这些问题。

Thank you.

谢谢你!

3 个解决方案

#1


28  

Finally found the answer after a lot of searching. For anybody in a similar situation, as well as enabling javascript you also need to enable Dom storage by adding in;

经过大量的搜索,终于找到了答案。对于处于类似情况的任何人,除了启用javascript之外,还需要通过添加来启用Dom存储;

webView.getSettings().setDomStorageEnabled(true);

Change webView to whatever yours is called and you should be good to go.

将webView更改为您所调用的任何内容,您应该很好。

Hope this helps someone.

希望这可以帮助别人。

#2


0  

Your website has a JavaScript error. Did you try something about that error in the log you shared?

你的网站有一个JavaScript错误。你有没有在你共享的日志中尝试过这个错误?

Uncaught TypeError: Cannot read property 'clear' of null", source: http://www.broadbentstudios.com/application/_output/pb.out.front.js?v=7 (1)

未捕获的类型错误:无法读取属性'clear' of null,来源:http://www.broadbentstudios.com/application/_output/pb.out.front.js?v = 7(1)

#3


0  

I recently create one repository with a basic web view application for android with some error handling for no internet connection

我最近创建了一个存储库,其中包含一个基本的android web view应用程序,并在没有internet连接的情况下进行了一些错误处理

https://github.com/jgarciabt/SmartWebView

https://github.com/jgarciabt/SmartWebView

You can clone it and start your application from it, maybe that is easier.

您可以克隆它,然后从它开始应用程序,也许这更容易。

#1


28  

Finally found the answer after a lot of searching. For anybody in a similar situation, as well as enabling javascript you also need to enable Dom storage by adding in;

经过大量的搜索,终于找到了答案。对于处于类似情况的任何人,除了启用javascript之外,还需要通过添加来启用Dom存储;

webView.getSettings().setDomStorageEnabled(true);

Change webView to whatever yours is called and you should be good to go.

将webView更改为您所调用的任何内容,您应该很好。

Hope this helps someone.

希望这可以帮助别人。

#2


0  

Your website has a JavaScript error. Did you try something about that error in the log you shared?

你的网站有一个JavaScript错误。你有没有在你共享的日志中尝试过这个错误?

Uncaught TypeError: Cannot read property 'clear' of null", source: http://www.broadbentstudios.com/application/_output/pb.out.front.js?v=7 (1)

未捕获的类型错误:无法读取属性'clear' of null,来源:http://www.broadbentstudios.com/application/_output/pb.out.front.js?v = 7(1)

#3


0  

I recently create one repository with a basic web view application for android with some error handling for no internet connection

我最近创建了一个存储库,其中包含一个基本的android web view应用程序,并在没有internet连接的情况下进行了一些错误处理

https://github.com/jgarciabt/SmartWebView

https://github.com/jgarciabt/SmartWebView

You can clone it and start your application from it, maybe that is easier.

您可以克隆它,然后从它开始应用程序,也许这更容易。