请问大家,如何用代码修改一个android应用程序在桌面的图标呢 网上找了很久都没找到,哪位朋友给一小段代码,或者给的连接呢?谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 直接在资源文件res->drawable中把图标换成你想要的就可以了啊要是.png格式的 private static final String ACTION_INSTALL_SHORTCUT = "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完全不起作用,无法删除快捷方式。 如何将视频解码器移植到Android中 有android开发google map的兄弟吗?道路偏移怎么解决啊? ItemizedOverlay中怎么自定义图标 这是什么情况 android重力感应问题 string.xml特殊符号转译 eclipse上写的和服务器数据交换的项目在模拟器中能实现,但是在真机中不能实现 如何解决Activity 目录过深的问题 启动模拟器时闪一下就消失,求解! vs2015如何打包apk 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完全不起作用,无法删除快捷方式。