Java Code Examples for com.google.android.exoplayer2.util.Util#startForegroundService()

The following examples show how to use com.google.android.exoplayer2.util.Util#startForegroundService() . 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: PlatformScheduler.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onStartJob(JobParameters params) {
  logd("PlatformSchedulerService started");
  PersistableBundle extras = params.getExtras();
  Requirements requirements = new Requirements(extras.getInt(KEY_REQUIREMENTS));
  if (requirements.checkRequirements(this)) {
    logd("Requirements are met");
    String serviceAction = extras.getString(KEY_SERVICE_ACTION);
    String servicePackage = extras.getString(KEY_SERVICE_PACKAGE);
    Intent intent =
        new Intent(Assertions.checkNotNull(serviceAction)).setPackage(servicePackage);
    logd("Starting service action: " + serviceAction + " package: " + servicePackage);
    Util.startForegroundService(this, intent);
  } else {
    logd("Requirements are not met");
    jobFinished(params, /* needsReschedule */ true);
  }
  return false;
}
 
Example 2
Source File: PlatformScheduler.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onStartJob(JobParameters params) {
  logd("PlatformSchedulerService started");
  PersistableBundle extras = params.getExtras();
  Requirements requirements = new Requirements(extras.getInt(KEY_REQUIREMENTS));
  if (requirements.checkRequirements(this)) {
    logd("Requirements are met");
    String serviceAction = extras.getString(KEY_SERVICE_ACTION);
    String servicePackage = extras.getString(KEY_SERVICE_PACKAGE);
    Intent intent = new Intent(serviceAction).setPackage(servicePackage);
    logd("Starting service action: " + serviceAction + " package: " + servicePackage);
    Util.startForegroundService(this, intent);
  } else {
    logd("Requirements are not met");
    jobFinished(params, /* needsReschedule */ true);
  }
  return false;
}
 
Example 3
Source File: PlatformScheduler.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onStartJob(JobParameters params) {
  logd("PlatformSchedulerService started");
  PersistableBundle extras = params.getExtras();
  Requirements requirements = new Requirements(extras.getInt(KEY_REQUIREMENTS));
  if (requirements.checkRequirements(this)) {
    logd("Requirements are met");
    String serviceAction = extras.getString(KEY_SERVICE_ACTION);
    String servicePackage = extras.getString(KEY_SERVICE_PACKAGE);
    Intent intent = new Intent(serviceAction).setPackage(servicePackage);
    logd("Starting service action: " + serviceAction + " package: " + servicePackage);
    Util.startForegroundService(this, intent);
  } else {
    logd("Requirements are not met");
    jobFinished(params, /* needsReschedule */ true);
  }
  return false;
}
 
Example 4
Source File: PlatformScheduler.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onStartJob(JobParameters params) {
  logd("PlatformSchedulerService started");
  PersistableBundle extras = params.getExtras();
  Requirements requirements = new Requirements(extras.getInt(KEY_REQUIREMENTS));
  if (requirements.checkRequirements(this)) {
    logd("Requirements are met");
    String serviceAction = extras.getString(KEY_SERVICE_ACTION);
    String servicePackage = extras.getString(KEY_SERVICE_PACKAGE);
    Intent intent =
        new Intent(Assertions.checkNotNull(serviceAction)).setPackage(servicePackage);
    logd("Starting service action: " + serviceAction + " package: " + servicePackage);
    Util.startForegroundService(this, intent);
  } else {
    logd("Requirements are not met");
    jobFinished(params, /* needsReschedule */ true);
  }
  return false;
}
 
Example 5
Source File: PlatformScheduler.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onStartJob(JobParameters params) {
  logd("PlatformSchedulerService started");
  PersistableBundle extras = params.getExtras();
  Requirements requirements = new Requirements(extras.getInt(KEY_REQUIREMENTS));
  if (requirements.checkRequirements(this)) {
    logd("Requirements are met");
    String serviceAction = extras.getString(KEY_SERVICE_ACTION);
    String servicePackage = extras.getString(KEY_SERVICE_PACKAGE);
    Intent intent =
        new Intent(Assertions.checkNotNull(serviceAction)).setPackage(servicePackage);
    logd("Starting service action: " + serviceAction + " package: " + servicePackage);
    Util.startForegroundService(this, intent);
  } else {
    logd("Requirements are not met");
    jobFinished(params, /* needsReschedule */ true);
  }
  return false;
}
 
Example 6
Source File: DownloadService.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static void startService(Context context, Intent intent, boolean foreground) {
  if (foreground) {
    Util.startForegroundService(context, intent);
  } else {
    context.startService(intent);
  }
}
 
