当前位置: 首页>>代码示例>>Java>>正文


Java Context.startService方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:AyushR1,项目名称:KernelAdiutor-Mod,代码行数:8,代码来源:Utils.java

示例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));
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:11,代码来源:WifiReceiver.java

示例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);
}
 
开发者ID:TigranSarkisian,项目名称:Boilerplate,代码行数:9,代码来源:TlIntentService.java

示例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);
    }
}
 
开发者ID:aliumujib,项目名称:Orin,代码行数:13,代码来源:BootReceiver.java

示例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);
        }
    }
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:11,代码来源:BasePlayback.java

示例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);
}
 
开发者ID:srasthofer,项目名称:FuzzDroid,代码行数:10,代码来源:BytecodeLogger.java

示例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);
}
 
开发者ID:gregoreesmaa,项目名称:minu-poska-android,代码行数:11,代码来源:LessonNotificationScheduler.java

示例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());
}
 
开发者ID:paozhuanyinyu,项目名称:FreshMember,代码行数:12,代码来源:DaemonStrategyXiaomi.java

示例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);
}
 
开发者ID:gregoreesmaa,项目名称:minu-poska-android,代码行数:15,代码来源:DataUpdateService.java

示例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));
    }
}
 
开发者ID:fekracomputers,项目名称:MuslimMateAndroid,代码行数:8,代码来源:StartUpBootReceiver.java

示例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);
    }
}
 
开发者ID:snoozinsquatch,项目名称:unity-obb-downloader,代码行数:13,代码来源:DownloaderService.java

示例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);
}
 
开发者ID:ashutoshgngwr,项目名称:10-bitClockWidget,代码行数:14,代码来源:ClockWidgetProvider.java

示例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);
    }
 
开发者ID:victordiaz,项目名称:phonk,代码行数:15,代码来源:PhonkAppHelper.java

示例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;
    }
}
 
开发者ID:shashi2459,项目名称:notify-me,代码行数:32,代码来源:HeadPhoneListener.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:6,代码来源:IntentStarter.java


注:本文中的android.content.Context.startService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。