【问题标题】:Problem with WebView, gets stuck in loadingWebView 出现问题,卡在加载中
【发布时间】:2020-05-23 06:28:40
【问题描述】:

我遇到了一个问题,我的页面卡在加载页面中,只是那个页面,我认为是因为它没有启用 javascript,然后添加它并添加了一堆其他代码,我可能不会需要,但它被丢弃了。

知道这会是什么问题吗?

import android.content.pm.ActivityInfo;
import android.os.Build;
import android.os.Bundle;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.webkit.GeolocationPermissions;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//Obtain the WebSettings object//
    WebSettings webSettings = browser.getSettings();

    browser.setWebChromeClient(new WebChromeClient() {
        public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
            // callback.invoke(String origin, boolean allow, boolean remember);
            callback.invoke(origin, true, false);
                                   }

                               });



browser.getSettings().setUseWideViewPort(true);
        browser.getSettings().setLoadWithOverviewMode(true);
        browser.getSettings().setDomStorageEnabled(true);
        browser.clearView();
        browser.setHorizontalScrollBarEnabled(false);
        browser.getSettings().setAppCacheEnabled(true);
        browser.getSettings().setDatabaseEnabled(true);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            browser.getSettings().setDatabasePath("/data/data/" + this.getPackageName() + "/databases/");
        }
        browser.setVerticalScrollBarEnabled(false);
        browser.getSettings().setBuiltInZoomControls(true);
        browser.getSettings().setDisplayZoomControls(false);
        browser.getSettings().setAllowFileAccess(true);
        browser.getSettings().setPluginState(WebSettings.PluginState.OFF);
        browser.setScrollbarFadingEnabled(false);
        browser.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        browser.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
        browser.setWebViewClient(new WebViewClient());
        browser.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
        browser.setInitialScale(1);


    browser.loadUrl("https://s167-es.ogame.gameforge.com/game/index.php?page=ingame&component=overview");
    Toast.makeText(this, "Loading... Wait, please...",
            Toast.LENGTH_LONG).show();
    browser.setWebViewClient(new WebViewClient() {
        // evita que los enlaces se abran fuera nuestra app en el navegador de android
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }

    });
}

}

然后在普通浏览器中应该会打开一个带有游戏的新标签页,它也使用 javascript 以防万一它很重要。

