B4A Library WebViewExtras

Discussion in 'Additional libraries, classes and official updates' started by warwound, Nov 7, 2011.

  1. warwound

    warwound Expert Licensed User

    WebViewExtras2 has been updated to version 2.20

    This updates adds support for the PermissionRequest object introduced in android API level 21.
    If a webpage requests access to 'user media' (camera, mic etc) then the WebChromeClient raises an event:

    PermissionRequest (PermissionRequest1 As PermissionRequest)

    And in your code you can grant or deny permission to the webpage to access the 'user media'.

    WebViewExtras2 version 2.20 can be found here: http://b4a.martinpearman.co.uk/webviewextras/WebViewExtras2-v2.20.zip
    An example project showing the use of PermissionRequest is attached to this post.

    An up to date reference for WebViewExtras2 can be found here: http://b4a.martinpearman.co.uk/webviewextras/WebViewExtras2.html
     

    Attached Files:

    Mashiane, AndOrNot, Erel and 2 others like this.
  2. AndOrNot

    AndOrNot Well-Known Member Licensed User

    Is possible to use javascript (such as for example getelementbyId("ex").value = 'hey') when i open the webview in fore desktop mode?
     
  3. warwound

    warwound Expert Licensed User

    Yes stuff like javascript work the same regardless of whether you've opened the webpage in it's mobile or desktop mode.
    Obviously javascript must be enabled in your WebView settings.
     
  4. AndOrNot

    AndOrNot Well-Known Member Licensed User

    When i connect webview in force desktop mode and i try to use getel...value to insert for example a string in google search bar the webview will be white.. why?
     
  5. warwound

    warwound Expert Licensed User

    You need to see the WebView console output to debug this.
    To see that output you can use WebViewExtras2 library:
    http://b4a.martinpearman.co.uk/webviewextras/WebViewExtras2-v2.20.zip

    Create and add a DefaultWebChromeClient to your WebView.
    The WebChromeClient will raise an event 'ConsoleMessage' whenever an error occurs in the WebView.
    Code example here:
    http://www.b4x.com/android/forum/th...oaded-website-into-webview.11232/#post-354156

    Now try to execute some javascript and see what ConsoleMessage(s) are passed in this event.
    You should hopefully see what's happening.
     
    AndOrNot likes this.
  6. AndOrNot

    AndOrNot Well-Known Member Licensed User

    Sorry, exactly in this moment i found the error. I don't write a callsub with callUIThread, so it is necessary to change UI. Thanks for help, all are very useful ;)
     
    warwound likes this.
  7. AndOrNot

    AndOrNot Well-Known Member Licensed User

    What is the minimum sdk required?
     
  8. warwound

    warwound Expert Licensed User

    AndOrNot and DonManfred like this.
  9. peacemaker

    peacemaker Well-Known Member Licensed User

    Hi, warwound,

    Is it possible to dynamically update HTML by document.getElementById and update somehow by .innerHTML = new_string ? Without full reloading.
    Any sample, please ?
     
  10. warwound

    warwound Expert Licensed User

    Hi.

    That is all pretty much 'standard javascript and DOM manipulation' so all possible.
    I'm afraid I'm too busy with work to put any example together for you.

    Can you describe what you're hoping to achieve?

    Martin.
     
  11. peacemaker

    peacemaker Well-Known Member Licensed User

    THanks for confirmation.
    I hope to make dynamical table update with data, getting from a web-site XML.
     
  12. Mousa Najafi

    Mousa Najafi Member Licensed User

    I added webview to viewpager panel that showed correctly on android 4.2 but blank on android 5
    I don't know this relates to webview or something else. I also tried with the webviewextra 1.42
    and webviewextra 2 too
     
  13. warwound

    warwound Expert Licensed User

    1) Is the WebView blank if you make the page it is contained in into the page that ViewPager initially displays?

    2) You can call a ViewPager method named 'setOffscreenPageLimit'.
    This sets how many offscreen pages ViewPager will keep loaded in memory.
    It might be that your page containing the WebView is being destroyed when offscreen, then when that page becomes visible the WebView fails to be recreated.
    So try calling setOffscreenPageLimit and setting a number of pages that will ensure that the page that contains the WebView is always kept in memory.
    http://www.b4x.com/android/forum/th...-panels-now-perfect.14165/page-15#post-196173
     
  14. Mousa Najafi

    Mousa Najafi Member Licensed User

    1) I used AHViewPager to design a 4 fixedtab layout. 3 Tabs are simple WebViews added to viewpager's panel and 4th tab
    is customlistview that contains cardviews including label and iconbutton.
    I got the PageFinished (Url As String) message from webview and it loads webpage from url in android 4.2
    but in android 5 It completes loading and just I can scroll down a blank webpage which scroll height is as same as contents of webpage . It seems contents are not able to load.

    2)I will try and reply here.
    also I will try the AHViewPager updated library ( DesignSupport) as I think this problem should be related to deprecated
    AHViewPager library
     
  15. Mousa Najafi

    Mousa Najafi Member Licensed User

    The problem is with website. I made a simple test webview which loads every tested webpage except my links. links works in a
    browser in my device. also another demo app that developed in android studio.
    I enabled javascript and setwebchromeclient by looking the source code from android studio project but I couldn't succeed
    would you test the following link in a webview and see what's going wrong with this web page in android 5.0
    link:
    http://pushe.co/mcontact/
     
  16. Mousa Najafi

    Mousa Najafi Member Licensed User

    by the way. here is my tested source code:
    Code:
    Sub Globals
        
    Dim WebView1 As WebView
        
    Dim client As DefaultWebChromeClient
        
    Dim murl As String = "http://pushe.co/mcontact/"
      
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
      
        
    Activity.LoadLayout("WebView")
      
        
    Dim webextra As WebViewExtras
      
        webextra.Initialize(WebView1)
        client.Initialize(
    "geo")
        webextra.GetSettings.SetCacheMode(webextra.GetSettings.LOAD_CACHE_ELSE_NETWORK)
        webextra.ZoomEnabled = 
    True
        webextra.SetWebChromeClient(client)
       
        webextra.JavaScriptEnabled = 
    True
        WebView1.LoadUrl(murl)
    End Sub
     
    Last edited: Dec 20, 2015
  17. Mousa Najafi

    Mousa Najafi Member Licensed User

    I attached the fragment xml and java code that is working properly for the above link.
    project is in android studio.
     

    Attached Files:

  18. stevel05

    stevel05 Expert Licensed User

    There appears to be something in the Javascript that the webview doesn't like on that site, if you add the lines:

    Code:
    Dim WVJO As JavaObject = WebView1
        WVJO.RunMethod(
    "setWebContentsDebuggingEnabled",Array(True))
    You can then use the chrome debugging tools on a USB connected Android device at chrome://inspect/#devices in a Google Chrome Browser on your PC to access a huge amount of debugging information.

    More info here: https://developers.google.com/web/t...debug/remote-debugging/remote-debugging?hl=en
     
    Mashiane and Mousa Najafi like this.
  19. warwound

    warwound Expert Licensed User

    Well i'm busy working for the next three days and then i'm flying to the UK on Thursday.
    I won't have time to look at the problem until after christmas :(.
     
  20. Mousa Najafi

    Mousa Najafi Member Licensed User

    Merry christmas warwound and thank you very much Stevel05 I will try remote debugging and reply
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice