I have the following situation:
AS3 Code:
...
Security.allowDomain("*");
ExternalInterface.addCallback("onZoom", onZoom);
...
public function onZoom(...
JavaScript code:
...
alert(getFlashMovie("test"));
alert(getFlashMovie("test").onZoom);
...
And in OBJECT and EMBED tags I have allowScriptAccess="always"
If I test the html page from my computer ("file:///path-to-file.html") both
alert(getFlashMovie("test"));
alert(getFlashMovie("test").onZoom);
give me proper result.
If I put my html as well as my swf in my android phone sdcard and I do load it into a WebView like this...
webView = (WebView) findViewById(R.id.webViewMain);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginsEnabled(true);
webView.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl("file:///sdcard/test/test.html");
... then alert(getFlashMovie("test").onZoom); gives me "undefined".
If I move my html and swf to a web server, and load with webView.loadUrl("http:/mydomain.com/test/test.html"); it works.
I did another try with this example:
http://0me.me/demo/adobeflash/ExternalInterface.call/demo.html
It works if I load it from that url, it doesn't if I copy that html file (and the relevant swf) on my sdcard.
If I copy the same file (and swf) on my computer and test it locally, there it works.
So it seems that flash player for computer allows ExternalInterface.addCallback even for local files (file:///...) whereas flash player for android 10.2 doesn't.
I didn't try installing a local web server on my android phone and loading from there so far, but I would avoid such a solution if possible.
Can someone help me please?
Thanks.
Related
I've developed a small group of .html pages that are stored in a server.
My android app, using a webview with: setWebChromeClient loads these pages.
minSdkVersion 19
targetSdkVersion 24
The problem:
Everytime I need to load a new page, using a link in my .html page, the new page is opened in an external browser.
Url Overriding
I know about the shouldOverrideUrlLoading() method, when we're using the setWebViewClient().
But unfortunately I can't use the normal webview. I need to use the WebChromeClient() because of some feature that only work with this one. (Like the input file)
My doubt is...
How can I override my URL to force them to load inside of the webChromeClient?
I tried this but with no luck:
webView.setWebChromeClient(new WebChromeClient() {
// (...)
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
You can use following code to achieve this.
WebView web = (WebView)findViewById(R.id.web);
WebSettings webSettings = web.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportMultipleWindows(true); // This forces ChromeClient enabled.
web.setWebChromeClient(new WebChromeClient(){
#Override
public void onReceivedTitle(WebView view, String title) {
getWindow().setTitle(title); //Set Activity tile to page title.
}
});
web.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
I was using an embedded mobile web application in an Android App making use of the WebChromeClient class and did not want to fiddle around with recompiling the APK.
While looking for the easiest header(); solution (since the mobile web application is in php) I found out that using:
header("Location: url.php", TRUE, 307);
was a quick fix solution without recompiling the Android app.
This allowed the user to re-direct within the app without calling the web browser externally from my app.
Here is the link to the answer by Arindam Nayak where I got the idea from.
I have an Android app with that displays a mobile website (WebView), in the mobile website there are links redirecting to a PDF, Excel and video files.
When try to open it in my regular browser my phone asks to open it with another app or it start a download, so I can open it afterwards.
But in my WebView app it either doesn't work, no response or it displays a "Page unavailable" error.
Is it even possible?
To handle links in WebView, you can use the shouldOverrideUrlLoading method of WebViewClient class. Consider the following example;
WebView webView = (WebView) findViewById(R.id.infoView);
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Assuming you are giving link to some PDF file.
if (url.contains(".pdf")) {
// Now do what you want to with the url here
}
return true;
}
}
This way, you can intercept any link tapped in WebView and then do whatever you want.
I'm dealing with the following problem:
I have a webview inside an activity:
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setBuiltInZoomControls(false);
webView.getSettings().setSupportZoom(false);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webView.setScrollbarFadingEnabled(false);
webView.setWebViewClient(new HelloWebViewClient());
System.out.println("percorso" + path.toString());
url.setText(path.toString());
webView.loadUrl("local path of my html file" .....\..\..page.htm);
private class HelloWebViewClient extends WebViewClient {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
This is the app I'd like to run locally offline: http://miniapps.co.uk/checklist/
If I open the browser and i go to the link above everything works fine, so the android browser is actually able to run it.
Now I have downloaded this app and I stored it in a folder on my sd card: download/myapp
in the folder I have the html file: check_list.htm and a folder (check_list files) with the javascript files needed to run it.
But when i open it inside my webview, the page is correcty loaded but doesn't work...i can't click on buttons and other elements, i can't actually interact with it....
I thought it could be a problem related to my webview settings so i used astro file manager to surf into my sd card, i clicked on check_list.htm, i chose html viewer and i got the same issues....
So I downloaded opera mobile, and i did the same but this time I opened it with opera and now it's working correctly.
Do you know why? How can I fix the problem? Am I missing some settings on my webview or is the webview\android broser that hase some problems opening locally stored html pages and running linked javascript files?
EDIT
If I open the android browser and I write the path of the HTML file, it works. I have to do it manually cause if I click on the HTML file, android browser it's not an option......so in the end it works both on android browser and opera, and it doesn't with HTML viewer and my web view.....so I'm missing some settings cause the web view should have the same features of the android browser....shouldn't it?
If "doesn't run" mean it does not open new windows, that's because you need to specify the webview client.
From the Javadoc for WebView
By default, requests by the HTML to open new windows are ignored. This is true whether they be opened by JavaScript or by the target attribute on a link. You can customize your WebChromeClient to provide your own behaviour for opening multiple windows, and render them in whatever manner you want.
See https://stackoverflow.com/a/3847016/94363 or rtfm...
Please confirm before, your local file is inside asset/www/index.html directory.
I am having difficulty in loading a html file from my project assets folder into a webview. I have looked at dozens of tutorials and solutions but none seem to work for me.
In my project's assets folder I have two simple html files. index.html and faq.html
(The plan is to utilise this structure for my help documentation)
My code:
WebView wv = (WebView)findViewById(R.id.webview1);
wv.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
wv.loadUrl("file:///android_asset/index.html");
The webview displays the following:
Web Page Not Available
The Web Page at file:///android_asset/index.html could not be loaded as:
The requested file was not found. index.html
From everything I have read what I have here should work, but it does not.
your usage is right, so if has this problem, you need check the index.html file existed or not carefully, also you can clean the project, and rebuild it.
You can try this code ....
WebView myBrowser;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String myURL = "file:///android_asset/index.html";
myBrowser=(WebView)findViewById(R.id.mybrowser);
/*By default Javascript is turned off,
* it can be enabled by this line.
*/
myBrowser.getSettings().setJavaScriptEnabled(true);
myBrowser.setWebViewClient(new WebViewClient());
myBrowser.loadUrl(myURL);
}
I have a requirement where there is a URL = "http://www.example/Open.pdf"
Now from my android application I want to open this PDF file directly in the default PDF viewer.
The moment I click on this link on the webpage, user should be presented with a default PDF viewer opened with this document.
Note: This file should not be stored on the SD card.
How do I proceed for this implementation?
We can open PDF file in the webview without caching it. Write below code in "onCreate" method .
Working code :
String url = "http://www.example.com/abc.pdf";
final String googleDocsUrl = "http://docs.google.com/viewer?url=";
WebView mWebView=new WebView(this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return false; // then it is not handled by default action
}
});
mWebView.loadUrl((googleDocsUrl + url));
setContentView(mWebView);
What happens here is you open the PDF using Google Docs. Best Advantage of using above method is the lazy loading of PDF. Does not matter how heavy the PDF is. Google Docs takes care of it.
You can view the pdf in the WebView using googleDocs.
WebView webView = (WebView) findViewById(R.id.my_webview);
webView.setWebViewClient(new MyWebViewClient());
webView.addView(webView.getZoomControls());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf");
There is no way you can open a default PDF view from your application.
If your file is on the server and you want to open it without downloading then this might also pose a greater security concern. If external applications like default adobe reader can access the content on your server, then this is breaking the security framework altogether.
So, best option would be to launch a new instance of browser or webview and show the PDF document in google docs to the user.
This way user can read the document and get back to the recent state of the application as well.
You can view the pdf in the WebView using googleDocs.
WebView webView = (WebView) findViewById(R.id.my_webview);
webView.setWebViewClient(new MyWebViewClient());
webView.addView(webView.getZoomControls());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf");
do you have the others solution besides view pdf file using http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf