本文整理汇总了Java中android.content.Context.startService方法的典型用法代码示例。如果您正苦于以下问题:Java Context.startService方法的具体用法?Java Context.startService怎么用?Java Context.startService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.Context
的用法示例。
在下文中一共展示了Context.startService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: onReceive
import android.content.Context; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
WifiManager wifiMgr = (WifiManager) context.getApplicationContext()
.getSystemService(Service.WIFI_SERVICE);
if (wifiMgr.isWifiEnabled()) {
context.startService(new Intent(context, DeskDroidService.class));
} else {
context.stopService(new Intent(context, DeskDroidService.class));
}
}
示例3: start
import android.content.Context; //导入方法依赖的package包/类
public static void start(Context context, String subscriber, String url,
int requestType) {
Intent intent = new Intent(context, TlIntentService.class);
intent.putExtra(Extra.SUBSCRIBER, subscriber);
intent.putExtra(Extra.URL, url);
intent.putExtra(Extra.REQUEST_TYPE, requestType);
context.startService(intent);
}
示例4: onReceive
import android.content.Context; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
final AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);
// Start music service if there are any existing widgets
if (widgetManager.getAppWidgetIds(new ComponentName(context, AppWidgetBig.class)).length > 0 ||
widgetManager.getAppWidgetIds(new ComponentName(context, AppWidgetClassic.class)).length > 0 ||
widgetManager.getAppWidgetIds(new ComponentName(context, AppWidgetSmall.class)).length > 0) {
final Intent serviceIntent = new Intent(context, MusicService.class);
context.startService(serviceIntent);
}
}
示例5: onReceive
import android.content.Context; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intent.getAction())) {
if (isPlaying()) {
Intent i=new Intent(context, MusicPlaybackService.class);
i.setAction(MediaTasks.ACTION_PAUSE);
context.startService(i);
}
}
}
示例6: reportConditionOutcome
import android.content.Context; //导入方法依赖的package包/类
public static void reportConditionOutcome(boolean decision, Context context) {
Intent serviceIntent = new Intent(context, TracingService.class);
serviceIntent.setAction(TracingService.ACTION_ENQUEUE_TRACE_ITEM);
serviceIntent.putExtra(TracingService.EXTRA_ITEM_TYPE,
TracingService.ITEM_TYPE_PATH_TRACKING);
serviceIntent.putExtra(TracingService.EXTRA_TRACE_ITEM, (Parcelable)
new PathTrackingTraceItem(getLastExecutedStatement(), decision));
context.startService(serviceIntent);
}
示例7: onReceive
import android.content.Context; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
intent.setClass(context, NotificationService.class);
// Schedule the next alarm at every show action
int lessonNumber = intent.getIntExtra(NotificationService.LESSON_NUMBER, -1);
if (intent.getAction().equals(NotificationService.ACTION_HIDE_LESSON))
setNextAlarm(context, lessonNumber, 0);
Log.d(TAG, "Forwarding notification for: " + intent.getAction());
context.startService(intent);
}
示例8: onDaemonAssistantCreate
import android.content.Context; //导入方法依赖的package包/类
@Override
public void onDaemonAssistantCreate(Context context, DaemonConfigurations configs) {
Intent intent = new Intent();
ComponentName component = new ComponentName(context.getPackageName(), configs.PERSISTENT_CONFIG.SERVICE_NAME);
intent.setComponent(component);
context.startService(intent);
if(configs != null && configs.LISTENER != null){
configs.LISTENER.onWatchDaemonDaed();
}
android.os.Process.killProcess(android.os.Process.myPid());
}
示例9: startStuudiumEventsUpdate
import android.content.Context; //导入方法依赖的package包/类
/**
* Starts this service to perform Stuudium events update. If
* the service is already performing a task this action will be queued.
*
* @see IntentService
*/
public static void startStuudiumEventsUpdate(Context context, boolean manualUpdate) {
Log.i(TAG, "Starting Stuudium events update; manual: " + manualUpdate);
Intent intent = new Intent(context, DataUpdateService.class);
intent.setAction(ACTION_UPDATE_STUUDIUM);
intent.putExtra(UPDATE_STUUDIUM_EVENTS, true);
intent.putExtra(MANUAL_UPDATE, manualUpdate);
context.startService(intent);
}
示例10: onReceive
import android.content.Context; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
MindtrackLog.add("Boot Complete");
context.startService(new Intent(context, PrayingDayCalculateHandler.class));
}
}
示例11: onReceive
import android.content.Context; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
pollNetworkState();
if (mStateChanged
&& !isServiceRunning()) {
Log.d(Constants.TAG, "InnerBroadcastReceiver Called");
Intent fileIntent = new Intent(context, mService.getClass());
fileIntent.putExtra(EXTRA_PENDING_INTENT, mPendingIntent);
// send a new intent to the service
context.startService(fileIntent);
}
}
示例12: onUpdate
import android.content.Context; //导入方法依赖的package包/类
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int appWidgetIds[]) {
// get widget ids for all available instances
int ids[] = appWidgetManager.getAppWidgetIds(
new ComponentName(context.getPackageName(), getClass().getName()));
if (ids.length == 0)
return; // No widget is added to home screen. Bailing out!
// start update service
Intent serviceIntent = new Intent(context, ClockWidgetUpdateService.class);
context.startService(serviceIntent);
}
示例13: launchScript
import android.content.Context; //导入方法依赖的package包/类
public static void launchScript(Context context, Project p) {
/*
Answers.getInstance().logContentView(new ContentViewEvent()
.putContentId("launched script"));
*/
Intent intent = new Intent(context, AppRunnerLauncherService.class);
intent.putExtra(Project.SERVER_PORT, PhonkSettings.HTTP_PORT);
intent.putExtra(Project.FOLDER, p.getFolder());
intent.putExtra(Project.NAME, p.getName());
intent.putExtra(Project.DEVICE_ID, (String) UserPreferences.getInstance().get("device_id"));
context.startService(intent);
}
示例14: handleHeadsetIntent
import android.content.Context; //导入方法依赖的package包/类
private void handleHeadsetIntent(final Context context, final Intent intent) {
int status = intent.getIntExtra("state", -1);
Intent service = new Intent(context, MyService.class);
switch (status) {
case 1:
Log.i(TAG, "onReceive: Headset plug!!!");
/*
* Start TEXT TO SPEECH service here
*/
Log.e(TAG, "onReceive: Starting Text to speech!!!");
context.startService(service);
break;
case 0:
Log.i(TAG, "onReceive: Headphone disconnected!!!");
/*
Stop TEXT TO SPEECH service here
*/
context.stopService(service);
Log.e(TAG, "onReceive: Stopping Text to speech!!!");
break;
default:
Log.i(TAG, "onReceive: Invalid state!!!");
break;
}
}
示例15: sendMailViaService
import android.content.Context; //导入方法依赖的package包/类
public void sendMailViaService(Context context, Mail mail) {
Intent i = new Intent(context, SendMailService.class);
i.putExtra(SendMailService.KEY_MAIL, mail);
context.startService(i);
}