Java Code Examples for android.content.Intent#ACTION_BOOT_COMPLETED

The following examples show how to use android.content.Intent#ACTION_BOOT_COMPLETED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BootCompletedBroadcast.java    From adamant-android with GNU General Public License v3.0 7 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    AndroidInjection.inject(this, context);

    if (intent == null || intent.getAction() == null) { return; }

    switch (intent.getAction()) {
        case Intent.ACTION_LOCKED_BOOT_COMPLETED:
        case Intent.ACTION_BOOT_COMPLETED:
            PushNotificationServiceFacade currentFacade = switchPushNotificationServiceInteractor.getCurrentFacade();
            boolean isCurrentLocalService = currentFacade != null && SupportedPushNotificationFacadeType.LOCAL_SERVICE.equals(currentFacade.getFacadeType());
            if (isCurrentLocalService) {
                Intent i = new Intent(context, AdamantLocalMessagingService.class);

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                    context.startForegroundService(i);
                } else {
                    context.startService(i);
                }
            }
            break;
    }
}
 
Example 2
Source File: LocationUpdateReceiver.java    From home-assistant-Android with GNU General Public License v3.0 7 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    prefs = Utils.getPrefs(context);
    switch (intent.getAction()) {
        case Intent.ACTION_BOOT_COMPLETED:
        case ACTION_START_LOCATION:
            tempContext = context;
            apiClient = new LostApiClient.Builder(context)
                    .addConnectionCallbacks(this)
                    .build();

            apiClient.connect();
            break;
        case ACTION_LOCATION_UPDATE:
            if (prefs.getBoolean(Common.PREF_ENABLE_LOCATION_TRACKING, false) && LocationResult.hasResult(intent)) {
                LocationResult result = LocationResult.extractResult(intent);
                Location location = result.getLastLocation();
                if (location != null)
                    logLocation(location, context);
            }
            break;
    }
}
 
Example 3
Source File: LocationUpdateReceiver.java    From home-assistant-Android with GNU General Public License v3.0 7 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    prefs = Utils.getPrefs(context);
    switch (intent.getAction()) {
        case Intent.ACTION_BOOT_COMPLETED:
        case ACTION_START_LOCATION:
            apiClient = new GoogleApiClient.Builder(context)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .addApi(LocationServices.API)
                    .build();

            apiClient.connect();
            break;
        case ACTION_LOCATION_UPDATE:
            if (prefs.getBoolean(Common.PREF_ENABLE_LOCATION_TRACKING, false) && LocationResult.hasResult(intent)) {
                LocationResult result = LocationResult.extractResult(intent);
                Location location = result.getLastLocation();
                if (location != null)
                    logLocation(location, context);
            }
            break;
    }
}
 
Example 4
Source File: WifiPeriodicReplicationReceiverTest.java    From sync-android with Apache License 2.0 6 votes vote down vote up
/**
 * Check that when {@link WifiPeriodicReplicationReceiver} receives
 * {@link Intent#ACTION_BOOT_COMPLETED}, the wasOnWifi flag is set to false and
 * an {@link Intent} is sent out to start the Service
 * {@link ReplicationService} associated with
 * {@link WifiPeriodicReplicationReceiver} containing the extra
 * {@link ReplicationService#EXTRA_COMMAND} with the value
 * {@link PeriodicReplicationService#COMMAND_DEVICE_REBOOTED}.
 */
@Test
public void testBootCompleted() {
    Intent intent = new Intent(Intent.ACTION_BOOT_COMPLETED);

    mMockPreferencesEditor = mock(SharedPreferences.Editor.class);
    when(mMockPreferences.edit()).thenReturn(mMockPreferencesEditor);

    mReceiver.onReceive(mMockContext, intent);
    verify(mMockPreferencesEditor, times(1)).putBoolean(ReplicationService.class.getName() + ".wasOnWifi",
            false);
    assertEquals(1, mMockContext.getIntentsReceived().size());

    Intent receivedIntent = mMockContext.getIntentsReceived().get(0);
    assertEquals(ReplicationService.class.getName(), receivedIntent.getComponent().getClassName());
    assertNull(receivedIntent.getAction());
    assertEquals(PeriodicReplicationService.COMMAND_DEVICE_REBOOTED, receivedIntent.getIntExtra(ReplicationService.EXTRA_COMMAND, ReplicationService.COMMAND_NONE));
}
 
