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