【发布时间】:2018-05-27 02:39:01
【问题描述】:
我来自这个话题:New activity not opening
应用程序现在可以正常工作,但用于显示课程的 WebView 不能正常工作。
//Argomento.java
import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class Argomento extends AppCompatActivity {
private ProgressDialog progDailog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_argomento);
String nomeDispensa = getIntent().getStringExtra("dispensa");
progDailog = ProgressDialog.show(this, "Loading","Please wait...", true);
progDailog.setCancelable(false);
WebView documentOpener = findViewById(R.id.documentOpener);
WebSettings webSettings = documentOpener.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
documentOpener.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
progDailog.show();
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, final String url) {
progDailog.dismiss();
}
});
documentOpener.loadUrl(nomeDispensa);
}
}
//activity_argomento.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.fabio.myschoolsyllabus.Argomento">
<WebView
android:id="@+id/documentOpener"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>
我认为我输入了正确的所有代码,但网页没有显示,Android Studio 向我返回此日志:
I/WebViewFactory: Loading com.android.chrome version 58.0.3029.125 (code
303012512)
I/cr_LibraryLoader: Time to load native libraries: 2 ms (timestamps 8632-
8634)
I/chromium: [INFO:library_loader_hooks.cc(140)] Chromium logging enabled:
level = 0, default verbosity = 0
I/cr_LibraryLoader: Expected native library version number "58.0.3029.125",
actual native library version number "58.0.3029.125"
W/cr_ChildProcLauncher: Create a new ChildConnectionAllocator with package
name = com.android.chrome, inSandbox = true
I/cr_BrowserStartup: Initializing chromium process, singleProcess=false
D/: HostConnection::get() New Host Connection established 0x89833d80, tid
7494
D/EGL_emulation: eglCreateContext: 0x98f1adc0: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0x98f1adc0: ver 2 0 (tinfo 0x98b68e20)
W/ResourceType: For resource 0x7f0a0030, entry index(48) is beyond type
entryCount(2)
Failure getting entry for 0x7f0a0030 (t=9 e=48) (error -75)
E/GooglePlayServicesUtil: The Google Play services resources were not found.
Check your project configuration to ensure that the resources are included.
W/cr_media: Requires BLUETOOTH permission
I/cr_LibraryLoader: Using linker:
org.chromium.base.library_loader.ModernLinker
I/zygote: Do partial code cache collection, code=30KB, data=43KB
I/zygote: After code cache collection, code=30KB, data=43KB
I/zygote: Increasing code cache capacity to 256KB
I/zygote: JIT allocated 71KB for compiled code of void
android.widget.TextView.<init>(android.content.Context,
android.util.AttributeSet, int, int)
Compiler allocated 4MB to compile void android.widget.TextView.<init>
(android.content.Context, android.util.AttributeSet, int, int)
D/EGL_emulation: eglMakeCurrent: 0x98f18360: ver 2 0 (tinfo 0x98ba9890)
D/: HostConnection::get() New Host Connection established 0x86094dc0, tid
7571
D/EGL_emulation: eglCreateContext: 0x8604b2c0: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0x8604b2c0: ver 2 0 (tinfo 0x86095170)
I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
W/cr_MediaCodecUtil: HW encoder for video/avc is not available on this
device.
W/cr_MediaCodecUtil: HW encoder for video/avc is not available on this
device.
E/chromium: [ERROR:gl_surface_egl.cc(264)] eglChooseConfig failed with error
EGL_SUCCESS
D/EGL_emulation: eglCreateContext: 0x8604bf80: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0x8604bf80: ver 2 0 (tinfo 0x86095170)
W/zygote: Attempt to remove non-JNI local reference, dumping thread
D/EGL_emulation: eglMakeCurrent: 0x98f18360: ver 2 0 (tinfo 0x98ba9890)
D/EGL_emulation: eglMakeCurrent: 0x98f18360: ver 2 0 (tinfo 0x98ba9890)
I/Choreographer: Skipped 63 frames! The application may be doing too much
work on its main thread.
D/EGL_emulation: eglMakeCurrent: 0x98f18360: ver 2 0 (tinfo 0x98ba9890)
I/zygote: Do full code cache collection, code=121KB, data=80KB
After code cache collection, code=117KB, data=55KB
D/EGL_emulation: eglMakeCurrent: 0x98f18360: ver 2 0 (tinfo 0x98ba9890)
I/chatty: uid=10085(u0_a85) RenderThread identical 1 line
D/EGL_emulation: eglMakeCurrent: 0x98f18360: ver 2 0 (tinfo 0x98ba9890)
W/zygote: Attempt to remove non-JNI local reference, dumping thread
D/EGL_emulation: eglMakeCurrent: 0x98f18360: ver 2 0 (tinfo 0x98ba9890)
W/zygote: Attempt to remove non-JNI local reference, dumping thread
编辑
我已经在 AndroidManifest.xml 中添加了 Internet 权限。
作为“nomeDispensa”值的 URL,为了测试 WebView,是我可以选择的最简单的网页:“www.google.it”。
【问题讨论】:
-
您是否将互联网权限添加到清单?
-
请告诉使用的url的值。
nomeDispensa. -
@masoudvali 我已经添加了互联网权限。
-
@greenapps
nomeDispensa的值只是一个 url。在这种情况下,为了测试这个 WebView 是否有效,我将 www.google.it 作为值。 -
我认为这行不通。您需要添加协议。