當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。