android.content.Context#startService ( )源码实例Demo

下面列出了android.content.Context#startService ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pjsip-android   文件: SipServiceCommand.java
/**
 * Adds a new SIP account.
 * @param context application context
 * @param sipAccount sip account data
 * @return sip account ID uri as a string
 */
public static String setAccount(Context context, SipAccountData sipAccount) {
    if (sipAccount == null) {
        throw new IllegalArgumentException("sipAccount MUST not be null!");
    }

    String accountID = sipAccount.getIdUri();
    checkAccount(accountID);

    Intent intent = new Intent(context, SipService.class);
    intent.setAction(ACTION_SET_ACCOUNT);
    intent.putExtra(PARAM_ACCOUNT_DATA, sipAccount);
    context.startService(intent);

    return accountID;
}
 
源代码2 项目: BigApp_Discuz_Android   文件: ServiceManager.java
public void startService(final Context context, final Service... services) {

        Thread serviceThread = new Thread(new Runnable() {
            @Override
            public void run() {
                for (Service s : services) {

                    if (!ServiceUtils.isServiceRunning(context, s.getClass()
                            .getName())) {

                        Intent i = new Intent(context, s.getClass());
                        context.startService(i);

                        ZogUtils.printLog(ServiceManager.class,
                                "start service " + s.getClass().getName());
                    }

                }
            }
        });
        serviceThread.start();
    }
 
源代码3 项目: BackPackTrackII   文件: Proximity.java
public static void setAlert(long id, double latitude, double longitude, long radius, Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M ||
            context.checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
        Intent proximity = new Intent(context, BackgroundService.class);
        proximity.setAction(BackgroundService.ACTION_PROXIMITY);
        proximity.putExtra(BackgroundService.EXTRA_WAYPOINT, id);
        PendingIntent pi = PendingIntent.getService(context, 100 + (int) id, proximity, PendingIntent.FLAG_UPDATE_CURRENT);
        LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        Log.i(TAG, "Set proximity waypoint=" + id + " radius=" + radius);
        if (radius == 0) {
            lm.removeProximityAlert(pi);

            // Send proximity exit
            Intent exit = new Intent(context, BackgroundService.class);
            exit.setAction(BackgroundService.ACTION_PROXIMITY);
            exit.putExtra(LocationManager.KEY_PROXIMITY_ENTERING, false);
            exit.putExtra(BackgroundService.EXTRA_WAYPOINT, id);
            context.startService(exit);
        } else
            lm.addProximityAlert(latitude, longitude, radius, -1, pi);

        new DatabaseHelper(context).setProximity(id, radius).close();
    }
}
 
源代码4 项目: deskcon-android   文件: EventBroadcastReceiver.java
private void startServiceCommand(Context context, String cmd, String mess) {			
	Intent i = new Intent(context, StatusUpdateService.class);
	i.putExtra("commandtype", cmd);
	i.putExtra("message", mess);

	context.startService(i);
}
 
源代码5 项目: imsdk-android   文件: MixPushClient.java
@Override
public void onNotificationMessageClicked(Context context, MixPushMessage message) {
    message.setNotify(1);
    Intent intent = new Intent(MixPushMessageReceiver.NOTIFICATION_CLICKED);
    intent.putExtra(MixPushMessageReceiver.MESSAGE, message);
    context.sendBroadcast(intent, sReceiverPermission);
    Log.d("onNotificationClicked", message.getContent());

    if (sMixPushIntentServiceClass != null){
        intent.setClass(context,sMixPushIntentServiceClass);
        context.startService(intent);
    }
}
 
源代码6 项目: Movie-Check   文件: UpcomingMoviesWidget.java
@Override
public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, int[] appWidgetIds) {

    Intent intent = new Intent(context.getApplicationContext(), UpcomingMovieUpdateService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);

    context.startService(intent);
}
 
源代码7 项目: xDrip   文件: WakeLockTrampoline.java
/**
 * When we receive the broadcast callback we extract the required service and start it.
 * The framework only releases the wakelock when onReceive returns.
 */

@SuppressWarnings("ConstantConditions")
@Override
public void onReceive(final Context context, final Intent broadcastIntent) {
    JoH.getWakeLock(TAG, 1000); // deliberately not released
    final String serviceName = broadcastIntent.getStringExtra(SERVICE_PARAMETER);

    UserError.Log.d(TAG, "Trampoline ignition for: " + serviceName);
    if (serviceName == null) {
        UserError.Log.wtf(TAG, "Incorrectly passed pending intent with null service parameter!");
        return;
    }
    final Class serviceClass = getClassFromName(serviceName);
    if (serviceClass == null) {
        UserError.Log.wtf(TAG, "Could not resolve service class for: " + serviceName);
        return;
    }

    final Intent serviceIntent = new Intent(context, serviceClass);
    final String function = broadcastIntent.getStringExtra("function");
    if (function != null) serviceIntent.putExtra("function", function);

    ComponentName startResult;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
            && BuildConfig.targetSDK >= Build.VERSION_CODES.N
            && ForegroundServiceStarter.shouldRunCollectorInForeground()) {
        try {
            UserError.Log.d(TAG, String.format("Starting oreo foreground service: %s", serviceIntent.getComponent().getClassName()));
        } catch (NullPointerException e) {
            UserError.Log.d(TAG, "Null pointer exception in startServiceCompat");
        }
        startResult = context.startForegroundService(serviceIntent);
    } else {
        startResult = context.startService(serviceIntent);
    }
    if (D) UserError.Log.d(TAG, "Start result: " + startResult);

}
 
