Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.content.ComponentName;
import android.content.Context;

import android.content.pm.PackageManager;

public class Main {
    /**
     * Enable/Disable Broadcast Receiver
     *
     * @param context
     *     the context
     * @param brClass
     *     the br class
     * @param enabled
     *     the enabled
     */
    public static void setStateOfReceiver(Context context, Class<?> brClass, boolean enabled) {
        ComponentName receiverName = new ComponentName(context, brClass.getName());
        PackageManager pm = context.getPackageManager();

        int newstate;
        if (enabled) {
            newstate = PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
        } else {
            newstate = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
        }

        pm.setComponentEnabledSetting(receiverName, newstate, PackageManager.DONT_KILL_APP);
    }
}