这是上一张图片中的源代码视图:(在 google chrome 中,但我的观点是,您可能会找到一些可以帮助您确定我在 webview 中是否缺少某些代码的东西什么的。

<!do ctype htm l><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=de vice-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><link rel="icon" href="/favicon.ico"><script type="text/javascript" src="/config/configuration.js"></script><title></title><link href="https://s3-static.geo.gfsrv.net/browsergamelobby/ogame/2.7.0/css/main.33ce9fb9.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><div class="planet"></div><script type="text/javascript" src="https://s3-static.geo.gfsrv.net/browsergamelobby/ogame/2.7.0/js/main.b0b4a5d3.js"></scri pt></body></html>

这是我的 LOGCAT2020-02-07 02:45:31.362 21035-21035/? I/me.serverOctan: Not late-enabling -Xcheck:jni (already on) 2020-02-07 02:45:31.377 21035-21035/? E/me.serverOctan: Unknown bits set in runtime_flags: 0x8000 2020-02-07 02:45:31.384 21035-21035/? W/me.serverOctan: Unexpected CPU variant for X86 using defaults: x86 2020-02-07 02:45:31.518 21035-21070/? D/libEGL: Emulator has host GPU support, qemu.gles is set to 1. 2020-02-07 02:45:31.520 21035-21070/? W/libc: Unable to set property "qemu.gles" to "1": connection failed; errno=13 (Permission denied) 2020-02-07 02:45:31.507 21035-21035/? W/RenderThread: type=1400 audit(0.0:124): avc: denied { write } for name="property_service" dev="tmpfs" ino=7421 scontext=u:r:untrusted_app:s0:c142,c256,c512,c768 tcontext=u:object_r:property_socket:s0 tclass=sock_file permissive=0 app=OGame.serverOctans 2020-02-07 02:45:31.532 21035-21070/? D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so 2020-02-07 02:45:31.535 21035-21070/? D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so 2020-02-07 02:45:31.537 21035-21070/? D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so 2020-02-07 02:45:31.614 21035-21035/? W/me.serverOctan: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed) 2020-02-07 02:45:31.614 21035-21035/? W/me.serverOctan: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed) 2020-02-07 02:45:31.623 21035-21035/? I/WebViewFactory: Loading com.google.android.webview version 74.0.3729.185 (code 373018518) 2020-02-07 02:45:31.626 21035-21035/? I/me.serverOctan: The ClassLoaderContext is a special shared library. 2020-02-07 02:45:31.629 21035-21035/? I/me.serverOctan: The ClassLoaderContext is a special shared library. 2020-02-07 02:45:31.660 21035-21035/? I/cr_LibraryLoader: Time to load native libraries: 4 ms (timestamps 5821-5825) 2020-02-07 02:45:31.673 21035-21035/? I/chromium: [INFO:library_loader_hooks.cc(50)] Chromium logging enabled: level = 0, default verbosity = 0 2020-02-07 02:45:31.673 21035-21035/? I/cr_LibraryLoader: Expected native library version number "74.0.3729.185", actual native library version number "74.0.3729.185" 2020-02-07 02:45:31.678 21035-21075/? W/cr_ChildProcLH: Create a new ChildConnectionAllocator with package name = com.google.android.webview, sandboxed = true 2020-02-07 02:45:31.683 21035-21075/? W/me.serverOctan: Accessing hidden method Landroid/content/Context;->bindServiceAsUser(Landroid/content/Intent;Landroid/content/ServiceConnection;ILandroid/os/Handler;Landroid/os/UserHandle;)Z (greylist, reflection, allowed) 2020-02-07 02:45:31.688 21035-21035/? I/cr_BrowserStartup: Initializing chromium process, singleProcess=false 2020-02-07 02:45:31.819 21035-21035/? W/me.serverOctan: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker;-><init>(Landroid/content/Context;I)V (greylist, reflection, allowed) 2020-02-07 02:45:31.819 21035-21035/? W/me.serverOctan: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker;->logEvent(Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;)V (greylist, reflection, allowed) 2020-02-07 02:45:31.819 21035-21035/? W/me.serverOctan: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionStarted(I)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (greylist, reflection, allowed) 2020-02-07 02:45:31.820 21035-21035/? W/me.serverOctan: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(II)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (greylist, reflection, allowed) 2020-02-07 02:45:31.820 21035-21035/? W/me.serverOctan: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(IILandroid/view/textclassifier/TextClassification;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (greylist, reflection, allowed) 2020-02-07 02:45:31.820 21035-21035/? W/me.serverOctan: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(IILandroid/view/textclassifier/TextSelection;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (greylist, reflection, allowed) 2020-02-07 02:45:31.820 21035-21035/? W/me.serverOctan: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionAction(III)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (greylist, reflection, allowed) 2020-02-07 02:45:31.820 21035-21035/? W/me.serverOctan: Accessing hidden method Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionAction(IIILandroid/view/textclassifier/TextClassification;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent; (greylist, reflection, allowed) 2020-02-07 02:45:31.851 21035-21111/? D/HostConnection: HostConnection::get() New Host Connection established 0xe1a3fd20, tid 21111 2020-02-07 02:45:31.858 21035-21111/? D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_1 2020-02-07 02:45:31.864 21035-21103/? W/cr_media: Requires BLUETOOTH permission 2020-02-07 02:45:31.887 21035-21111/? D/EGL_emulation: eglCreateContext: 0xe1a1baa0: maj 3 min 1 rcv 4 2020-02-07 02:45:31.890 21035-21111/? D/EGL_emulation: eglMakeCurrent: 0xe1a1baa0: ver 3 1 (tinfo 0xe1a0fec0) 2020-02-07 02:45:31.893 21035-21111/? E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da 2020-02-07 02:45:31.893 21035-21111/? E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da 2020-02-07 02:45:31.976 21035-21068/? D/HostConnection: HostConnection::get() New Host Connection established 0xde52daa0, tid 21068 2020-02-07 02:45:31.977 21035-21068/? D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_1 2020-02-07 02:45:31.977 21035-21068/? W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 2020-02-07 02:45:31.993 21035-21111/? I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es 2020-02-07 02:45:31.996 21035-21111/? W/cr_MediaCodecUtil: HW encoder for video/avc is not available on this device. 2020-02-07 02:45:32.011 21035-21068/? D/EGL_emulation: eglCreateContext: 0xebb10080: maj 3 min 1 rcv 4 2020-02-07 02:45:32.020 21035-21068/? D/EGL_emulation: eglMakeCurrent: 0xebb10080: ver 3 1 (tinfo 0xca674190) 2020-02-07 02:45:32.036 21035-21068/? E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da 2020-02-07 02:45:32.036 21035-21068/? E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da 2020-02-07 02:45:32.036 21035-21111/? D/EGL_emulation: eglCreateContext: 0xe1a1ca60: maj 3 min 0 rcv 3 2020-02-07 02:45:32.038 21035-21111/? D/EGL_emulation: eglMakeCurrent: 0xe1a1ca60: ver 3 0 (tinfo 0xe1a0fec0) 2020-02-07 02:45:32.050 21035-21111/? E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef 2020-02-07 02:45:32.050 21035-21111/? E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef 2020-02-07 02:45:32.079 21035-21068/? W/Gralloc3: mapper 3.x is not supported 2020-02-07 02:45:32.083 21035-21068/? D/HostConnection: createUnique: call 2020-02-07 02:45:32.084 21035-21068/? D/HostConnection: HostConnection::get() New Host Connection established 0xca9745b0, tid 21068 2020-02-07 02:45:32.085 21035-21068/? D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV420_888_to_NV21 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_1 2020-02-07 02:45:32.086 21035-21068/? D/eglCodecCommon: allocate: Ask for block of size 0x1000 2020-02-07 02:45:32.086 21035-21068/? D/eglCodecCommon: allocate: ioctl allocate returned offset 0x3ff740000 size 0x2000 2020-02-07 02:45:32.102 21035-21068/? D/EGL_emulation: eglMakeCurrent: 0xebb10080: ver 3 1 (tinfo 0xca674190) 2020-02-07 02:45:32.156 21035-21111/? E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef 2020-02-07 02:45:32.157 21035-21111/? E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef 2020-02-07 02:45:32.160 21035-21068/? D/EGL_emulation: eglMakeCurrent: 0xebb10080: ver 3 1 (tinfo 0xca674190) 2020-02-07 02:45:32.198 21035-21068/? D/EGL_emulation: eglMakeCurrent: 0xebb10080: ver 3 1 (tinfo 0xca674190) 2020-02-07 02:45:32.414 21035-21090/OGame.serverOctans D/NetworkSecurityConfig: No Network Security Config specified, using platform default 2020-02-07 02:45:34.074 21035-21068/OGame.serverOctans E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef 2020-02-07 02:45:34.074 21035-21068/OGame.serverOctans E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef 2020-02-07 02:45:34.643 21035-21111/OGame.serverOctans E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef 2020-02-07 02:45:34.646 21035-21111/OGame.serverOctans I/chatty: uid=10142(OGame.serverOctans) Chrome_InProcGp identical 2 lines 2020-02-07 02:45:34.646 21035-21111/OGame.serverOctans E/eglCodecCommon: glUtilsParamSize: unknow param 0x000088ef 2020-02-07 02:45:37.285 21035-21091/OGame.serverOctans W/chromium: [WARNING:spdy_session.cc(3232)] Received HEADERS for invalid stream 23

【问题讨论】:

    标签: javascript php android android-studio webview


    【解决方案1】:

    我认为问题与使用 JavaScript 完全动态创建的 URL 上的内容有关(如您在 HTML 源代码中所见),并且您尚未在 WebSettings 中启用 JavaScript。

    还有其他一些事情正在发生使您的代码难以阅读。

    你有这行:

    WebSettings webSettings = browser.getSettings();
    

    但是你这样做:

    browser.getSettings().setUseWideViewPort(true);
    

    可以写成:

    webSettings.setUseWideViewPort(true);
    

    至于这个问题,我相信下面这行可以解决加载问题:

    webSettings.setJavaScriptEnabled(true);
    

    就个人而言,我还会包括:

    webSettings.setLoadsImagesAutomatically(true);
    

    【讨论】:

    • 嘿,谢谢你的建议。关于这个问题,它仍然有同样的问题。是的,我相信就像你说的那样,如果你的意思是它在“点击正确的”之前通过一些 URL 重定向你。我认为问题在于大厅,因为您无法像以前那样直接登录游戏。游戏让你登录,然后即使你已经登录游戏,你也会被重定向到大厅,然后你需要按 PLAY 或“Jugar”才能转到我最初想去的链接。
    • 我刚刚意识到它卡在这个链接中:lobby.ogame.gameforge.com/es_ES/loading 您实际上可以在链接中看到它就像一个循环,而它确实加载了它必须去的真实网络。但是问题在于它在加载后没有正确重定向,或者实际上并没有真正加载网站,所以它可能无法重定向。我认为它必须是这两个选项之一。
    猜你喜欢
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 2020-05-07
    相关资源
    最近更新 更多