How do I get my android webview make a load locally - android

I have a doubt. What happens is the following:
I exported my game by using cocoonjs contruct 2, but I want to run it on my android webview by, because I want to implement starApp, and cocoonjs not support this.
So, using my code below, I get only a blank screen.
But in my launcher cocoonjs, this same project works normally, just that I select Canvas + can anyone help me?
web = (WebView) findViewById(R.id.webInicial);
web.setWebChromeClient(new WebChromeClient());
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("file:///android_asset/www/index.html");

webView.loadData(yourData, "text/html", "UTF-8");
Where youData is the actual HTML data.

Have you tried getApplicationContext().getAssets().open("www/index.html");?
If that doesn't work, I'd say try the solutions in this post and let us know if it worked for you.

Related

android WebView cannot show the image in release mode

WebView wv = new WebView(this.context);
wv.loadDataWithBaseURL("file:///android_res/drawable/", "...<img src="my_pic.png ..."", "text/html", "UTF-8", null);
the html is actually in string, i just made it easy to read.
I used above code to populate some html to a WebView to display an image in drawable,
it is fine in debug mode, but a broken image icon results if I install a apk directly.
i am suspecting proguard, but seems doesn't make sense.
anyone experienced please help me ...
thank you

WebView getting 404 on a good url

I'm getting a 404 in a webview using the following code . . .
LocateBrowser = (WebView)findViewById(R.id.locatebrowser);
LocateBrowser.setWebViewClient(new WebViewClient());
LocateBrowser.loadUrl("http://maps.google.com/maps?z=17&t=h&q=loc:31.8526,-110.9959");
If I copy that url into a browser on my PC, it works just fine.
If I don't implement the WebViewClient (the second line), the browser on the Android device opens up and displays the map properly. But I don't want it to do that, I want it to show in my WebView. The map looks like this in the external browser...
The problem is the above code first displays the screen above without the map and an indeterminate progress "Loading . . ." symbol for about a second and then displays google's 404 page saying "the URL /Search was not found on this server".
Is there something else I need to do?
Thanks,
Gary
What is wrong to use the WebViewClient ? If it works with that solution without using a the map api, that would be ok.
What is you aim ?
I failed to enable java script. Following code works but it produces a screen real estate problem.
LocateBrowser = (WebView)findViewById(R.id.locatebrowser);
LocateBrowser.setWebViewClient(new WebViewClient());
WebSettings webSettings = LocateBrowser.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setLoadWithOverviewMode(true);
LocateBrowser.loadUrl("http://maps.google.com/maps?z=17&t=h&q=loc:31.8526,-110.9959");

Issue with WebView and Google Maps

In my application on click of a button i am trying to launch the following url using a web view :
https://maps.google.com/maps?saddr=indiranagar bangalore&daddr=mgroad bangalore
My code is as below:
WebView webView=new WebView(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setSupportZoom(true);
webView.loadUrl("https://maps.google.com/maps?saddr=indiranagar bangalore&daddr=mgroad bangalore");
When the web view appears it first displays the following:
And immediately displays the following:
I do not get to see the maps. Am i missing on something in my code. Can someone kindly help me with this please. Thanks in advance.
I had the same issue in using Google Maps URL into a ColorBox popup.
I found out that you can add &output=embed at the end of the URL to make it show in an iframe.
Maybe this solution will help you too.
So try:
webView.loadUrl("https://maps.google.com/maps?saddr=indiranagar bangalore&daddr=mgroad bangalore&output=embed");
i found that WebView does not support javascript by default, and this will lead google map jump to a URL that contains a params "nojs",
so, just add this line for your webview, problem gone.
webview.getSettings().setJavaScriptEnabled(true);

Android +1 button in WebView

I've tried putting Google's +1 button in WebView using the methods they describe. I've initialized the WebView as follows:
final WebView web = (WebView)findViewById(R.id.webView);
web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setSavePassword(false);
web.getSettings().setBuiltInZoomControls(false);
web.getSettings().setUseWideViewPort(true);
web.getSettings().setLoadWithOverviewMode(true);
web.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
web.setHorizontalScrollBarEnabled(false);
web.setBackgroundColor(0xff2e2e2e);
web.loadDataWithBaseURL(null, htmlCodeGoesHere, "text/html", "utf-8", null);
And the html code:
<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<g:plusone href="http://stackoverflow.com"></g:plusone>
The problem is... the button doesn't display at all.
How do I fix it? By the way - I also want the button to launch a new window instead using the WebView. Is there a simple solution?
Thanks
The problem lies in permissions system in WebView. Scripts in local files have problems accessing external resources. The solution is to make WebView think local code was loaded from external website.
web.loadDataWithBaseURL("http://fake.com", htmlCodeGoesHere, "text/html", "utf-8", null);
The button will appear, but unfortunetely it doesn't work well in WebView.
I am not too experienced with WebView, but the fact the the button doesn't show up at all, sounds like it could be an issue in your layout/main.xml file. Have you taken a look at this yet?
Also, for the button to launch a new window, I think it is possible to attach an setOnClickListener, once that is done just treat it as a button, and open a new window. I hope that is possible.

zoom controller not working in webview in android

I am suffering from a strange problem in order to implement WebView in android. I am trying to load html5 supported web page in my WebView, but the problem is default zoom controller is not working in WebView.
i tried with the following code.
webview.getSettings().setBuiltInZoomControls(true);
webview.invokeZoomPicker();
Can any body help regarding this.
Add this line also
WebSettings setting = wView.getSettings();
setting.setBuiltInZoomControls(true);
setting.setSupportZoom(true);
if work or not please reply

Categories

Resources