Example usage for android.content Context startService

List of usage examples for android.content Context startService

Introduction

In this page you can find the example usage for android.content Context startService.

Prototype

@Nullable
public abstract ComponentName startService(Intent service);

Source Link

Document

Request that a given application service be started.

Usage

From source file:org.ohmage.reminders.types.time.TimeTrigger.java

@Override
public void resetTrigger(Context context, int trigId, String trigDesc) {
    Intent i = new Intent(context, TimeTrigService.class);
    i.setAction(TimeTrigService.ACTION_RESET_TRIGGER);
    i.putExtra(TimeTrigService.KEY_TRIG_ID, trigId);
    i.putExtra(TimeTrigService.KEY_TRIG_DESC, trigDesc);
    context.startService(i);
}

From source file:org.ohmage.reminders.types.time.TimeTrigger.java

@Override
public void stopTrigger(Context context, int trigId, String trigDesc) {
    Intent i = new Intent(context, TimeTrigService.class);
    i.setAction(TimeTrigService.ACTION_REMOVE_TRIGGER);
    i.putExtra(TimeTrigService.KEY_TRIG_ID, trigId);
    i.putExtra(TimeTrigService.KEY_TRIG_DESC, trigDesc);
    context.startService(i);
}

From source file:org.metawatch.manager.MetaWatchService.java

public static void autoStartService(Context context) {
    if (connectionState != ConnectionState.DISCONNECTED)
        return;/*from   ww  w. j  a  v  a  2  s  .  c  o m*/

    if (!Preferences.loaded)
        loadPreferences(context);

    if (Preferences.autoConnect) {
        context.startService(new Intent(context, MetaWatchService.class));
        if (Preferences.logging)
            Log.v(MetaWatchStatus.TAG, "Service auto started");
    }
}

From source file:org.egov.android.controller.ServiceController.java

/**
 * When starting an activity, this function is called. If the service is already started, then
 * no need to start it again. The service is called to run the jobs in background.
 * //w  w w  .  j av  a  2s .  c o m
 * @param ctx
 */
public void startService(Context ctx) {
    this.ctx = ctx;
    if (!isServiceStarted) {
        egovService = new Intent(ctx, EgovService.class);
        ctx.startService(egovService);
        isServiceStarted = true;
    }
    bindService();
}

From source file:org.sipdroid.sipua.ui.Receiver.java

public static synchronized SipdroidEngine engine(Context context) {
    if (mContext == null || !context.getClass().getName().contains("ReceiverRestrictedContext"))
        mContext = context;//w  w w  .  jav a2s  .  c  om
    if (mSipdroidEngine == null) {
        if (android.os.Build.VERSION.SDK_INT > 9) {
            ReceiverNew.setPolicy();
        }
        mSipdroidEngine = new SipdroidEngine();
        mSipdroidEngine.StartEngine();
        if (Integer.parseInt(Build.VERSION.SDK) >= 8)
            Bluetooth.init();
    } else
        mSipdroidEngine.CheckEngine();
    context.startService(new Intent(context, RegisterService.class));
    return mSipdroidEngine;
}

From source file:com.esminis.server.library.service.server.ServerNotification.java

