Example usage for android.content Intent ACTION_BOOT_COMPLETED

List of usage examples for android.content Intent ACTION_BOOT_COMPLETED

Introduction

In this page you can find the example usage for android.content Intent ACTION_BOOT_COMPLETED.

Prototype

String ACTION_BOOT_COMPLETED

To view the source code for android.content Intent ACTION_BOOT_COMPLETED.

Click Source Link

Document

Broadcast Action: This is broadcast once, after the user has finished booting.

Usage

From source file:com.bhb27.isu.services.BootBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    // only run if the app has run before and main has extracted asserts
    String action = intent.getAction();
    boolean run_boot = Tools.getBoolean("run_boot", false, context);
    boolean rootAccess = Tools.rootAccess(context);
    if (Intent.ACTION_BOOT_COMPLETED.equals(action) && rootAccess && run_boot) {
        Log.d(TAG, " Started action " + action + " run_boot " + run_boot);

        if (Tools.getBoolean("prop_run", false, context) && Tools.getBoolean("apply_props", false, context))
            ContextCompat.startForegroundService(context, new Intent(context, PropsService.class));

        ContextCompat.startForegroundService(context, new Intent(context, BootService.class));

        if (Tools.getBoolean("apply_su", false, context) && Tools.SuVersionBool(Tools.SuVersion(context))) {

            AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
            Intent serviceIntent = new Intent("com.bhb27.isu.services.SuServiceReceiver.RUN");
            serviceIntent.putExtra("RUN", 100);
            serviceIntent.setClass(context, SuServiceReceiver.class);
            serviceIntent.setAction("RUN");

            PendingIntent pi = PendingIntent.getBroadcast(context, 100, serviceIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
                    + Integer.valueOf(Tools.readString("apply_su_delay", "0", context)), pi);
        }/*from w ww.j a v a2  s  . c  om*/

    } else
        Log.d(TAG, "Not Started action " + action + " rootAccess " + rootAccess + " run_boot " + run_boot);
}

From source file:com.android.talkback.BootReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    TalkBackService service = TalkBackService.getInstance();
    if (service == null) {
        return;//  w  ww.  j  a va2  s . c  o m
    }

    // We need to ensure that onLockedBootCompleted() and onUnlockedBootCompleted() are called
    // *in that order* to properly set up TalkBack.
    switch (intent.getAction()) {
    case Intent.ACTION_LOCKED_BOOT_COMPLETED:
        // Only N+ devices will get this intent (even if they don't have FBE enabled).
        service.onLockedBootCompleted();
        break;
    case Intent.ACTION_BOOT_COMPLETED:
        if (!BuildCompat.isAtLeastN()) {
            // Pre-N devices will never get LOCKED_BOOT, so we need to do the locked-boot
            // initialization here right before we do the unlocked-boot initialization.
            service.onLockedBootCompleted();
        }
        service.onUnlockedBootCompleted();
        break;
    }
}

From source file:it.gulch.linuxday.android.receivers.AlarmReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    if (ACTION_NOTIFY_EVENT.equals(action)) {

        // Forward the intent to the AlarmIntentService for background processing of the notification
        Intent serviceIntent = new Intent(context, AlarmIntentService.class);
        serviceIntent.setAction(ACTION_NOTIFY_EVENT);
        serviceIntent.setData(intent.getData());
        startWakefulService(context, serviceIntent);

    } else if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {

        if (FosdemAlarmManager.getInstance().isEnabled()) {
            Intent serviceIntent = new Intent(context, AlarmIntentService.class);
            serviceIntent.setAction(AlarmIntentService.ACTION_UPDATE_ALARMS);
            serviceIntent.putExtra(AlarmIntentService.EXTRA_WITH_WAKE_LOCK, true);
            startWakefulService(context, serviceIntent);
        }/*ww  w.j  a  v a  2 s  .  c  om*/
    }
}

From source file:org.namelessrom.devicecontrol.receivers.BootUpReceiver.java

