com.google.android.exoplayer2.util.Util.startForegroundService()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(2.6k)|赞(0)|评价(0)|浏览(222)

本文整理了Java中com.google.android.exoplayer2.util.Util.startForegroundService()方法的一些代码示例,展示了Util.startForegroundService()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.startForegroundService()方法的具体详情如下:
包路径:com.google.android.exoplayer2.util.Util
类名称:Util
方法名:startForegroundService

Util.startForegroundService介绍

[英]Calls Context#startForegroundService(Intent) if #SDK_INT is 26 or higher, or Context#startService(Intent) otherwise.
[中]如果#SDK_INT为26或更高,则调用Context#startForegroundsService(Intent),否则调用Context#startService(Intent)。

代码示例

代码示例来源:origin: google/ExoPlayer

  1. /**
  2. * Starts the service in the foreground without adding a new action. If there are any not finished
  3. * actions and the requirements are met, the service resumes executing actions. Otherwise it stops
  4. * immediately.
  5. *
  6. * @param context A {@link Context}.
  7. * @param clazz The concrete download service to be started.
  8. * @see #start(Context, Class)
  9. */
  10. public static void startForeground(Context context, Class<? extends DownloadService> clazz) {
  11. Intent intent = getIntent(context, clazz, ACTION_INIT).putExtra(KEY_FOREGROUND, true);
  12. Util.startForegroundService(context, intent);
  13. }

代码示例来源:origin: google/ExoPlayer

  1. /**
  2. * Starts the service, adding an action to be executed.
  3. *
  4. * @param context A {@link Context}.
  5. * @param clazz The concrete download service to be started.
  6. * @param downloadAction The action to be executed.
  7. * @param foreground Whether the service is started in the foreground.
  8. */
  9. public static void startWithAction(
  10. Context context,
  11. Class<? extends DownloadService> clazz,
  12. DownloadAction downloadAction,
  13. boolean foreground) {
  14. Intent intent = buildAddActionIntent(context, clazz, downloadAction, foreground);
  15. if (foreground) {
  16. Util.startForegroundService(context, intent);
  17. } else {
  18. context.startService(intent);
  19. }
  20. }

代码示例来源:origin: google/ExoPlayer

  1. @Override
  2. public boolean onStartJob(JobParameters params) {
  3. logd("PlatformSchedulerService started");
  4. PersistableBundle extras = params.getExtras();
  5. Requirements requirements = new Requirements(extras.getInt(KEY_REQUIREMENTS));
  6. if (requirements.checkRequirements(this)) {
  7. logd("Requirements are met");
  8. String serviceAction = extras.getString(KEY_SERVICE_ACTION);
  9. String servicePackage = extras.getString(KEY_SERVICE_PACKAGE);
  10. Intent intent = new Intent(serviceAction).setPackage(servicePackage);
  11. logd("Starting service action: " + serviceAction + " package: " + servicePackage);
  12. Util.startForegroundService(this, intent);
  13. } else {
  14. logd("Requirements are not met");
  15. jobFinished(params, /* needsReschedule */ true);
  16. }
  17. return false;
  18. }

代码示例来源:origin: sschueller/peertube-android

  1. private void startPlayer() {
  2. Util.startForegroundService(Objects.requireNonNull(getContext()), videoPlayerIntent);
  3. }

相关文章