Passing data from Android Browser to external app - android

This is what I need to do:
I have an app running in the background. Now when the user is browsing and comes across an 'interesting' URL, he can make a gesture and send the URL to the external app. The app then processes it.
I can think of two way of doing this(though I am not sure if either is possible)
1. Program something like a hook that senses the particular gesture or key press and sends the URL to the app
Write something like an add on to the browser.
My question is, is any of this possible. If yes, could you give me a few hints so that I can go ahead. If not, then is there any other way to do it?
Thanks,
Sandip

Short answer : You can't use the android browser like this.
Long answer : The android browser is an application. The only way you can interact with it is to call it with an argument (a URL). And... that's all. You can't write an extension to the browser like you can do in Chrome.
If you want to control the browser, use a webview, but even in that case, you won't have the ability to detect gesture.
What you're trying to do is not possible.

Take a look at WebViewClient.shouldOverrideUrlLoading. It should allow you to be notified when a new URL is loaded.
http://developer.android.com/reference/android/webkit/WebViewClient.html#shouldOverrideUrlLoading%28android.webkit.WebView,%20java.lang.String%29

Related

Should I open an url in WebView inside app or in browser?

I was wondering if there is a best practice in Android about WebView/Browsers. I want to open an url in my app to show a web page but I do not have anything to retrieve from that page so I do not need to show it in a webview inside my app. Should I show that page in a browser or in a webview ?
If you should open an URL in WebView or Browser that totally depends upon your requirements. Still I am adding some points that you can consider:
Browser:
If you have some data like Privacy Policy of your organization, that just for user information. You do not require any inputs from user.
WebView:
If you want to,
Customize content of URL
Get some input from User
Send some information to Server
Thank You!
Quick Answer:
From your context, it looks going the Browser way is good enough.
Details:
When you don't have user inputs to process and it is not part of the user-flow in your app, go about showing it in the Browser. It's easier that way, because you don't have to manage anything explicitly.
When you have something to process or that this window is some part of your in-app flow, you should go the WebView way. It gives you the power to manage things and you really need to code of situations like user pressing "back button", and the like. I mean, you're the owner of the life-cycle management of the WebView and see how it seamlessly fits in your user flow while (s)he is at it.

Get url from android browser

is it possible to get callback whenever a url is opened from the android browser.
getallvisitedurls() method returns just url, I want it in realtime and with timestamp of the access.
This is not possible. The Android Browser does not emit a broadcast or anything like that whenever the user opens a URL in it. Besides, the user may be using a third party browser instead of the default one.
The only way you could do this is by making your own browser app and have the user use that one instead of the default browser that came with their ROM.
I believe it is possible to do so by using retrieveRequestToken.
The Twitter API returns a callback for OAuth, so I think it would be possible.
Have a look at this post. It explains how it is to be done and it sounds all good to me.
Note : I haven't tried it myself. So no guarantees. :)

Redial or reload a href tel if the number is engaged

I am using an href tel: to successfully create a clickable link for mobile phones such as Android. However, if the number is engaged/busy (unreachable) there seems to be no fall=back option to redial or reload the page.
Is it possible to refresh or redial the page if this happens from within the OS?
That functionality would clearly lie outside the control of a website or web app, since it will have transferred control of the call over to the phone application by that point.
So no, you're not going to be able to get a "callback" or the like from the phone application to the webpage indicating failure. Indeed, that might be a privacy concern anyway.
As far as refreshing or redialing, the closest you might get is to put a "refresh page" hook on the action of clicking a href tel: link with javascript, which is a relatively trivial procedure that is well documented elsewhere.

How can I prevent an Android WebView from manipulating a web page?

As shown here it is possible to:
1. Create an Android WebView with setJavaScriptEnabled=true
2. Load a URL
3. Override onPageFinished and change the Web page displayed to the user
Now, is it possible for the Web page owner to implement anything server-side which prevents this from happening? The risk is that a malicious app could spoof the user by amending the Web page for nefarious means...
Many thanks!
It is not really possible to prevent the web response being modified. You can only think of making it difficult for the spoofer to edit it.

Programmatically clear browser cache/history

During my activity I'm sending an intent to the browser in order to display a webpage :
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://ww.mywebpage.com");
startActivity(i);
I need to make sure that before sending the intent the browser cache and history are cleared so that the page get loaded from server directly and not from phone.
So far I've found the 2 following but I'm not sure they are used correctly :
Browser.clearHistory(getContentResolver());
Browser.clearSearches(getContentResolver());
Also with that cache is not cleared.
Do you know how to do that ?
First, you are assuming there is only one Web browser for Android. You are mistaken, and will be increasingly mistaken over time. Steel, Dolphin, Opera, etc. are already in production for Android, and Mozilla's Fennec is coming along nicely. This solution will not help you with other browsers.
Second, if a browser is incorrectly caching your data, your problem is probably on the server (i.e., not sending proper cache control headers). I'd try to fix it there, so that it will behave properly across all browsers.
Third, wiping the user's entire history and searches, to satisfy your requirements, is rather unprofessional. How would you like some desktop app wiping out your desktop browser's history and searches?
Fourth, you cannot clear the browser's cache programmatically.
Yes... and if you must assert more control on the client side rather than fixing it at the server, you'll need to display the content with a webview inside your application where you have full control, rather than delegating to the browser (which is a separate application running under a separate user id and separate security context that you can't mess with).

Categories

Resources