如何在android中动态更改APP图标

Yel*_*oud 7 android

我已尝试下面的代码,以动态更改应用程序图标,但没有用.

表现:

<uses-permission android:name="com.android.launcher.action.INSTALL_SHORTCUT"/>
Run Code Online (Sandbox Code Playgroud)

类:

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);
Run Code Online (Sandbox Code Playgroud)

我需要在应用程序图标上显示计数器,只要有任何传入消息来到我的应用程序,如gmail应用程序 那么如何在android中动态获取应用程序图标和设置图标???

Com*_*are 4

您无法动态修改应用程序图标。Gmail 不会动态修改应用程序图标。

主屏幕(实际显示这些内容的应用程序)可以选择将徽章应用于某些应用程序图标。您还可以创建一个看起来像带有徽章的图标的应用程序小部件。

  • @CommonsWare SuperSU 应用程序允许您更改其图标,因此这是可能的。我认为它可能通过更改图标并广播应用程序被替换/更新的意图来起作用。此外,即使启动器应用程序将图标存储在内存中,它们也需要在下次启动时再次获取它。 (3认同)