如何改变应用程序的图标和标签一旦被安装? [英] How to change the icon and label of an app once it is installed?

查看:277
本文介绍了如何改变应用程序的图标和标签一旦被安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变我的应用程序的图标和标签一旦被安装。

I am trying to change the icon and label of my app once it is installed.

在清单中,我把这个code:

In the manifest, i put this code :

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/MyTheme" >
// 1st Activity declaration
<activity
    android:name=".activities.SplashScreenActivity"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:screenOrientation="portrait"
    android:theme="@style/Theme.Sherlock.NoActionBar" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        // I removed the next line to put it with the alias :
        // <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

// Activity Aliases
<activity-alias
    android:name=".Alias_0"
    android:enabled="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:targetActivity=".activities.SplashScreenActivity" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity-alias>
<activity-alias
    android:name=".Alias_1"
    android:enabled="false"
    android:icon="@drawable/alias1"
    android:label="@string/alias1"
    android:targetActivity=".activities.SplashScreenActivity" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity-alias>

和在preferenceActivity,我启用/禁用的别名是这样的:

And in a PreferenceActivity, I am enabling/disabling aliases like this :

packageManager.setComponentEnabledSetting(
        new ComponentName("com.mypackage", "com.mypackage.Alias_0"),
        PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
        PackageManager.DONT_KILL_APP);

packageManager.setComponentEnabledSetting(
        new ComponentName("com.mypackage", "com.mypackage.Alias_1"),
        PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
        PackageManager.DONT_KILL_APP);

有永远只有一个激活的别名。

There is always only one activated alias.

一旦被改变,我就可以在旧的应用程序图标/标签已经消失,在某些设备上,它需要一些时间的应用程序启动器看到(它可以持续很长)的发射显示激活的一个。
在此期间,没有办法来启动应用程序,因为没有图标

Once this is changed, I can see on the application launcher that the old app icon/label has disappeared and on some devices, it takes some times (it can last very long) for the launcher to display the activated one. During this time, there is no way to launch the app since there is no icon.

有没有办法通过编程刷新启动?

Is there any way to refresh the launcher programmatically ?

另外,我试图创建别名的激活/停用后的快捷方式。它工作正常,但如果我尝试移动周围的快捷方式,一旦我松开快捷方式到新的位置,Android启动崩溃。
这里是code我使用的是:

Also, i've tried to create a shortcut after the activation/deactivation of the aliases. It works fine but if I try to move the shortcut around, once I release the shortcut to its new position, the Android launcher crashes. Here is the code I'm using :

Intent shortcutIntent = new Intent(getApplicationContext(), SplashScreenActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);

Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutTitle);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), shortcutDrawableId));
addIntent.putExtra("duplicate", false);

addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
sendBroadcast(addIntent);

我缺少的东西吗?

Am I missing something ?

修改:只是要清楚,我并不想改变我的应用程序的名称之前安装。我想这样做,一旦应用程序被安装在手机上。

EDIT : Just to be clear, I am not looking to change the name of my app BEFORE installing it. I want to do it once the app is installed on my phone.

我想给的机会,用户有另一个图标/标签,一旦他们已经安装了应用程序。如果他们不激活该选项,他们应该有原来的图标/标签。

我也不会找一个更新来改变应用程序的名称。

I am also not looking to change the name of the app with an update.

推荐答案

在code张贴在这个问题显然是做了正确的道路。
有与Android 4.1和4.2的问题。在这里找到更多的细节:

The code posted in the question is apparently the correct way to do it. There is an issue with Android 4.1 and 4.2. Find more details here:

HTTPS://$c$c.google。 COM / p /安卓/问题/细节?ID = 54546

这篇关于如何改变应用程序的图标和标签一旦被安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