@Override
public void onReceive(final Context ctx, final Intent intent) {
    if (intent == null) {
        return;/*from   ww w .j  a v  a 2 s .com*/
    }

    final String action = intent.getAction();
    if (TextUtils.isEmpty(action) || (!Intent.ACTION_BOOT_COMPLETED.equals(action)
            && !"android.intent.action.QUICKBOOT_POWERON".equals(action))) {
        return;
    }

    startBootupStuffs(ctx);
}

From source file:com.example.android.directboot.BootBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    boolean bootCompleted;
    String action = intent.getAction();
    Log.i(TAG, "Received action: " + action + ", user unlocked: " + UserManagerCompat.isUserUnlocked(context));
    if (BuildCompat.isAtLeastN()) {
        bootCompleted = Intent.ACTION_LOCKED_BOOT_COMPLETED.equals(action);
    } else {/*from  w  w  w  .  ja v a  2 s.c o m*/
        bootCompleted = Intent.ACTION_BOOT_COMPLETED.equals(action);
    }
    if (!bootCompleted) {
        return;
    }
    AlarmUtil util = new AlarmUtil(context);
    AlarmStorage alarmStorage = new AlarmStorage(context);
    for (Alarm alarm : alarmStorage.getAlarms()) {
        util.scheduleAlarm(alarm);
    }
}

From source file:com.bufarini.reminders.AlarmReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    final String action = intent.getAction();
    if (Log.LOGV)
        Log.v("AlarmInitReceiver \"" + action + "\"");
    final PendingResult result = goAsync();
    final WakeLock wakelock = AlarmAlertWakeLock.createPartialWakeLock(context);
    wakelock.acquire();/*w w w. j a  v  a2 s .c  o m*/
    AsyncHandler.post(new Runnable() {
        @Override
        public void run() {
            try {
                String alarmActionName = context.getResources().getString(R.string.intent_action_alarm);
                if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
                    SharedPreferences prefs = context.getSharedPreferences(Reminders.class.getName(),
                            Context.MODE_PRIVATE);
                    String accountName = prefs.getString(ListManager.PREF_ACCOUNT_NAME, null);
                    if (Log.LOGV)
                        Log.v("AlarmInitReceiver accountName = \"" + accountName + "\"");
                    if (accountName != null && !accountName.equals(""))
                        setReminders(context, accountName);
                } else if (alarmActionName.equals(action)) {
                    showNotification(context, intent);

                    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
                    vibrator.vibrate(VIBRATE_PATTERN, 1);
                }
                result.finish();
                if (Log.LOGV)
                    Log.v("AlarmInitReceiver finished");
            } finally {
                wakelock.release();
            }
        }
    });
}

From source file:com.stanleyidesis.quotograph.api.receiver.LWQReceiver.java