@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);
    }
}
 
源代码9 项目: xDrip   文件: SyncingService.java
/**
 * Starts this service to perform action Single Sync with the given parameters. If
 * the service is already performing a task this action will be queued.
 *
 * @see IntentService
 */
public static void startActionSingleSync(Context context, int numOfPages) {
    Intent intent = new Intent(context, SyncingService.class);
    intent.setAction(ACTION_SYNC);
    intent.putExtra(SYNC_PERIOD, numOfPages);
    context.startService(intent);
}
 
源代码10 项目: a   文件: ReadAloudService.java
/**
 * @param context 停止ForReplace
 */
public static void stopForReplace(Context context) {
    if (running) {
        Intent intent = new Intent(context, ReadAloudService.class);
        intent.setAction(ActionDoneService);
        intent.putExtra("replace","1");
        context.startService(intent);
    }
}
 
源代码11 项目: splitapkinstall   文件: MyIntentService.java
/**
 * Starts this service to perform action Foo with the given parameters. If
 * the service is already performing a task this action will be queued.
 *
 * @see IntentService
 */
// TODO: Customize helper method
public static void startActionExtractApk(Context context, String param1, HashMap<String, List<String>> packageNameToSplitApksMapping) {
    Intent intent = new Intent(context, MyIntentService.class);
    intent.setAction(ACTION_EXPORT_APK);
    intent.putExtra(PACKAGENAME, param1);
    intent.putExtra(PACKAGE_NAME_TO_SPLIT_APKS_MAPPING, packageNameToSplitApksMapping);
    context.startService(intent);
}
 
源代码12 项目: pjsip-android   文件: SipServiceCommand.java
/**
 * Mutes and Un-Mutes video for a call. If the call does not exist or has been terminated, a disconnected
 * state will be sent to
 * {@link BroadcastEventReceiver#onCallState(String, int, pjsip_inv_state, pjsip_status_code, long, boolean, boolean, boolean)}
 * @param context application context
 * @param accountID account ID
 * @param callID call ID
 * @param mute whether to mute or un-mute the video
 */
public static void setVideoMute(Context context, String accountID, int callID, boolean mute) {
    checkAccount(accountID);

    Intent intent = new Intent(context, SipService.class);
    intent.setAction(ACTION_SET_VIDEO_MUTE);
    intent.putExtra(PARAM_ACCOUNT_ID, accountID);
    intent.putExtra(PARAM_CALL_ID, callID);
    intent.putExtra(PARAM_VIDEO_MUTE, mute);
    context.startService(intent);
}
 
@Override
public void onReceive(Context context, Intent intent) {
    NetworkInfo network = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE))
            .getActiveNetworkInfo();

    if (network != null && network.isConnected()) {
        if (Settings.needToRegister(context)) {
            context.startService(new Intent(context, RegistrationIntentService.class));
        }
    }
}
 
源代码14 项目: AndroidChromium   文件: NotificationService.java
@Override
public void onReceive(Context context, Intent intent) {
    Log.i(TAG, "Received a notification intent in the NotificationService's receiver.");

    // TODO(peter): Do we need to acquire a wake lock here?

    intent.setClass(context, NotificationService.class);
    context.startService(intent);
}
 
public static void start(Context context, QBChatDialog chatDialog) {
    Intent intent = new Intent(QBServiceConsts.LEAVE_GROUP_DIALOG_ACTION, null, context, QBService.class);
    intent.putExtra(QBServiceConsts.EXTRA_DIALOG, chatDialog);
    context.startService(intent);
}
 
源代码16 项目: edslite   文件: FileOpsServiceBase.java
public static void cancelTask(Context context)
{
	Intent i = new Intent(context, FileOpsService.class);
	i.setAction(ACTION_CANCEL_TASK);
	context.startService(i);
}
 
源代码17 项目: fanfouapp-opensource   文件: QueueService.java
public static void start(final Context context) {
    context.startService(new Intent(context, QueueService.class));
}
 
源代码18 项目: PinyinSearchLibrary   文件: AppSearchService.java
public static void startAppSearchService(Context context){
	Intent intent=new Intent(context,AppSearchService.class);
	intent.setAction(AppSearchService.ACTION_APP_SEARCH_SERVICE);
	context.startService(intent);
	
	
}
 
源代码19 项目: SmsRadar   文件: SmsRadar.java
/**
 * Starts the service and store the listener to be notified when a new incoming or outgoing sms be processed
 * inside the SMS content provider
 *
 * @param context used to start the service
 * @param smsListener to notify when the sms content provider gets a new sms
 */
public static void initializeSmsRadarService(Context context, SmsListener smsListener) {
	SmsRadar.smsListener = smsListener;
	Intent intent = new Intent(context, SmsRadarService.class);
	context.startService(intent);
}
 
源代码20 项目: hprof-tools   文件: CruncherService.java
/**
 * Starts this service to check if there are any HPROF files to process and if any are found,
 * start converting them to BMD.
 *
 * @see IntentService
 */
public static void processHprofDumps(@NonNull Context context) {
    Intent intent = new Intent(context, CruncherService.class);
    intent.setAction(ACTION_CHECK_FILES);
    context.startService(intent);
}
 
 方法所在类
 同类方法