Itai Sagi
Itai Sagi

Reputation: 5615

Creating home screen browser shortcuts from android app

I have a php site, which is basically like a site directory, what I want to achieve is to create a home screen shortcuts from when I click a URL in an application, meaning: I need to first, intercept the url, decode it, and create a browser shortcut to a parameter within the url.

Thanks in advance, Itai.

Upvotes: 0

Views: 3145

Answers (1)

zsniperx
zsniperx

Reputation: 2742

It's quite easy to make the shortcut,

final Intent i = new Intent(); //intent for the shortcut
final Intent shortcutIntent = new Intent( /*put necessary parameters (i.e activity to launch)*/ );
shortcutIntent.putExtra(Browser.EXTRA_APPLICATION_ID /*if your launching a browser*/,
        Long.toString(/*put unique id e.g. system time etc.*/));
i.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
i.putExtra(Intent.EXTRA_SHORTCUT_NAME, /*title*/);
i.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,/*drawable*/);
i.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(i);

for url interception, in a WebViewClient

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (url.equalsIgnoreCase(/*your sitemap url*/)) {
        //use the above code
    }
    return true;
}

I hope this helps. I have not tested this but this is the general idea! Good luck

Upvotes: 6

Related Questions