UC浏览器有把书签发送至桌面的功能,现在Boss需要这个功能,我记得我以前写过一个Demo(下载),现在把方法分享给大家。
首先WebView制作一个简单的浏览器,这里方法就不在赘述了。
我添加了一个“添加书签至桌面的”Menu,并在onOptionsItemSelected()方法中添加了createShortCut()方法。
直接上createShortCut()方法:
private void createShortCut() {
// TODO Auto-generated method stub
//添加书签的意图
Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcutintent.putExtra("duplicate", false);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, wv.getTitle());
shortcutintent.putExtra("url", wv.getUrl());
Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icon);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
Intent intent =new Intent();
Uri content_url = Uri.parse(wv.getUrl());
intent.setData(content_url);
intent.setClassName("com.android.browser","com.android.browser.BrowserActivity"); //调用系统浏览器
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
sendBroadcast(shortcutintent);
}
当然你可以通过改变intent.setClassName(包名,类名)来改变打开方式,如果不添加这句话则让用户选择打开方式。
常用浏览器包名、类名:
uc浏览器 :"com.uc.browser", "com.uc.browser.ActivityUpdate"
opera :"com.opera.mini.android", "com.opera.mini.android.Browser"
qq浏览器 :"com.tencent.mtt", "com.tencent.mtt.MainActivity"