本文整理了Java中com.google.android.exoplayer2.util.Util.startForegroundService()
方法的一些代码示例,展示了Util.startForegroundService()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.startForegroundService()
方法的具体详情如下:
包路径:com.google.android.exoplayer2.util.Util
类名称: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
/**
* 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);
}
代码示例来源:origin: google/ExoPlayer
/**
* 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);
}
}
代码示例来源:origin: google/ExoPlayer
@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;
}
代码示例来源:origin: sschueller/peertube-android
private void startPlayer() {
Util.startForegroundService(Objects.requireNonNull(getContext()), videoPlayerIntent);
}
内容来源于网络,如有侵权,请联系作者删除!