Example 7
Source File: DownloadService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Starts the service, adding an action to be executed.
 *
 * @param context A {@link Context}.
 * @param clazz The concrete download service to be started.
 * @param downloadAction The action to be executed.
 * @param foreground Whether the service is started in the foreground.
 */
public static void startWithAction(
    Context context,
    Class<? extends DownloadService> clazz,
    DownloadAction downloadAction,
    boolean foreground) {
  Intent intent = buildAddActionIntent(context, clazz, downloadAction, foreground);
  if (foreground) {
    Util.startForegroundService(context, intent);
  } else {
    context.startService(intent);
  }
}
 
Example 8
Source File: DownloadService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Starts the service, adding an action to be executed.
 *
 * @param context A {@link Context}.
 * @param clazz The concrete download service to be started.
 * @param downloadAction The action to be executed.
 * @param foreground Whether the service is started in the foreground.
 */
public static void startWithAction(
    Context context,
    Class<? extends DownloadService> clazz,
    DownloadAction downloadAction,
    boolean foreground) {
  Intent intent = buildAddActionIntent(context, clazz, downloadAction, foreground);
  if (foreground) {
    Util.startForegroundService(context, intent);
  } else {
    context.startService(intent);
  }
}
 
Example 9
Source File: DownloadService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static void startService(Context context, Intent intent, boolean foreground) {
  if (foreground) {
    Util.startForegroundService(context, intent);
  } else {
    context.startService(intent);
  }
}
 
Example 10
Source File: DownloadService.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static void startService(Context context, Intent intent, boolean foreground) {
  if (foreground) {
    Util.startForegroundService(context, intent);
  } else {
    context.startService(intent);
  }
}
 
Example 11
Source File: DownloadService.java    From MediaSDK with Apache License 2.0 2 votes vote down vote up
/**
 * Starts the service in the foreground without adding a new download request. If there are any
 * not finished downloads and the requirements are met, the service resumes downloading. Otherwise
 * it stops immediately.
 *
 * @param context A {@link Context}.
 * @param clazz The concrete download service to be started.
 * @see #start(Context, Class)
 */
public static void startForeground(Context context, Class<? extends DownloadService> clazz) {
  Intent intent = getIntent(context, clazz, ACTION_INIT, true);
  Util.startForegroundService(context, intent);
}
 
Example 12
Source File: DownloadService.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Starts the service in the foreground without adding a new action. If there are any not finished
 * actions and the requirements are met, the service resumes executing actions. Otherwise it stops
 * immediately.
 *
 * @param context A {@link Context}.
 * @param clazz The concrete download service to be started.
 * @see #start(Context, Class)
 */
public static void startForeground(Context context, Class<? extends DownloadService> clazz) {
  Intent intent = getIntent(context, clazz, ACTION_INIT).putExtra(KEY_FOREGROUND, true);
  Util.startForegroundService(context, intent);
}
 
Example 13
Source File: DownloadService.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Starts the service in the foreground without adding a new action. If there are any not finished
 * actions and the requirements are met, the service resumes executing actions. Otherwise it stops
 * immediately.
 *
 * @param context A {@link Context}.
 * @param clazz The concrete download service to be started.
 * @see #start(Context, Class)
 */
public static void startForeground(Context context, Class<? extends DownloadService> clazz) {
  Intent intent = getIntent(context, clazz, ACTION_INIT).putExtra(KEY_FOREGROUND, true);
  Util.startForegroundService(context, intent);
}
 
Example 14
Source File: DownloadService.java    From Telegram-FOSS with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Starts the service in the foreground without adding a new download request. If there are any
 * not finished downloads and the requirements are met, the service resumes downloading. Otherwise
 * it stops immediately.
 *
 * @param context A {@link Context}.
 * @param clazz The concrete download service to be started.
 * @see #start(Context, Class)
 */
public static void startForeground(Context context, Class<? extends DownloadService> clazz) {
  Intent intent = getIntent(context, clazz, ACTION_INIT, true);
  Util.startForegroundService(context, intent);
}
 
Example 15
Source File: DownloadService.java    From Telegram with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Starts the service in the foreground without adding a new download request. If there are any
 * not finished downloads and the requirements are met, the service resumes downloading. Otherwise
 * it stops immediately.
 *
 * @param context A {@link Context}.
 * @param clazz The concrete download service to be started.
 * @see #start(Context, Class)
 */
public static void startForeground(Context context, Class<? extends DownloadService> clazz) {
  Intent intent = getIntent(context, clazz, ACTION_INIT, true);
  Util.startForegroundService(context, intent);
}