网上找了很久都没找到,哪位朋友给一小段代码,或者给的连接呢?
谢谢
谢谢
解决方案 »
- 使用shape画环的问题
- 我下载XML,取出里面的中文字,打印就出现乱码
- 新手问android 4.0 文件管理怎么关联新增的文件类型?
- 求在windows下调试android ndk C/C++的代码
- android客户端向服务端传输对象。报了一个异常,请大家解决啊
- 如何下载apk到内存然后安装?
- viewpager 滑动的时候有没有什么特效啊
- android 媒体库刷新问题
- 求救 !关于AlertDialog 中OnClickListener问题!
- 新人求教,这安卓sdk的虚拟机是不是多核优化不行呀还是怎么地,任务管理器居然是这样的
- MIDIPlayer
- 是否有公认的异步http请求的写法?
要是.png格式的
"com.android.launcher.action.INSTALL_SHORTCUT";
/**
* 是否可以有多个快捷方式的副本
*/
static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
Intent shortcutIntent = new Intent(ACTION_INSTALL_SHORTCUT);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
getString(R.string.app_name));
shortcutIntent.putExtra(EXTRA_SHORTCUT_DUPLICATE, false);
Intent intent2 = new Intent(Intent.ACTION_MAIN);
intent2.addCategory(Intent.CATEGORY_LAUNCHER);
intent2.setComponent(new ComponentName(this.getPackageName(),
".Main"));
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent2);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this,
R.drawable.icon)); //可以修改icon的值
sendBroadcast(shortcutIntent);
private void CreateIcon(boolean enc)
{
int icon = enc ? R.drawable.icon_enc : R.drawable.icon_dec;
String ACTION_INSTALL_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";
String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
Intent shortCutIntent = new Intent(ACTION_INSTALL_SHORTCUT);
shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
shortCutIntent.putExtra(EXTRA_SHORTCUT_DUPLICATE, false);
Intent mainIntent = new Intent(Intent.ACTION_MAIN);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
mainIntent.setComponent(new ComponentName(this.getPackageName(),
"." + this.getLocalClassName()));
shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, mainIntent);
shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this, icon));
sendBroadcast(shortCutIntent);
}
private void DeleteIcon()
{
String ACTION_UNINSTALL_SHORTCUT =
"com.android.launcher.action.UNINSTALL_SHORTCUT";
Intent shortCutIntent = new Intent(ACTION_UNINSTALL_SHORTCUT);
shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
Intent mainIntent = new Intent(Intent.ACTION_MAIN);
mainIntent.setComponent(new ComponentName(this.getPackageName(),
"." + this.getLocalClassName()));
shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, mainIntent);
sendBroadcast(shortCutIntent);
}上面的代码,CreateIcon可以在桌面创建快捷方式,但是当再次调用时,会提示快捷方式已经存在。
而DeleteIcon完全不起作用,无法删除快捷方式。