Example 5
Source File: BootUpReceiver.java    From rn-heartbeat with MIT License 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if(intent.getAction() == Intent.ACTION_BOOT_COMPLETED){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            //log("Starting the service in >=26 Mode from a BroadcastReceiver")
            context.startForegroundService(new Intent(context, HeartbeartService.class));
            return;
        }
        //log("Starting the service in < 26 Mode from a BroadcastReceiver")
        context.startService(new Intent(context, HeartbeartService.class));
    }

}
 
Example 6
Source File: PersistReceiver.java    From Trigger with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    switch (action) {
        case Trigger.DEBUG_DEVICE_ON_B:
            if (!Trigger.DEBUG)
                break;
        case Intent.ACTION_BOOT_COMPLETED:
            context.startService(TriggerLoop.deviceOn(context));
            break;
        default:
            break;
    }
}
 
Example 7
Source File: BootCompletedReceiver.java    From FreezeYou with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {

    if (intent == null || intent.getAction() == null) {
        return;
    }

    switch (intent.getAction()) {
        case Intent.ACTION_BOOT_COMPLETED:
            runBackgroundService(context);
            checkAndReNotifyNotifications(context);
            checkTasks(context);
            break;
        case Intent.ACTION_MY_PACKAGE_REPLACED:
            runBackgroundService(context);
            checkAndReNotifyNotifications(context);
            checkTasks(context);
            cleanExternalCache(context);

            final SharedPreferences sharedPreferences =
                    context.getSharedPreferences("Ver", Context.MODE_PRIVATE);
            if (sharedPreferences.getInt("Ver", 0) < VersionUtils.getVersionCode(context)) {
                clearCrashLogs();
            }

            break;
        default:
            break;
    }
}
 
Example 8
Source File: MyReceiver.java    From EZScreenshot with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(final Context context, final Intent intent) {
    switch (intent.getAction()) {
        case Intent.ACTION_BOOT_COMPLETED: {
            if (SettingHelper.shouldStartServiceOnBoot()){
                MyService.startService(context);
            }
            break;
        }
    }
}
 
Example 9
Source File: BootReceiver.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
  TalkBackService service = TalkBackService.getInstance();
  if (service == null) {
    return;
  }

  EventId eventId = EVENT_ID_UNTRACKED; // Not a user-initiated event.

  // 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(eventId);
      break;
    case Intent.ACTION_BOOT_COMPLETED:
      if (!BuildVersionUtils.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(eventId);
      }
      service.onUnlockedBootCompleted();
      break;
    default: // fall out
  }
}
 
Example 10
Source File: MyService.java    From BetterAndroRAT with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
     IntentFilter filterBoot = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
     filterBoot.addAction(Intent.ACTION_SCREEN_OFF);
     mReceiver = new ServiceReceiver();
     registerReceiver(mReceiver, filterBoot);
     super.onCreate();
      	PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putLong("inacall", 0).commit();
}
 
Example 11
Source File: MainReceiver.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (TextUtils.isEmpty(action)) {
        return;
    }
    switch (action) {
        case Intent.ACTION_BOOT_COMPLETED:
        case Intent.ACTION_WALLPAPER_CHANGED:
            IntentHelper.startAwakeForegroundUpdateService(context);
            break;
    }
}
 
Example 12
Source File: NotificationReceiver.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
@Override public void onReceive(Context context, Intent intent) {
  notificationPublishRelay =
      ((AptoideApplication) context.getApplicationContext()).getNotificationsPublishRelay();
  Bundle intentExtras = intent.getExtras();
  NotificationInfo notificationInfo;
  NotificationManager manager =
      (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
  Intent closeIntent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);

  switch (intent.getAction()) {
    case Intent.ACTION_BOOT_COMPLETED:
      notificationInfo = new NotificationInfo(Intent.ACTION_BOOT_COMPLETED);
      notificationPublishRelay.call(notificationInfo);
      break;
    case NOTIFICATION_PRESSED_ACTION:
      notificationInfo = new NotificationInfo(NOTIFICATION_PRESSED_ACTION,
          intentExtras.getInt(NOTIFICATION_NOTIFICATION_ID),
          intentExtras.getString(NOTIFICATION_TRACK_URL),
          intentExtras.getString(NOTIFICATION_TARGET_URL));
      manager.cancel(intent.getIntExtra(NOTIFICATION_NOTIFICATION_ID, -1));
      context.sendBroadcast(closeIntent);
      notificationPublishRelay.call(notificationInfo);
      break;
    case NOTIFICATION_DISMISSED_ACTION:
      notificationInfo = new NotificationInfo(NOTIFICATION_DISMISSED_ACTION,
          intentExtras.getInt(NOTIFICATION_NOTIFICATION_ID),
          intentExtras.getString(NOTIFICATION_TRACK_URL),
          intentExtras.getString(NOTIFICATION_TARGET_URL));
      manager.cancel(intent.getIntExtra(NOTIFICATION_NOTIFICATION_ID, -1));
      notificationPublishRelay.call(notificationInfo);
      break;
  }
}
 
