Android向桌面添加快捷方式,使其指向特定的(URL)网页
2011-08-18 10:32
786 查看
/*
* 在桌面添加快捷方式
* @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);
}
/*
* 在桌面添加快捷方式
* @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);
}
2.权限设置
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
这里第一个参数Parcelable类型的icon如何获得呢,以下举个例子从Drawable文件夹中获取图片。
Parcelable icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
* 在桌面添加快捷方式
* @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);
}
/*
* 在桌面添加快捷方式
* @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);
}
2.权限设置
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
这里第一个参数Parcelable类型的icon如何获得呢,以下举个例子从Drawable文件夹中获取图片。
Parcelable icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
相关文章推荐
- Android向桌面添加快捷方式,使其指向特定的网页
- Android向桌面添加快捷方式,使其指向特定的网页
- Android 开机自动运行和添加删除桌面快捷方式
- Android添加快捷方式(Short)到手机桌面
- android 添加桌面快捷方式
- android 添加快捷方式到桌面
- Android 添加、移除和判断 桌面快捷方式图标
- Android中程序向桌面和Launcher添加快捷方式【安卓进化三十二】
- android桌面快捷方式添加 删除 更新 自动运行
- Android编程实现向桌面添加快捷方式的方法
- Android 通过程序添加桌面快捷方式
- Android开发之向桌面添加快捷方式
- 如何在android桌面添加几个app图标做快捷方式?
- 9、Android添加快捷方式(Short)到手机桌面
- Android添加快捷方式(Short)到手机桌面
- Android添加桌面快捷方式
- Android编程添加快捷方式(Short)到手机桌面的方法(含添加,删除及查询)
- Android 为程序添加桌面快捷方式
- Android 添加App快捷方式到桌面
- Android为你的应用程序添加桌面快捷方式