我尝试以下代码来动态更改应用程序图标,但没有作用。
清单:
<uses-permission android:name="com.android.launcher.action.INSTALL_SHORTCUT"/>
类:
Intent myLauncherIntent = new Intent();
myLauncherIntent.setClassName("your.package.name", "YourLauncherActivityName");
myLauncherIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myLauncherIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Application Name");
intent.putExtra
(
Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext
(
getApplicationContext(),
R.drawable.app_icon
)
);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);
我需要在我的应用程序图标上显示计数器,每当有任何传入消息时,就像Gmail应用程序一样。那么如何在Android中获取应用程序图标并动态设置图标?
com.android.launcher
Intent
操作所证明的那样),并且可能会导致N个启动器快捷方式,即使是那些采纳它的启动器也是如此。 - CommonsWare