本文整理汇总了Java中android.content.Context.startForegroundService方法的典型用法代码示例。如果您正苦于以下问题:Java Context.startForegroundService方法的具体用法?Java Context.startForegroundService怎么用?Java Context.startForegroundService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Context
的用法示例。
在下文中一共展示了Context.startForegroundService方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startService
import android.content.Context; //导入方法依赖的package包/类
public static void startService(Context context, Intent intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(intent);
} else {
context.startService(intent);
}
}
示例2: startService
import android.content.Context; //导入方法依赖的package包/类
private static void startService(Context context, String command) {
final Intent intent = new Intent(context, MusicService.class);
intent.setAction(command);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(intent);
} else {
context.startService(intent);
}
}
示例3: startServicePossiblyInForeground
import android.content.Context; //导入方法依赖的package包/类
static void startServicePossiblyInForeground(Context context, Intent i) {
if (VERSION.SDK_INT >= VERSION_CODES.O) {
System.out.println(i);
context.startForegroundService(i);
} else {
context.startService(i);
}
}
示例4: enablePocketMode
import android.content.Context; //导入方法依赖的package包/类
public void enablePocketMode(Context context, boolean state) {
sp = context.getSharedPreferences(TAG2, Context.MODE_PRIVATE);
spe = sp.edit();
if(state) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(new Intent(context, ProximityService.class));
} else {
context.startService(new Intent(context, ProximityService.class));
}
spe.putBoolean(TAG,true).apply();
} else {
context.stopService(new Intent(context, ProximityService.class));
spe.putBoolean(TAG,false).apply();
}
}
示例5: onReceive
import android.content.Context; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
Log.d(TAG, "Received intent:" + intent);
// Long running tasks, like calling Account Transfer API, shouldn't happen here. Start a
// foreground service to perform long running tasks.
Intent serviceIntent = AccountTransferService.getIntent(context, intent.getAction());
if (Build.VERSION.SDK_INT >= 26) {
context.startForegroundService(serviceIntent);
} else {
context.startService(serviceIntent);
}
}
示例6: start
import android.content.Context; //导入方法依赖的package包/类
public static void start(Context context, VpnConfiguration config) {
Intent intent = new Intent(context, GnirehtetService.class);
intent.setAction(ACTION_START_VPN);
intent.putExtra(GnirehtetService.EXTRA_VPN_CONFIGURATION, config);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(intent);
} else {
context.startService(intent);
}
}
示例7: startDownload
import android.content.Context; //导入方法依赖的package包/类
public static void startDownload(@NonNull Context context,
@NonNull HashMap<String, File> downloads) {
Intent intent = new Intent(context, ModelDownloadService.class);
intent.putExtra(ARG_DOWNLOAD, downloads);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O) {
context.startService(intent);
} else {
context.startForegroundService(intent);
}
}
示例8: onReceive
import android.content.Context; //导入方法依赖的package包/类
@Override
public void onReceive(final Context context, Intent intent) {
// Start service on boot only if the user has said yes in the app.
final SharedPreferences sp = context.getSharedPreferences(TAG2, Context.MODE_PRIVATE);
final boolean returnFromSp = sp.getBoolean(TAG2, false);
if(DEBUG) Log.i(TAG2, String.valueOf(returnFromSp));
if (returnFromSp) {
if(DEBUG) Log.d(TAG, "Starting");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(new Intent(context, ProximityService.class));
} else {
context.startService(new Intent(context, ProximityService.class));
}
}
boolean applyOnBoot = sp.getBoolean("ApplyOnBoot",false);
if(applyOnBoot) {
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
RootUtil r = new RootUtil();
boolean returnVal = sp.getBoolean("dt2w",false);
if(returnVal)
r.echo(dt2wSysfsNode,"1");
else
r.echo(dt2wSysfsNode,"0");
returnVal = sp.getBoolean("vdt2w",false);
if(returnVal)
r.echo(vibrateDt2wSysfsNode,"1");
else
r.echo(dt2wSysfsNode,"0");
returnVal = sp.getBoolean("bcl",false);
if(DEBUG) Log.i("bcl",String.valueOf(returnVal));
if(returnVal)
r.echo(bclSysfsNode,"-n 'enable'");
else
r.echo(bclSysfsNode,"-n 'disable'");
r.echo("backlightModeSysfsNode", String.valueOf(sp.getInt("backlightMode",0)));
r.echo("backlightTimeSysfsNode", String.valueOf(sp.getInt("time",0)));
Toast.makeText(context, "BKT Boot Settings applied",Toast.LENGTH_SHORT).show();
}
},10000);
}
}