13

This is what I am using to open the browser with the given URI

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com/"));
startActivity(browserIntent);

Is there a way I can open the browser with previous visited page. Or say just open the Browser, so that last viewed page is shown.

Purpose:

In application user is asked to submit a URL, So instead of typing, it has an option Open Browser so that he/she can copy the URL, come back and submit it. There is a good probability that the last URL is what he/she wants to submit

EDIT:

I can get the last visited page from the browser history using

<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" />

but while installing the application, it says:

This application will read your browser history

which on seeing, no one installs.

Any way to change the Browser settings like, switch on Continue where I left ??

CJ Ramki
  • 2,620
  • 3
  • 25
  • 47
Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226
  • are you use webview display url... – NagarjunaReddy Jan 10 '13 at 13:32
  • This answer might be helpful: http://stackoverflow.com/questions/2577084/android-read-browser-history – Tomik Jan 10 '13 at 13:34
  • @Tomik I don't want to add any new permissions in my manifest. Moreover i don't want any history. I just want to open the browser(not with some url) :) – Archie.bpgc Jan 10 '13 at 13:37
  • I don't know, if you can open the browser at the last url like that. But you can try doing it by getting the last url from history and then use the intent above with that url. – Tomik Jan 10 '13 at 13:42

5 Answers5

1

I believe that you are developing this app so you know when you are firing an intent for opening the web browser. Just save that URL as a string in your shared preferences variable and whenever you open a new URL replace its value with new opened URL.

This way you will always have the last URL address in your shared pref variable. Now whenever you need it, just get it from the shared preferences.

You can find in more details about shared preferences from here:

http://developer.android.com/reference/android/content/SharedPreferences.html

mudit
  • 25,306
  • 32
  • 90
  • 132
  • My application has nothing to do with browser actually. Say you want to submit a facebook profile page as a comment in my application. I just want it to be user friendly, by avoiding typing if possible – Archie.bpgc Jan 10 '13 at 13:53
  • ohh then in that case you can maintain your own browser history in a simple sqlite DB and use it wherever you want. May be in autocompleteBox or any other view. – mudit Jan 11 '13 at 05:50
0

If you want to submit an URL, the easiest solution is to able to share the URL from the Browser to your app. The browser has a share button.

If you have the right Intent filter, your app will show up in that list.

RvdK
  • 19,580
  • 4
  • 64
  • 107
  • My application has nothing to do with browser actually. Say you want to submit a facebook profile page as a comment in my application. I just want it to be user friendly, by avoiding typing if possible. I dont want users to share url using my app or something like that – Archie.bpgc Jan 10 '13 at 13:54
0

I think it is okay to keep it opening www.google.com. If you user is about to insert a just clipboarded link he hardly wants to leave the tabs he currently has opened. So he has to create a new tab and insert the link. Now what if you already opened this new tab and served to www.google.com. There is one step less he has to do if you leave it as it is.

poitroae
  • 21,129
  • 10
  • 63
  • 81
  • Yeah currently i am using `www.google.com` but it would be better(not always tough) to open the browser with last visited page. Something like changing browser settings to **remember where i left** or asking user to switch it on.. – Archie.bpgc Feb 12 '13 at 12:02
0

Here is the code:

// create an intent to describe what app you wanna open
Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://"));

// and then get the default package name and start this app by yourself with a flag which allow it restore from history
ResolveInfo resolveInfo = getPackageManager().resolveActivity(browserIntent,PackageManager.MATCH_DEFAULT_ONLY);
Intent startIntent = getPackageManager().getLaunchIntentForPackage(resolveInfo.activityInfo.packageName);
startIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
startActivity(startIntent);
exloong
  • 441
  • 3
  • 6
0

this code may help:

Intent browserIntent = getPackageManager().getLaunchIntentForPackage("com.android.chrome");
startActivity(browserIntent);

by chance user don't have chrome then you can get the default browser's package name and open that intent.

Sonu Raj
  • 369
  • 3
  • 11