Android向桌面添加快捷方式,使其指向特定的网页
2010-07-21 11:34
615 查看
今天遇到一个需求,就是向桌面添加一个快捷方式,使点击时链接到特定的网页。网上找了一下,看到这篇文章
http://www.moandroid.com/?p=1699
受其启发,实现了该功能。
/*
* 在桌面添加快捷方式
* @param
icon 快捷方式图标
* @param
name 快捷方式名称
* @param
uri 快捷方式的intent Uri
*/
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);
}
当然,你还需要添加一个permission
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"
/>
这里第一个参数Parcelable类型的icon如何获得呢,以下举个例子从Drawable文件夹中获取图片。
Parcelable
icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
http://www.moandroid.com/?p=1699
受其启发,实现了该功能。
/*
* 在桌面添加快捷方式
* @param
icon 快捷方式图标
* @param
name 快捷方式名称
* @param
uri 快捷方式的intent Uri
*/
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);
}
当然,你还需要添加一个permission
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"
/>
这里第一个参数Parcelable类型的icon如何获得呢,以下举个例子从Drawable文件夹中获取图片。
Parcelable
icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
相关文章推荐
- Android向桌面添加快捷方式,使其指向特定的(URL)网页
- Android向桌面添加快捷方式,使其指向特定的网页
- Android O添加桌面快捷方式的示例
- Android在桌面添加两个快捷方式,如何区分从哪个入口进去的?
- JS 添加网页桌面快捷方式的代码详细整理
- Android开发被添加到桌面快捷方式
- Android 开机自动运行和添加删除桌面快捷方式
- Android添加桌面快捷方式的简单实现
- JS 添加网页桌面快捷方式的代码
- Android应用添加(创建)和删除及判断是否存在桌面快捷方式
- Android中为你的应用程序添加桌面快捷方式
- Android 添加App快捷方式到桌面
- Android添加快捷方式(Short)到手机桌面
- android 添加桌面快捷方式
- Android添加快捷方式(Short)到手机桌面
- Android编程添加快捷方式(Short)到手机桌面的方法(含添加,删除及查询)
- Android 通过程序添加桌面快捷方式
- android应用添加桌面快捷方式
- 在Android桌面添加应用程序的快捷方式图标