Android中禁用组件(如Receiver或Activity等)

    private void disableComponent(Context context, String klass) {
        ComponentName name = new ComponentName(context, klass);
        PackageManager pm = context.getPackageManager();
        
        // We need the DONT_KILL_APP flag, otherwise we will be killed
        // immediately because we are in the same app.
        pm.setComponentEnabledSetting(name, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
    }

调用方法如下例:

disableComponent(context, "com.android.camera.DisableCameraReceiver");

 

上一篇:Android实现更新应用启动图标和名称


下一篇:判断微信是否已经安装