通过在AndroidManifest.xml中删除以下intent-filter,它可以在安装后删除该图标。
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
但我在启动时尝试以下操作而不是删除图标,但重启后图标仍然存在。我已经添加了权限,这个重启接收器正常工作。
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);
}
}
或者将Boot设置为service并且AndroidManifest.xml不会删除intent-filter,该服务正在运行并且正常工作。
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();
}
答案 0 :(得分:3)
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);
请注意,在下次重新启动之前,图标可能不会消失。
答案 1 :(得分:2)
尝试以下代码,这个对我有用
PackageManager p = ctx.getPackageManager();
p.setComponentEnabledSetting(((Activity)ctx).getComponentName(),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);