How to get Webview 'url' from AccessibilityNodeInfo - android

Suppose ,I'm on the third party app say Amazon.
Now I'm able to access all of the window content using accessibility service and accessibility event type : typeViewFocused.
And I have a condition that if the window content contains class name android.webkit.WebView then I have to find the loaded URL for that Webview. But couldn't find the URL
, I can access all the content inside webview but I dont need the content of WebView I only need that URL which that webview used to load the content. Even I have checked all AccessibilityNodeInfo objects but not able to find URL

Related

who sets the mimetype in Downloader?

In the WebView I am loading a HTML which has an anchor pointing to a location like "http://localhost:9300/sample.pdf"
I have also overriden the Downloader's onDowloadStart method.
When clicking the link, the onDowload method is called and the mimetype value is set to "application/pdf"
My question is how does Android know how to set the mime type?
Looking with Fiddler (I set it as a proxy on Android) there is no request done to the server when clicking the link.

WebView detect click in iframe

I have a WebView where I am loading a javascript that loads some content. That content is an html with an iframe.
It seems any click within iframe is not triggering calls to WebViewClient#shouldOverrideUrlLoading(WebView view, String url); The webview has set both WebViewClient and WebChromeClient.
A work-around I can see of is to call getSettings().setSupportMultipleWindows(true) on the WebView and then within onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) assume the call was made within iframe and use some inserted javascript in order to get the iframe data. But that seems ugly to me.
So, the question: how do you detect a click within iframe loaded within the webview?
Thanks!
I think I have found what is the problem: I broke the Same Origin Policy. A colleague that is doing web development pointed me in the right direction.
The whole document (containing the iFrame) has a different origin (combination of scheme, host name and port number) than containing iframe. As long as those frames (containing document and inner iframe) have different origins, they cannot communicate. That's why I am not getting calls to shouldOverrideUrlLoading.
EDIT: It seems there is a way to overpass above security policy, but that comes with accepted security risk: Add the following header in the response that contains the iframe: "Access-Control-Allow-Origin:*"

Titanium webview.reload() not working correct

When I try to reload the titanium webview true webview.reload(), the view does not reload correctly. Instead if loading the page it gives me a page not found.
what i'm doing:
In Titanium i make use of webviews to display data. These webviews make use of HTML that is stored in the local filesystem that Titanium offers. The webview is called url is set by :
webview.setUrl( Ti.Filesystem.applicationDataDirectory.toString() + 'index.html');
This sets the proper url for the webview, it let's me see the correct html page. When I use webview.reload(), it seems lost... is there a way to reload the webview, or should i remove and then add the webview again?
Setting a URL for WebView the resource is usually loaded from the Resources folder.
So try to move all HTML files there (into Resources, same folder where app.js is located) and simply use.
webview.setUrl('index.html');
This has worked for me both on iOS and Android.
(There is an issue related to Android regarding WebView and setting its content by html property but this shouldn't matter here)

Read content (XML) from Android WebView

when i try to get the html source code from webview i use this example for my solution:
Extracting HTML from a WebView
now i want to parse a page which has no html content. the page displays only a text extracted from xml source.
does anybody have an idea how to get the content (or xml source code) from webview?
best regards
EXAMPLE: XML
< ID >test< /ID > <BR>
< Status >0< /Status >
Is shown as: test0 in webview
I want get the "test0" and put it to string
Option #1: Use the same approach as is shown in the linked-to blog post. Devise some JavaScript that grabs the data out of your Web page and call that JavaScript via loadUrl(), routing the results to some JavaScript interface you injected into the WebView via addJavascriptInterface().
Option #2: Don't use WebView at all, and use HttpURLConnection or HttpClient to fetch the XML source.

page not available when opening link in webview

I take the response from an HTTP connection in the form of string and show that to webview like this:
WebView engine = (WebView)findViewById(R.id.webview);
engine.loadData(endResult, "text/html", "UTF-8"); /*endresult is string*/
I actually get a response that contains the google page (google search result direct from google.com).
The loadData method works well i.e it shows the web page but when I click on one of the links on that page it shows "page not available" and said that "xyz link might be temporarily down or it may have moved to permanently to a new web address".
this happens for all links accept the first present link on that page. i.e it shows correct page from first link on that page but fails for others..
I noticed that OSes prior to 2.3 failed to follow links if setHorizontalScrollBarEnabled and setVerticalScrollBarEnabled are set to false.
try to use loadDataWithBaseURL of the WebView class
I would avoid using engine.loadData - it seems to cause all sorts of crazy problems.
Use engine.loadDataWithBaseURL instead, and pass the base URL of where the content exists. I would think that the content you are loading is using relative paths in it's HTML so it's looking inside your app resources. By specifying the base URL you get around this problem.

Categories

Resources