Example 13
Source File: MyService.java    From Dendroid-HTTP-RAT with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate() {
     IntentFilter filterBoot = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
     filterBoot.addAction(Intent.ACTION_SCREEN_OFF);
     mReceiver = new ServiceReceiver();
     registerReceiver(mReceiver, filterBoot);
     super.onCreate();
      	PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putLong("inacall", 0).commit();
}
 
Example 14
Source File: BootReceiver.java    From NetUpDown with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
        case Intent.ACTION_BOOT_COMPLETED:
            if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("run", false)) {
                context.startService(new Intent(context, NetTrafficService.class));
            }
    }
}
 
Example 15
Source File: AlarmsService.java    From OmniList with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    String action = intent.getAction();
    if (action == null) {
        throw new IllegalArgumentException("Illegal action");
    }

    switch (action){
        case Intent.ACTION_BOOT_COMPLETED:
            LogUtils.d("onStartCommand: " + "android.intent.action.BOOT_COMPLETED");
            alarmsManager.registerAllAlarms();
            break;
        case Intent.ACTION_TIMEZONE_CHANGED:
            LogUtils.d("onStartCommand: " + "android.intent.action.TIMEZONE_CHANGED");
            alarmsManager.registerAllAlarms();
            break;
        case Intent.ACTION_LOCALE_CHANGED:
            LogUtils.d("onStartCommand: " + "android.intent.action.LOCALE_CHANGED");
            alarmsManager.registerAllAlarms();
            break;
        case Intent.ACTION_TIME_CHANGED:
            LogUtils.d("onStartCommand: " + "android.intent.action.TIME_SET");
            alarmsManager.registerAllAlarms();
            break;
    }

    int code = -1;
    try {
        code = intent.getIntExtra(Constants.EXTRA_CODE, -1);
        switch (action) {
            case PresentationToModelIntents.ACTION_REQUEST_SNOOZE:
                alarmsManager.snooze(code, null);
                break;
            case PresentationToModelIntents.ACTION_REQUEST_DISMISS:
                alarmsManager.dismiss(code);
                break;
        }
    } catch (AlarmNotFoundException e) {
        LogUtils.d("onStartCommand: Alarm not found [ code:" + code + "]");
    }
    return START_NOT_STICKY;
}
 