public void show(Context context, CharSequence title, CharSequence titlePublic) {
    if (!preferences.contains(context, Preferences.SHOW_NOTIFICATION_SERVER)
            || !preferences.getBoolean(context, Preferences.SHOW_NOTIFICATION_SERVER)) {
        hide(context);// www .ja  v a  2  s.  co m
        return;
    }
    if (!serviceIsRunning) {
        serviceIsRunning = true;
        context.startService(new Intent(context, ServerNotificationService.class));
    }
    if (notification == null) {
        Builder builder = setupNotificationBuilder(context, title)
                .setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
                .setPublicVersion(setupNotificationBuilder(context, titlePublic).build());
        Intent intent = new Intent(context, MainActivity.class);
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        builder.setContentIntent(
                PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
        notification = builder.build();
    }
    getManager(context).notify(NOTIFICATION_ID, notification);
}

From source file:com.ntsync.android.sync.activities.PaymentVerificationService.java

private static void runVerifier(final Context context, final ScheduledExecutorService sched) {
    SystemHelper.initSystem(context);// ww  w  . ja  v  a2  s  .  co  m
    // Check if PaymentData available -> when no cancel
    AccountManager acm = AccountManager.get(context);
    Account[] accounts = acm.getAccountsByType(Constants.ACCOUNT_TYPE);
    boolean foundPaymentData = false;
    for (Account account : accounts) {
        PaymentData paymentData = SyncUtils.getPayment(account, acm);
        if (paymentData != null) {
            if (SyncUtils.isPaymentVerificationStarted()) {
                return;
            }

            if (System.currentTimeMillis() > paymentData.paymentSaveDate + TIMEOUT_PENDING_PAYMENT) {
                sendNotification(context, account, R.string.shop_activity_pendingverification,
                        ShopActivity.class, false);
            }
            foundPaymentData = true;
            break;
        }
    }

    if (foundPaymentData) {
        // Check if user has to be notified

        // Start Service
        Intent verifService = new Intent(context, PaymentVerificationService.class);
        context.startService(verifService);
        LogHelper.logD(TAG, "Start PaymentVerificationService", null);
    } else {
        sched.shutdownNow();
    }
}

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_communicator.services.ChannelService.java

public static void createChannel(Context ctx) {
    String regId = getGCMRegId(ctx);
    if (regId.isEmpty()) {
        log.warn("regId is empty. It will get from GCM register");
        return;/*w  w  w. j  a va  2s  .  c om*/
    }

    Account ac = AccountUtils.getAccount(ctx, false);
    AccountManager am = (AccountManager) ctx.getSystemService(Context.ACCOUNT_SERVICE);

    String userId;
    try {
        userId = am.getUserData(ac, JsonKeys.ID_STORED);
    } catch (Exception e) {
        log.error("Cannot get userId", e);
        return;
    }

    String json;
    try {
        json = registerInServer(ctx, regId, userId);
    } catch (Exception e) {
        log.error("Cannot send regId to server", e);
        return;
    }

    if (json == null) {
        log.error("Cannot get channelId");
        return;
    }

    try {
        JSONObject obj = new JSONObject(json);

        String channelId = obj.getString(JsonKeys.CHANNEL_ID);
        storeRegistrationId(ctx, regId, channelId);

        Intent i = new Intent(ConstantKeys.BROADCAST_SERVER_REGISTER);
        ctx.sendBroadcast(i);
    } catch (JSONException e) {
        log.error("Error processing register result", e);
    }

    ctx.startService(new Intent(ctx.getApplicationContext(), CommandGetService.class));
}

From source file:com.farmerbb.secondscreen.util.U.java

public static void turnOffProfile(Context context) {
    if (hasWriteSettingsPermission(context)) {
        // Set filename in current.xml
        SharedPreferences prefCurrent = getPrefCurrent(context);
        SharedPreferences.Editor editor = prefCurrent.edit();
        editor.putString("filename_backup", prefCurrent.getString("filename", "0"));
        editor.putString("filename", "0");
        editor.apply();//  www  .j a va2s  .c om

        // Start TurnOffService
        Intent intent = new Intent(context, TurnOffService.class);
        context.startService(intent);
    } else {
        Intent intent = new Intent(context, WriteSettingsPermissionActivity.class);
        intent.putExtra("action", "turn-off-profile");
        context.startActivity(intent);
    }
}

From source file:com.farmerbb.secondscreen.util.U.java

public static void loadProfile(Context context, String filename) {
    if (hasWriteSettingsPermission(context)) {
        // Set filename in current.xml
        SharedPreferences prefCurrent = getPrefCurrent(context);
        SharedPreferences.Editor editor = prefCurrent.edit();
        editor.putString("filename", filename);
        editor.apply();//ww  w  .ja  va  2 s.  c om

        // Start ProfileLoadService
        Intent intent = new Intent(context, ProfileLoadService.class);
        // Get filename of selected profile
        intent.putExtra(NAME, filename);
        context.startService(intent);
    } else {
        Intent intent = new Intent(context, WriteSettingsPermissionActivity.class);
        intent.putExtra("action", "load-profile");
        intent.putExtra("filename", filename);
        context.startActivity(intent);
    }
}