@Override
public void onReceive(final Context context, Intent intent) {
    String action = intent.getAction();
    if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
        // Set the alarm
        LWQAlarmController.resetAlarm();
    } else if (context.getString(R.string.action_change_wallpaper).equals(action)) {
        // Change the wallpaper
        Intent updateService = new Intent(context, LWQUpdateService.class);
        startWakefulService(context, updateService);
        LWQNotificationControllerHelper.get().dismissNewWallpaperNotification();
        LWQNotificationControllerHelper.get().dismissWallpaperGenerationFailureNotification();
        // Log either a skip or auto-generated wallpaper
        if (AnalyticsUtils.URI_CHANGE_SOURCE_NOTIFICATION.equalsIgnoreCase(intent.getDataString())) {
            AnalyticsUtils.trackEvent(AnalyticsUtils.CATEGORY_WALLPAPER, AnalyticsUtils.ACTION_SKIPPED,
                    AnalyticsUtils.LABEL_FROM_NOTIF);
        } else if (AnalyticsUtils.URI_CHANGE_SOURCE_ALARM.equalsIgnoreCase(intent.getDataString())) {
            AnalyticsUtils.trackEvent(AnalyticsUtils.CATEGORY_WALLPAPER,
                    AnalyticsUtils.ACTION_AUTOMATICALLY_GEN, AnalyticsUtils.LABEL_ALARM);
        }//from  w  w w .j  av a2s .  co  m
    } else if (context.getString(R.string.action_share).equals(action)) {
        final LWQWallpaperController wallpaperController = LWQWallpaperControllerHelper.get();
        final String shareText = String.format("\"%s\" - %s", wallpaperController.getQuote(),
                wallpaperController.getAuthor());
        final String shareTitle = String.format("Quote by %s", wallpaperController.getAuthor());
        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, shareTitle);
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareText);
        final Intent chooser = Intent.createChooser(sharingIntent,
                context.getResources().getString(R.string.share_using));
        chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(chooser);
        // Log it
        boolean sharedFromNotif = AnalyticsUtils.URI_SHARE_SOURCE_NOTIFICATION
                .equalsIgnoreCase(intent.getDataString());
        AnalyticsUtils.trackShare(AnalyticsUtils.CATEGORY_WALLPAPER,
                sharedFromNotif ? AnalyticsUtils.LABEL_FROM_NOTIF : AnalyticsUtils.LABEL_IN_APP);
    } else if (context.getString(R.string.action_save).equals(action)) {
        AnalyticsUtils.trackEvent(AnalyticsUtils.CATEGORY_WALLPAPER, AnalyticsUtils.ACTION_SAVED,
                AnalyticsUtils.LABEL_FROM_NOTIF);
        new LWQSaveWallpaperImageTask().execute();
    } else if (context.getString(R.string.action_survey_response).equals(action)) {
        LWQNotificationControllerHelper.get().dismissSurveyNotification();
        int surveyResponse = Integer.parseInt(intent.getDataString());
        if (surveyResponse < UserSurveyController.RESPONSE_NEVER
                || surveyResponse > UserSurveyController.RESPONSE_OKAY) {
            return;
        }
        UserSurveyController.handleResponse(surveyResponse);
    }
}

From source file:org.wso2.iot.agent.services.AgentStartupReceiver.java

