从Android应用程序创建主屏幕浏览器快捷方式

时间:2011-04-17 10:02:16

标签: java android

我有一个php网站,它基本上就像一个网站目录,我想要实现的是从我点击应用程序中的URL时创建主屏幕快捷方式,这意味着: 我需要先拦截网址,对其进行解码,然后在网址中创建一个参数的浏览器快捷方式。

先谢谢,Itai。

1 个答案:

答案 0 :(得分:6)

制作快捷方式非常容易,

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);

用于在WebViewClient中拦截url

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

我希望这会有所帮助。我没有测试过这个,但这是一般的想法!祝你好运