当前位置: 代码迷 >> Android >> 请教大家,怎么用代码修改一个android应用程序在桌面的图标呢
  详细解决方案

请教大家,怎么用代码修改一个android应用程序在桌面的图标呢

热度:77   发布时间:2016-05-01 22:00:29.0
请问大家,如何用代码修改一个android应用程序在桌面的图标呢
网上找了很久都没找到,哪位朋友给一小段代码,或者给的连接呢?
谢谢



------解决方案--------------------
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);
  相关解决方案