Code example for PackageManager

Methods: setComponentEnabledSetting

0
        // When the first widget is created, register for the TIMEZONE_CHANGED and TIME_CHANGED 
        // broadcasts.  We don't want to be listening for these if nobody has our widget active. 
        // This setting is sticky across reboots, but that doesn't matter, because this will 
        // be called after boot if there is a widget instance for this provider. 
        PackageManager pm = context.getPackageManager();
        pm.setComponentEnabledSetting(
                new ComponentName("com.example.android.apis", ".appwidget.ExampleBroadcastReceiver"),
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
    } 
 
    @Override 
    public void onDisabled(Context context) {
        // When the first widget is created, stop listening for the TIMEZONE_CHANGED and 
        // TIME_CHANGED broadcasts. 
        Log.d(TAG, "onDisabled");
        PackageManager pm = context.getPackageManager();
        pm.setComponentEnabledSetting(
                new ComponentName("com.example.android.apis", ".appwidget.ExampleBroadcastReceiver"),
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
Stop searching for code, let great code find you!  Add Codota to your java IDE