android.content.Intent#ACTION_BOOT_COMPLETED源码实例Demo

下面列出了android.content.Intent#ACTION_BOOT_COMPLETED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: adamant-android   文件: BootCompletedBroadcast.java
@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;
    }
}
 
@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;
    }
}
 
@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;
    }
}
 
/**
 * 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));
}
 
源代码5 项目: rn-heartbeat   文件: BootUpReceiver.java
@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));
    }

}
 
源代码6 项目: FreezeYou   文件: BootCompletedReceiver.java
@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;
    }
}
 
源代码7 项目: EZScreenshot   文件: MyReceiver.java
@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;
        }
    }
}
 
源代码8 项目: BetterAndroRAT   文件: MyService.java
@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();
}
 
源代码9 项目: GeometricWeather   文件: MainReceiver.java
@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;
    }
}
 
源代码10 项目: aptoide-client-v8   文件: NotificationReceiver.java
@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;
  }
}
 
源代码11 项目: Dendroid-HTTP-RAT   文件: MyService.java
@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();
}
 
源代码12 项目: NetUpDown   文件: BootReceiver.java
@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));
            }
    }
}
 
源代码13 项目: talkback   文件: BootReceiver.java
@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
  }
}
 
源代码14 项目: Trigger   文件: PersistReceiver.java
@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;
    }
}
 
源代码15 项目: OmniList   文件: AlarmsService.java
@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;
}
 
源代码16 项目: JobSchedulerCompat   文件: JobGcReceiverTest.java
@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)));
}
 
@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));
}
 
@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;
    }
}
 
源代码19 项目: opentasks   文件: TaskNotificationService.java
@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());
                        }
                    }
                }
            }
    }
}
 
源代码20 项目: RelaxFinger   文件: FloatBallReceiver.java
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;

        }
    }
 
 方法所在类
 同类方法