Example 16
Source File: TaskNotificationService.java    From opentasks with Apache License 2.0 4 votes vote down vote up
@Override
protected void onHandleWork(@NonNull Intent intent)
{
    switch (intent.getAction())
    {
        case Intent.ACTION_MY_PACKAGE_REPLACED:
        case Intent.ACTION_BOOT_COMPLETED:
            /*
             When the device boots up or the app has been updated we just repost all notifications.
             */
            for (String uri : mNotificationPrefs.getAll().keySet())
            {
                ActionService.startAction(this, ActionService.ACTION_RENOTIFY, Uri.parse(uri));
            }
            break;
        default:
            /*
             * In any other case we synchronize our stored state with the database.
             *
             * Notifications of tasks which no longer exist are removed.
             * Notifications of tasks which have been pinned are added.
             * Notifications of tasks which have been unpinned are removed.
             * Notifications of tasks which have changed otherwise are updated.
             */
            String authority = getString(R.string.opentasks_authority);

            Iterable<TaskNotificationState> currentNotifications = new org.dmfs.tasks.utils.Sorted<>(
                    (o, o2) -> (int) (ContentUris.parseId(o.instance()) - ContentUris.parseId(o2.instance())),
                    new Mapped<>(
                            PrefState::new,
                            mNotificationPrefs.getAll().entrySet()));

            for (Pair<Optional<TaskNotificationState>, Optional<RowState>> diff : new Diff<>(
                    currentNotifications,
                    new Mapped<>(snapShot -> new RowState(authority, snapShot.values()),
                            new QueryRowSet<>(
                                    new Sorted<>(TaskContract.Instances._ID,
                                            new InstancesView<>(authority, getContentResolver().acquireContentProviderClient(authority))),
                                    new Composite<>(Id.PROJECTION, TaskVersion.PROJECTION, TaskPin.PROJECTION, TaskIsClosed.PROJECTION,
                                            EffectiveDueDate.PROJECTION, TaskStart.PROJECTION),
                                    new AnyOf<>(
                                            // task is either pinned or has a notification
                                            new EqArg<>(Tasks.PINNED, 1),
                                            new In<>(Tasks._ID, new Mapped<>(p -> ContentUris.parseId(p.instance()), currentNotifications))))),
                    (o, o2) -> (int) (ContentUris.parseId(o.instance()) - ContentUris.parseId(o2.instance()))))
            {
                if (!diff.left().isPresent())
                {
                    // new task not notified yet, must be pinned
                    ActionService.startAction(this, ActionService.ACTION_RENOTIFY, diff.right().value().instance());
                }
                else if (!diff.right().isPresent())
                {
                    // task no longer present, remove notification
                    removeTaskNotification(diff.left().value().instance());
                }
                else
                {
                    if (diff.left().value().taskVersion() != diff.right().value().taskVersion())
                    {
                        // the task has been updated -> update the notification if necessary
                        StateInfo before = diff.left().value().info();
                        StateInfo now = diff.right().value().info();
                        if (!now.pinned() && // don't remove pinned notifications
                                (before.pinned() // pin was removed
                                        || before.started() && !now.started() // start was deferred or removed
                                        || !now.started() && before.due() && !now.due() // due was deferred or removed
                                        || !before.done() && now.done() // task was closed
                                ))
                        {
                            // notification is obsolete
                            removeTaskNotification(diff.left().value().instance());
                        }
                        else
                        {
                            // task was updated, also update the notification
                            ActionService.startAction(this, ActionService.ACTION_RENOTIFY, diff.left().value().instance());
                        }
                    }
                }
            }
    }
}
 
Example 17
Source File: LauncherNotificationReceiver.java    From leanback-homescreen-channels with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {

    Bundle extras = intent.getExtras();

    switch (intent.getAction()) {
        case TvContractCompat.ACTION_PREVIEW_PROGRAM_BROWSABLE_DISABLED:
            // Notice that the user has removed a preview program.
            // The app should remove the program from the channel and should never publish it
            // again. The app could use this as an indication that the user is no longer
            // interested in watching this type of content.
            Log.d(TAG, "preview program browsable disabled");
            break;
        case TvContractCompat.ACTION_WATCH_NEXT_PROGRAM_BROWSABLE_DISABLED:
            // Notice that the user has removed a program from the watch next list.
            Log.d(TAG, "watch next program browsable disabled");
            break;
        case TvContractCompat.ACTION_PREVIEW_PROGRAM_ADDED_TO_WATCH_NEXT:
            // Notice that the user has added a preview program to their watch next list. Use
            // this information to update internal data structures or as an indication of the
            // user's interest in this type of programming.
            // From that point on, the app is responsible for this program and should treat it
            // like other programs in a channel.
            Log.d(TAG, "preview program added to watch next   preview " +
                    extras.getString(TvContractCompat.EXTRA_PREVIEW_PROGRAM_ID)
                    + "  watch-next "
                    + extras.getString(TvContractCompat.EXTRA_WATCH_NEXT_PROGRAM_ID));
            break;
        case Intent.ACTION_BOOT_COMPLETED:
            // Notice that the device has just finished booting. Use this opportunity to publish
            // the initial list of channels to the launcher. This intent is useful for the
            // preinstalled apps on the device. Apps that can be installed from the Play Store
            // should use ACTION_INITIALIZE_PROGRAMS as the signal to start posting their
            // channels.
            Log.d(TAG, "ACTION_BOOT_COMPLETED received");
            break;
        case TvContractCompat.ACTION_INITIALIZE_PROGRAMS:
            // Notice that the app was just installed from the Play Store. Use this opportunity
            // to publish the initial list of channels to the launcher. This intent is useful
            // for apps that don't come "pre-installed" and are installed via Play Store.
            Log.d(TAG, "ACTION_INITIALIZE_PROGRAMS received");
            break;
    }
}
 
