簡體   English   中英

通過代碼更改應用程序圖標-android studio運行不再起作用

[英]Change app icon by code - android studio run does not work anymore

如果用戶希望更改我的應用程序圖標,我可以使用如下功能:

 public static void changeIcon(Activity activity, String addon)
{
    // 1) adactivate all aliases
    List<String> names = AppIconStyle.getNames();
    for (int i = 0; i < AppIconStyle.getNames().size(); i++)
    {
        ComponentName componentNameToDeactivate = new ComponentName(activity.getPackageName(), MainActivityMVP.class.getName() + "-" + names.get(i));
        activity.getPackageManager().setComponentEnabledSetting(componentNameToDeactivate, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    }
    // 2) activate selected alias
    ComponentName componentNameToActivate = new ComponentName(activity.getPackageName(), MainActivityMVP.class.getName() + "-" + addon);
    activity.getPackageManager().setComponentEnabledSetting(componentNameToActivate, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
}

問題是,android studio run始終會嘗試啟動我在設備上更改的默認別名...因此它找不到默認活動,因為此活動已停用...

我知道我可以在android studio run config中定義一個活動,但是實際上我希望有一個配置可以啟動設備上當前處於活動狀態的任何別名。 有可能嗎? 諸如“檢查清單並嘗試一個接一個的啟動器活動,直到一個啟動為止”之類的東西……

在清單中添加權限:

<uses-permission android:name="com.android.launcher.permission.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,“應用程序名稱”); 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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM