为软件创建桌面快捷方式
2011-05-25 11:47
375 查看
废话我就不说了 直接上代码了 希望对大家有帮助 ...
这是一个封装好的工具类
这是一个封装好的工具类
package com.xinghui.util; /** *by 小猪 * 需要权限 * <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/> <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"/> */ import com.xinghui.WelcomeActivity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Parcelable; public class Shortcut { private Context mContext; public Shortcut(Context mContext){ this.mContext = mContext; } public void createShortcut(String shortcutName, int icon) { Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); Parcelable img = Intent.ShortcutIconResource.fromContext(mContext, icon); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, img); Intent sendToAct = new Intent(mContext, WelcomeActivity.class); sendToAct.setAction(Intent.ACTION_MAIN); sendToAct.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // sendToAct.putExtra("id", id); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, sendToAct); mContext.sendBroadcast(intent); } // 删除快捷方式: public void deleteShortcut(String scName) { final String ACTION_UNINSTALL_SHORTCUT = "com.android.launcher.action.UNINSTALL_SHORTCUT"; Intent intent = new Intent(ACTION_UNINSTALL_SHORTCUT ); //scName是快捷方式的名字。 intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, scName); //第一个参数使用application里定义的包,第二个参数使用Activity里定义的名字, //写完整的类名:包+类名。 ComponentName comp = new ComponentName("synmin.app.shortcut", "synmin.app.shortcut.ExeShortcutAct"); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent() .setComponent(comp).setAction(Intent.ACTION_MAIN)); mContext.sendBroadcast(intent); } }
相关文章推荐
- linux 安装软件 创建桌面快捷方式
- 【软件-InstallAnywhere】Java软件打包:将指定的文件创建快捷方式并安装到桌面(工具installanywhere2012)
- ubuntu系统下创建软件桌面快捷方式
- ubuntu系统下创建软件桌面快捷方式
- 2、ubuntu应用-创建软件桌面快捷方式
- ubuntu系统下创建软件桌面快捷方式
- (转)ubuntu系统下创建软件桌面快捷方式
- java实现软件程序开机自动启动和创建程序的桌面快捷方式源代码
- ubuntu创建软件桌面快捷方式
- ubuntu系统下创建软件桌面快捷方式
- ubuntu系统下创建软件桌面快捷方式
- java实现软件程序开机自动启动和创建程序的桌面快捷方式源代码
- ubuntu系统下创建软件桌面快捷方式
- ubuntu系统下创建软件桌面快捷方式
- ubuntu系统下创建软件桌面快捷方式
- ubuntu系统下创建软件桌面快捷方式
- ubuntu系统下创建软件桌面快捷方式
- ubuntu系统下创建软件桌面快捷方式
- Linux软件桌面快捷方式创建--通用
- ubuntu系统下创建软件桌面快捷方式