Alex Rivera | Logout

How to add android bookmark on homescreen from web page?

Asked 2011-02-27T07:00:22.863
17

I'm new to web applications for Android..

How can you add a bookmark on the home screen from a web page using Javascript from the click of a button?

If we make an easy way for users to bookmark pages, they will show some interest in bookmarking them. This is one of the requirement for my projects.

How can this be done?

Edit
Report

1 Answer

4

You can create a web page shortcut on home screen using this code. Provide the necessary info like url, title etc..

  final Intent in = new Intent();
  final Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
  long urlHash = url.hashCode();
  long uniqueId = (urlHash << 32) | shortcutIntent.hashCode();
  shortcutIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
  in.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
  in.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
  in.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                    Intent.ShortcutIconResource.fromContext(
                            BrowserBookmarksPage.this,
                            R.drawable.ic_launcher_shortcut_browser_bookmark));
  in.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 
//or   in.setAction(Intent.ACTION_CREATE_SHORTCUT); 

  sendBroadcast(in);

Update

The browser does not recognise the intent scheme, so there is no way you can add a shortcut to your webpage from your webpage.

answered 2011-09-20T18:57:22.947

Your Answer