【问题标题】:cn1 - webview not workingcn1 - 网络视图不工作
【发布时间】:2016-02-23 17:41:12
【问题描述】:

在我的 cn1 应用程序中,我想要显示一些已经被格式化为 HTML 的内容,所以我认为只保留 WebView 而不是尝试解析它并为每个段落创建单独的 cn1 组件是最有意义的,等等

问题是我无法说服应用实际显示它。

这是我的代码:

WebBrowser web = new WebBrowser();
web.setURL(StateMachine.URL_PREFIX + "/api/article_body.php?articleId=" + (String)map.get("id"));
mac.findArticleBodyContainer(f).addComponent(BorderLayout.CENTER, web);
form.revalidate();

这是我在 Android 设备上打开应用程序时的 logcat 输出(运行 Marshmallow,之前使用 Lollipop 它也不起作用,但我没有其中的日志):

02-22 11:08:01.844 25899-25899/? W/AwContents: onDetachedFromWindow called when already detached. Ignoring
02-22 11:08:01.849 25899-25899/? W/ResourceType: No package identifier when getting value for resource number 0x00000000
02-22 11:08:02.188 25899-26296/? E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
02-22 11:08:02.408 25899-25899/? W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 25899
02-22 11:08:02.956 1786-1786/? W/AutostartServic: type=1400 audit(0.0:4802979): avc: denied { search } for name="26253" dev="proc" ino=2312770 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:r:kernel:s0 tclass=dir permissive=0
02-22 11:08:02.956 1786-1786/? W/AutostartServic: type=1400 audit(0.0:4802980): avc: denied { search } for name="26254" dev="proc" ino=2312771 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:r:kernel:s0 tclass=dir permissive=0
02-22 11:08:02.956 1786-1786/? W/AutostartServic: type=1400 audit(0.0:4802981): avc: denied { search } for name="26255" dev="proc" ino=2312772 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:r:kernel:s0 tclass=dir permissive=0
02-22 11:08:02.956 1786-1786/? W/AutostartServic: type=1400 audit(0.0:4802982): avc: denied { search } for name="26256" dev="proc" ino=2312773 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:r:kernel:s0 tclass=dir permissive=0
02-22 11:08:02.956 1786-1786/? W/AutostartServic: type=1400 audit(0.0:4802983): avc: denied { search } for name="26257" dev="proc" ino=2312774 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:r:kernel:s0 tclass=dir permissive=0
02-22 11:08:02.956 1786-1786/? W/AutostartServic: type=1400 audit(0.0:4802984): avc: denied { search } for name="26258" dev="proc" ino=2312775 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:r:kernel:s0 tclass=dir permissive=0
02-22 11:08:02.956 1786-1786/? W/AutostartServic: type=1400 audit(0.0:4802985): avc: denied { search } for name="26259" dev="proc" ino=2312776 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:r:kernel:s0 tclass=dir permissive=0
02-22 11:08:03.160 778-1444/? W/InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40f6863 attribute=null, token = android.os.BinderProxy@f97c335

我还没有在任何其他操作系统上尝试过,尽管我在另一台 Android 设备(也是 Marshmallow)上遇到了同样的问题。

注意This SO 问题有答案,但适用于原生 Android。我看不到以与 cn1 相同的方式访问 webview 设置的方法。

更新

我将 HTML 内容移至应用程序,并从本地文件加载它。我没有从模拟器中得到任何错误,但没有显示内容。在我的 Android 设备上,没有任何显示,这是 Logcat 的新输出:

