如何在启用/禁用活动别名后刷新应用程序启动器?

时间:2014-04-11 17:48:52

标签: java android android-activity android-manifest

我使用此清单

创建了一个应用程序
 <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.Activity"
        android:label="@string/app_name" >
    </activity>

    <activity-alias
        android:name="com.example.AliasIcon"
        android:enabled="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:targetActivity="com.example.Activity"
        android:theme="@style/AppTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

因为应用程序不需要启动器我想显示应用程序一次并让用户选择是保留还是隐藏图标

在我写的代码中

showIcon = hideIcon.isChecked();
    componentIcon = new ComponentName(getPackageName(), "com.example.AliasIcon");

    if (showIcon){
        flagIcon = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
    }else{
        flagIcon = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
    }


    getPackageManager().setComponentEnabledSetting(componentIcon, flagIcon, PackageManager.DONT_KILL_APP);
    hideIcon.setOnCheckedChangeListener(this);

showIcon是boolean,hideIcon是CheckBox,componentIcon是ComponentName,flagIcon是int。

当我运行应用程序(api8上的模拟器)时,一切正常但图标不会消失。 如果我点击出现一个吐司,说&#34;应用程序未安装&#34;。 为了让它消失,我必须重新启动模拟器。

有没有办法更新&#34;应用程序启动器? 也许使用android.intent.action.PACKAGE_CHANGED

0 个答案:

没有答案