首页 > 开发 > Android > 正文

安卓上将一个网址以桌面图标的方式添加到手机上,点击这个图标后,就能访问那个网址

2017-09-08 15:24:26  来源:网友分享

这是网上搜到的一个包装好的方法,但是第三个参数怎么设置我不会。不知道怎么用这个方法

public void addShortcut(Parcelable icon, String name, Uri uri){          Intent intentAddShortcut = new Intent(ACTION_ADD_SHORTCUT);          //添加名称          intentAddShortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);          //添加图标          intentAddShortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);          //设置Launcher的Uri数据          Intent intentLauncher = new Intent();          intentLauncher.setData(uri);                     //添加快捷方式的启动方法          intentAddShortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intentLauncher);          sendBroadcast(intentAddShortcut);  

解决方案

如果是网址的话URI 就是网址啊