02-23 10:22:28.426 16674-16674/? I/WebViewFactory: Loading com.google.android.webview version 47.0.2526.100 (code 252610000)
02-23 10:22:28.520 16674-16674/? I/cr_LibraryLoader: Time to load native libraries: 0 ms (timestamps 8908-8908)
02-23 10:22:28.520 16674-16674/? I/cr_LibraryLoader: Expected native library version number "47.0.2526.100", actual native library version number "47.0.2526.100"
02-23 10:22:28.546 16674-16674/? I/cr_LibraryLoader: Expected native library version number "47.0.2526.100", actual native library version number "47.0.2526.100"
02-23 10:22:28.546 16674-16674/? I/chromium: [INFO:library_loader_hooks.cc(122)] Chromium logging enabled: level = 0, default verbosity = 0
02-23 10:22:28.555 16674-16674/? I/cr_BrowserStartup: Initializing chromium process, singleProcess=true
02-23 10:22:28.558 16674-16674/? E/SysUtils: ApplicationContext is null in ApplicationStatus
02-23 10:22:28.615 16674-17002/? W/cr_media: Requires BLUETOOTH permission
02-23 10:22:28.643 16674-16674/? D/cr_Ime: [InputMethodManagerWrapper.java:27] Constructor
02-23 10:22:28.652 16674-16674/? D/cr_Ime: [ImeAdapter.java:241] attach
02-23 10:22:28.661 16674-16674/? W/AwContents: onDetachedFromWindow called when already detached. Ignoring
02-23 10:22:28.662 16674-16674/? D/cr_Ime: [InputMethodManagerWrapper.java:56] isActive: false
02-23 10:22:28.666 16674-16674/? W/ResourceType: No package identifier when getting value for resource number 0x00000000
02-23 10:22:28.728 16674-16674/? D/cr_Ime: [ImeAdapter.java:241] attach
02-23 10:22:28.766 16674-16674/? D/cr_Ime: [ImeAdapter.java:241] attach
02-23 10:22:28.824 16674-16674/? D/cr_Ime: [AdapterInputConnection.java:499] finishComposingText
02-23 10:22:28.827 16674-16674/? D/cr_Ime: [AdapterInputConnection.java:145] Constructor called with outAttrs: inputType=0xa1 imeOptions=0x12000000 privateImeOptions=null
                                           actionLabel=null actionId=0
                                           initialSelStart=0 initialSelEnd=0 initialCapsMode=0x0
                                           hintText=null label=null
                                           packageName=il.co.medonline.doctorapp fieldId=-1 fieldName=null
                                           extras=null
02-23 10:22:28.857 16674-16674/? D/cr_Ime: [AdapterInputConnection.java:308] getExtractedText
02-23 10:22:28.861 16674-16674/? D/cr_Ime: [AdapterInputConnection.java:542] setComposingRegion [0 0]
02-23 10:22:28.862 16674-16674/? D/cr_Ime: [AdapterInputConnection.java:499] finishComposingText
02-23 10:22:28.877 16674-17015/? E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
02-23 10:22:28.957 16674-16674/? W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 16674

同样存在两条不祥的线:validate_display:255 error 3008Cannot call determinedVisibility()。谷歌搜索这些似乎表明它们在应用程序没有更新某些安全措施以与 Android 5.0 及更高版本中使用的 Linux 内核兼容时出现,但可以通过在原生 Android WebView 上设置几个属性来轻松解决它们。 cn1 是否可以访问这些东西,还是我应该尝试使用原生组件?

【问题讨论】:

    标签: webview codenameone


    【解决方案1】:

    在下面的链接中提到了在代号中加载 webbrowser 的 3 种方法 Resources and Codename One

    【讨论】:

      【解决方案2】:

      浏览器是如何布局的?模拟器上能用吗?

      我看到您将它添加到边框布局,但如果您将该组件放置在没有显式增长组件的布局管理器中,那么这实际上并不重要。

      【讨论】:

      • 它在某些时候在模拟器中工作,从那时起我做了一些更改以尝试修复它,而我上面复制的当前代码在模拟器中也不起作用。我在模拟器和设备上看到的是一条穿过屏幕的 1 像素高的线,是 webview 背景的颜色,所以我知道它正在显示,但由于某种原因它只是空的。
      • webview被添加到一个边框布局的中心,在一个boxYLayout中,也就是form。这可能是问题的根源吗?
      • 这个答案应该是评论
      • 将 Web 浏览器放在表单的中心,而不是放在表单内的框中。这个答案是正确的答案,您可以理解为什么当您阅读开发人员指南codenameone.com/manual/basics.html 中的布局部分时,浏览器会请求 0 大小,因为数据尚未加载(HTML 异步加载)因此组件的大小为 0 . 将它放在 Box Y 中是不正确的。
      • 奇怪的是模拟器正在显示内容,即使在设备上它从未显示,你不觉得吗?
      【解决方案3】:

      我发现您还需要父容器/表单使用边框布局,仅此而已。我不知道为什么,但它似乎可以工作......

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多