Example 18
Source File: DeviceEventUpdatesProvider.java    From PrivacyStreams with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String event = null;
    String type = null;

    switch(intent.getAction()){
        case Intent.ACTION_SCREEN_OFF:
            event = DeviceEvent.EVENT_SCREEN_OFF;
            type = DeviceEvent.TYPE_SCREEN;
            break;

        case Intent.ACTION_SCREEN_ON:
            event = DeviceEvent.EVENT_SCREEN_ON;
            type = DeviceEvent.TYPE_SCREEN;
            break;

        case Intent.ACTION_USER_PRESENT:
            event = DeviceEvent.EVENT_SCREEN_USER_PRESENT;
            type = DeviceEvent.TYPE_SCREEN;
            break;

        case Intent.ACTION_BOOT_COMPLETED:
            event = DeviceEvent.EVENT_BOOT_COMPLETED;
            type = DeviceEvent.TYPE_BOOT;
            break;

        case Intent.ACTION_SHUTDOWN:
            event = DeviceEvent.EVENT_BOOT_SHUTDOWN;
            type = DeviceEvent.TYPE_BOOT;
            break;

        case Intent.ACTION_BATTERY_LOW:
            event = DeviceEvent.EVENT_BATTERY_LOW;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case Intent.ACTION_BATTERY_OKAY:
            event = DeviceEvent.EVENT_BATTERY_OKAY;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case Intent.ACTION_POWER_CONNECTED:
            event = DeviceEvent.EVENT_BATTERY_AC_CONNECTED;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case Intent.ACTION_POWER_DISCONNECTED:
            event = DeviceEvent.EVENT_BATTERY_AC_DISCONNECTED;
            type = DeviceEvent.TYPE_BATTERY;
            break;

        case AudioManager.RINGER_MODE_CHANGED_ACTION:
            AudioManager am = (AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE);
            switch (am.getRingerMode()) {
                case AudioManager.RINGER_MODE_SILENT:
                    event = DeviceEvent.EVENT_RINGER_SILENT;
                    type = DeviceEvent.TYPE_RINGER;
                    break;

                case AudioManager.RINGER_MODE_VIBRATE:
                    event = DeviceEvent.EVENT_RINGER_VIBRATE;
                    type = DeviceEvent.TYPE_RINGER;
                    break;

                case AudioManager.RINGER_MODE_NORMAL:
                    event = DeviceEvent.EVENT_RINGER_NORMAL;
                    type = DeviceEvent.TYPE_RINGER;
                    break;
            }
        default:
            break;
    }

    if (type != null)
        output(new DeviceEvent(type, event));
}
 
Example 19
Source File: JobGcReceiverTest.java    From JobSchedulerCompat with MIT License 4 votes vote down vote up
@Test
public void testBootReceiverRegistered() {
    Intent intent = new Intent(Intent.ACTION_BOOT_COMPLETED);
    List<BroadcastReceiver> receivers = shadowOf(application).getReceiversForIntent(intent);
    assertThat(receivers, hasItem(isA(JobGcReceiver.class)));
}
 
Example 20
Source File: FloatBallReceiver.java    From RelaxFinger with GNU General Public License v2.0 3 votes vote down vote up
public void onReceive(Context context, Intent intent) {


        mContext = context;

        sp = FloatingBallUtils.getSharedPreferences();

        String action = intent.getAction();

        switch (action){

            case Intent.ACTION_BOOT_COMPLETED:

                /*if(sp.getBoolean("autoStartSwitch",false) && sp.getBoolean("floatSwitch", false)){

                    sendMsg(Config.FLOAT_SWITCH, "ballstate", true);
                }*/

                if(sp.getBoolean("floatSwitch", false)){


                    sendMsg(Config.FLOAT_SWITCH, "ballstate", true);
                }
                break;
            default:
                break;

        }
    }