1

In my cn1 app I have some content I want to display that's already been formatted as HTML, so I figure it made the most sense to just stick in a WebView rather than try parsing it and creating individual cn1 components for each paragraph, etc.

The problem is that I can't convince the app to actually display it.

Here's my code:

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();

Here's the logcat output when I open the app on an Android device (running Marshmallow, previously with Lollipop it didn't work either, but I don't have the log from that):

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

I have yet to try it out on any other OS, although I get the same issue on another Android device (also Marshmallow).

Note: This SO question has an answer, but for native Android. I don't see a way to access the webview settings in the same way from cn1.

Update

I moved the HTML content to the app, and load it from the local file. I get no errors from the simulator, but no content shows. On my Android device, nothing shows, this is the new output from the 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

The same two ominous lines are present: validate_display:255 error 3008 and Cannot call determinedVisibility(). Googling these seems to indicate that they appear when an app hasn't updated certain security measures to be compatible with the Linux kernel used in Android 5.0 and up, but they can be easily solved by setting a couple of attributes on the native Android WebView. Does cn1 give access to these things, or should I try using a native component?

Community
  • 1
  • 1
ygesher
  • 1,133
  • 12
  • 26

3 Answers3

2

There are 3 ways of loading webbrowser in codenameone which is mentioned in below link Resources and Codename One

Community
  • 1
  • 1
tizbn
  • 1,907
  • 11
  • 16
0

How is the browser laid out? Does it work in the simulator?

I see that you added it to a border layout but if you placed that component within a layout manager that doesn't explicitly grow the component then this doesn't actually matter.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
  • It worked in the simulator at some point, since then I made some changes in order to try to fix it, and the current code which I copied above, doesn't work in the simulator either. What I do see, both in simulator and on device, is a one-pixel high line going across the screen, the color of the webview's background, so I know it is displaying, it's just empty for some reason. – ygesher Feb 23 '16 at 06:58
  • The webview is added to the center of a border layout, which is in a boxYLayout, which is the form. Could that be a source of the problem? – ygesher Feb 23 '16 at 07:38
  • This answer should have been a comment – ygesher Feb 23 '16 at 08:33
  • Place the web browser in the center of the form not in a box within a form. This answer is the correct answer and you can understand why when you read the section on layouts in the developer guide https://www.codenameone.com/manual/basics.html the browser requests 0 size as the data isn't loaded yet (HTML loads asynchronously) hence the component is sized to 0. Placing it in a Box Y is incorrect. – Shai Almog Feb 24 '16 at 03:31
  • Odd that the simulator was displaying the content even though on the device it never showed, don't you think? – ygesher Feb 24 '16 at 08:34
  • That's a race condition between the implementation and us which works better for the desktop than the Android device. – Shai Almog Feb 25 '16 at 03:42
  • What should I do if I have content above the webview that makes it so I need to the entire form to be scrollable? When I put the content in the North section of the `BorderLayout` container, it doesn't scroll. When I give the whole Form a layout of BoxYLayout, and put the webview in the center of a BorderLayout at the bottom, the webview doesn't expand. – ygesher Feb 26 '16 at 00:22
  • Redesign your UI. Scrolling a native widget is a bad idea and won't work properly neither in terms of UX nor in terms of functionality. To understand why read this: http://www.codenameone.com/blog/understanding-peer-native-components-why-codename-one-is-so-portable.html – Shai Almog Feb 26 '16 at 03:55
0

I found that you also need that parent containers/form use border layout and nothing else. I don't know why but in that way it seems to work...

Matt
  • 77
  • 7