@Override
public void onReceive(final Context context, Intent intent) {
    String action = intent.getAction();
    if (Constants.DEBUG_MODE_ENABLED) {
        Log.d(TAG, "Action received: " + action);
    }/*from ww w.jav  a2 s  .c  om*/
    if (ConnectivityManager.CONNECTIVITY_ACTION.equals(action) && !isNetworkConnected(context, intent)) {
        return;
    }
    if (!Preference.getBoolean(context, Constants.PreferenceFlag.DEVICE_ACTIVE)) {
        Log.e(TAG, "Device is not active");
        return;
    }
    setRecurringAlarm(context.getApplicationContext());
    if (!EventRegistry.eventListeningStarted) {
        EventRegistry registerEvent = new EventRegistry(context.getApplicationContext());
        registerEvent.register();
    }
    if (!CommonUtils.isServiceRunning(context, LocationService.class)) {
        Intent serviceIntent = new Intent(context, LocationService.class);
        context.startService(serviceIntent);
    }
    if (Intent.ACTION_BOOT_COMPLETED.equals(action)
            || Constants.AGENT_UPDATED_BROADCAST_ACTION.equals(action)) {
        if (Constants.OWNERSHIP_COSU.equals(Constants.DEFAULT_OWNERSHIP)) {
            Preference.putBoolean(context.getApplicationContext(), Constants.AGENT_FRESH_START, true);
            Intent i = new Intent(context, SplashActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        }
    }
}

From source file:org.durka.hallmonitor.CoreReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) || intent.getAction().equals(QUICKBOOT_POWERON)
            || intent.getAction().equals(HTC_QUICKBOOT_POWERON)) {
        Log.d(LOG_TAG + ".boot", "Boot called.");
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        if (prefs.getBoolean("pref_enabled", false)) {
            Intent mIntent = new Intent(context, CoreService.class);
            context.startService(mIntent);
        }/*from  w w w .j  a  v a  2  s .c  o m*/
    }

    if (CoreStateManager.getInitialized()) {
        localContext = CoreStateManager.getContext();
        mStateManager = ((CoreApp) localContext).getStateManager();
    } else {
        return;
    }

    if (!mStateManager.getPreference().getBoolean("pref_enabled", false)) {
        return;
    }

    mStateManager.acquireCPUGlobal();

    if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {

        Log.d(LOG_TAG + ".screen", "Screen on event received.");

        if (mStateManager.getCoverClosed()) {
            Log.d(LOG_TAG + ".screen", "Cover is closed, display Default Activity.");
            mStateManager.setBlackScreenTime(0);
            Intent mIntent = new Intent(localContext, CoreService.class);
            mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_LAUNCH_ACTIVITY);
            mStateManager.sendToCoreService(mIntent);
        } else {
            // Log.d(LOG_TAG + ".screen",
            // "Cover is open, free everything.");
            // mStateManager.freeDevice();
            Log.d(LOG_TAG + ".screen", "Cover is open, send to background.");
            Intent stbDAIntent = new Intent(CoreApp.DA_ACTION_SEND_TO_BACKGROUND);
            LocalBroadcastManager.getInstance(localContext).sendBroadcastSync(stbDAIntent);
        }

    } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
        Log.d(LOG_TAG + ".screen", "Screen off event received.");
        // mStateManager.freeDevice();

    } else if (intent.getAction().equals(Intent.ACTION_POWER_CONNECTED)) {
        Intent batteryDAIntent = new Intent(CoreApp.DA_ACTION_BATTERY_REFRESH);
        LocalBroadcastManager.getInstance(localContext).sendBroadcastSync(batteryDAIntent);

        Intent mIntent = new Intent(localContext, CoreService.class);
        mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_WAKEUP_DEVICE);
        mStateManager.sendToCoreService(mIntent);

    } else if (intent.getAction().equals(Intent.ACTION_POWER_DISCONNECTED)) {
        Intent batteryDAIntent = new Intent(CoreApp.DA_ACTION_BATTERY_REFRESH);
        LocalBroadcastManager.getInstance(localContext).sendBroadcastSync(batteryDAIntent);

        Intent mIntent = new Intent(localContext, CoreService.class);
        mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_WAKEUP_DEVICE);
        mStateManager.sendToCoreService(mIntent);

    } else if (intent.getAction().equals(ALARM_ALERT_ACTION)) {

        Log.d(LOG_TAG + ".alarm", "Alarm on event received.");

        // only take action if alarm controls are enabled
        if (mStateManager.getPreference().getBoolean("pref_alarm_controls", false)) {

            Log.d(LOG_TAG + ".alarm", "Alarm controls are enabled, taking action.");
            mStateManager.setAlarmFiring(true);

            Intent mIntent = new Intent(localContext, CoreService.class);
            mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_INCOMMING_ALARM);
            mStateManager.sendToCoreService(mIntent);
        } else {
            Log.d(LOG_TAG + ".alarm", "Alarm controls are not enabled.");
        }

    } else if (intent.getAction().equals(ALARM_DONE_ACTION)) {

        Log.d(LOG_TAG + ".alarm", "Alarm done event received.");

        // only take action if alarm controls are enabled
        if (mStateManager.getPreference().getBoolean("pref_alarm_controls", false)) {
            Log.d(mStateManager.getPreference() + ".alarm", "alarm is over, cleaning up");
            mStateManager.setAlarmFiring(false);

            if (mStateManager.getCoverClosed()) {
                Intent mIntent = new Intent(localContext, CoreService.class);
                mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_LAUNCH_ACTIVITY);
                mStateManager.sendToCoreService(mIntent);
            }
        }
    } else if (intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {

        if (mStateManager.getPreference().getBoolean("pref_phone_controls", false)) {
            String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
            Log.d(LOG_TAG + ".phone", "phone state changed to " + state);
            if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                Intent mIntent;
                mStateManager.setPhoneRinging(true);
                mStateManager.setCallFrom(intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER));
                Log.d(LOG_TAG, "call from " + mStateManager.getCallFrom());
                mIntent = new Intent(localContext, CoreService.class);
                mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_INCOMMING_CALL);
                mStateManager.sendToCoreService(mIntent);
            } else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                Intent mIntent;
                mStateManager.setPhoneRinging(false);
                Log.d(LOG_TAG, "call is over, cleaning up");
                if (mStateManager.getCoverClosed()) {
                    mIntent = new Intent(localContext, CoreService.class);
                    mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_LAUNCH_ACTIVITY);
                    mStateManager.sendToCoreService(mIntent);
                }
            } else if (state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
            }
        } else {
            Log.d(LOG_TAG + ".phone", "phone controls are not enabled");
        }
    } else if (intent.getAction().equals(mStateManager.getActionCover())) {
        int state = intent.getIntExtra(EXTRA_LID_STATE, LID_ABSENT);
        Log.d(LOG_TAG + ".cover", "cover state changed to " + state);
        if (state == LID_CLOSED) {
            Log.d(LOG_TAG + ".cover", "Cover is close, enable Default Activity.");
            mStateManager.setCoverClosed(true);
            Intent mIntent = new Intent(localContext, CoreService.class);
            mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_LAUNCH_ACTIVITY);
            mStateManager.sendToCoreService(mIntent);
        } else if (state == LID_OPEN) {
            // Log.d(LOG_TAG + ".cover",
            // "Cover is open, stopping Default Activity.");
            mStateManager.setCoverClosed(false);
            // mStateManager.freeDevice();
            Log.d(LOG_TAG + ".screen", "Cover is open, send to background.");
            Intent stbDAIntent = new Intent(CoreApp.DA_ACTION_SEND_TO_BACKGROUND);
            LocalBroadcastManager.getInstance(localContext).sendBroadcastSync(stbDAIntent);
            Intent mIntent = new Intent(localContext, CoreService.class);
            mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_WAKEUP_DEVICE);
            mStateManager.sendToCoreService(mIntent);
        }

    } else if (intent.getAction().equals(TORCH_STATE_CHANGED)) {
        if (mStateManager.getPreference().getBoolean("pref_flash_controls", false)) {
            Log.d(LOG_TAG + ".torch", "torch state changed");
            Intent mIntent = new Intent(localContext, CoreService.class);
            mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_TORCH_STATE);
            if (intent.getIntExtra("state", 0) != 0) {
                mIntent.putExtra(CoreApp.CS_EXTRA_STATE, true);
            } else {
                mIntent.putExtra(CoreApp.CS_EXTRA_STATE, false);
            }
            mStateManager.sendToCoreService(mIntent);
        } else {
            Log.d(LOG_TAG + ".torch", "torch controls are not enabled.");
        }

    } else if (intent.getAction().equals(Intent.ACTION_HEADSET_PLUG)) {
        int state = intent.getExtras().getInt("state");
        Log.d(LOG_TAG + ".headset", "headset is " + (state == 0 ? "gone" : "here") + "!");
        Intent mIntent = new Intent(localContext, CoreService.class);
        mIntent.putExtra(CoreApp.CS_EXTRA_TASK, CoreApp.CS_TASK_HEADSET_PLUG);
        mStateManager.sendToCoreService(mIntent);

    } else if (intent.getAction().equals("org.durka.hallmonitor.debug")) {
        Log.d(LOG_TAG + "", "received debug intent");
        // test intent to show/hide a notification
        boolean showhide = false;
        switch (intent.getIntExtra("notif", 0)) {
        case 1:
            showhide = true;
            break;
        case 2:
            showhide = false;
            break;
        }
        if (showhide) {
            Notification.Builder mBuilder = new Notification.Builder(localContext)
                    .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Hall Monitor")
                    .setContentText("Debugging is fun!");

            NotificationManager mNotificationManager = (NotificationManager) localContext
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(42, mBuilder.build());
        } else {
            NotificationManager mNotificationManager = (NotificationManager) localContext
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.cancel(42);
        }
    }
    mStateManager.releaseCPUGlobal();
}

From source file:com.oliversride.wordryo.UpdateCheckReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (null != intent && null != intent.getAction()
            && intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
        restartTimer(context);//w  ww  . jav  a2 s . c om
    } else {
        checkVersions(context, false);
        restartTimer(context);
    }
}