其他分享
首页 > 其他分享> > Android中禁用组件(如Receiver或Activity等)

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");

 

标签:DONT,Activity,KILL,context,Receiver,disableComponent,Android,PackageManager,pm
来源: https://blog.51cto.com/u_15298588/3034204