user1865039
user1865039

Reputation: 131

How to remove icon programatically (Android)

By remove the below intent-filter in AndroidManifest.xml, it can remove the icon after install.

<intent-filter>
  <action android:name="android.intent.action.MAIN" />
  <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

But i have try the below when on Boot than remove the Icon, but the icon still remain after reboot. I have add the permission, and this reboot receiver is work.

public class BootBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        PackageManager p = context.getApplicationContext().getPackageManager(); 
        ComponentName componentName = new ComponentName("com.example.removeicon","com.example.removeicon.LauncherActivity");
        p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

    }
}

Or Put the Boot on service and AndroidManifest.xml intent-filter is not remove, the service is run and work.

package com.example.removeicon;
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        PackageManager p = getPackageManager();
        ComponentName componentName = new ComponentName("com.example.removeicon","com.example.removeicon.LauncherActivity");
        p.setComponentEnabledSetting(componentName,PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
        startService();
    }

Upvotes: 0

Views: 2511

Answers (2)

satya prakash
satya prakash

Reputation: 238

try this below code, this one worked for me

PackageManager p = ctx.getPackageManager(); 
         p.setComponentEnabledSetting(((Activity)ctx).getComponentName(),
         PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

Upvotes: 2

Ram kiran Pachigolla
Ram kiran Pachigolla

Reputation: 21191

PackageManager p = getPackageManager();
ComponentName componentName = new ComponentName("com.example.removeicon","com.example.removeicon.LauncherActivity");
p.setComponentEnabledSetting(componentName, 
    PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

Note that the icon may not be gone until the next reboot.

Upvotes: 3

Related Questions