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:com.opentaxi.android.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (intent != null && intent.getExtras() != null) {
        String regId = intent.getExtras().getString("registration_id");
        if (regId != null && !regId.equals("") && !regId.equals(TaxiApplication.gcmId)) {
            TaxiApplication.gcmId = regId;
            /* Do what ever you want with the regId eg. send it to your server */
            Log.i("GcmBroadcastReceiver", "onReceive:" + regId);
            //RestClient.getInstance().gcmRegister(regId);
            Intent i = new Intent(context, GCMRegisterService.class);
            i.putExtra("regId", regId);
            context.startService(i);
        }//from w w w  . ja va 2  s . c o  m
    }

    // Explicitly specify that GcmIntentService will handle the intent.
    ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());
    // Start the service, keeping the device awake while it is launching.
    if (intent != null)
        startWakefulService(context, (intent.setComponent(comp)));
    setResultCode(Activity.RESULT_OK);
}

From source file:org.ohmage.triggers.types.location.LocationTrigger.java

@Override
public void stopTrigger(Context context, int trigId, String trigDesc) {
    Log.i(DEBUG_TAG, "LocationTrigger: removeTrigger(" + trigId + ", " + trigDesc + ")");

    //Tell the service to stop this trigger
    Intent i = new Intent(context, LocTrigService.class);
    i.setAction(LocTrigService.ACTION_REMOVE_TRIGGER);
    i.putExtra(LocTrigService.KEY_TRIG_ID, trigId);
    i.putExtra(LocTrigService.KEY_TRIG_DESC, trigDesc);
    context.startService(i);
}

From source file:org.ohmage.triggers.types.location.LocationTrigger.java

@Override
public void resetTrigger(Context context, int trigId, String trigDesc) {
    Log.i(DEBUG_TAG, "LocationTrigger: resetTrigger(" + trigId + ", " + trigDesc + ")");

    //Tell the service to restart the trigger
    Intent i = new Intent(context, LocTrigService.class);
    i.setAction(LocTrigService.ACTION_RESET_TRIGGER);
    i.putExtra(LocTrigService.KEY_TRIG_ID, trigId);
    i.putExtra(LocTrigService.KEY_TRIG_DESC, trigDesc);
    context.startService(i);
}

From source file:com.gcm.client.GcmHelper.java

/**
 * Delete the existing push token//from w  w  w.ja  va2 s  .  c o m
 * @param context An instance of the application Context
 */
public synchronized void deleteToken(Context context) {
    if (!TextUtils.isEmpty(pushToken)) {
        Intent registration = new Intent(context, RegistrationIntentService.class);
        registration.setAction(RegistrationIntentService.ACTION_UNREGISTER);
        context.startService(registration);

        SharedPreferences pref = getSharedPreference(context);
        pref.edit().remove(PREF_KEY_TOKEN).apply();
    }
}

From source file:com.linkbubble.MainApplication.java

public static boolean openLink(Context context, String url, boolean checkLastAppLoad,
        String openedFromAppName) {
    long time = System.currentTimeMillis();

    context = context.getApplicationContext();

    if (checkLastAppLoad) {
        /*//from ww w.  ja v a  2s .  c om
        long timeDiff = time - sLastLoadedTime;
        boolean earlyExit = false;
        if (timeDiff < 3000 && sLastLoadedUrl != null && sLastLoadedUrl.equals(url)) {
        Toast.makeText(context, "DOUBLE TAP!!", Toast.LENGTH_SHORT).show();
        earlyExit = true;
        }
        sLastLoadedUrl = url;
        sLastLoadedTime = time;
                
        if (earlyExit) {
        return false;
        }*/
    }

    Intent serviceIntent = new Intent(context, MainService.class);
    serviceIntent.putExtra("cmd", "open");
    serviceIntent.putExtra("url", url);
    serviceIntent.putExtra("start_time", time);
    serviceIntent.putExtra("openedFromAppName", openedFromAppName);
    context.startService(serviceIntent);

    return true;
}

From source file:com.cloudmine.api.db.BaseLocallySavableCMObject.java

boolean saveEventually(Context context, RequestDBObject request) {
    boolean wasCreated = false;
    try {//w w w.  j av  a 2  s . c  o m
        RequestDBOpenHelper.getRequestDBOpenHelper(context).insertRequest(request);
        wasCreated = true;
        LOG.debug("Request was inserted");
    } catch (Exception e) {
        wasCreated = false;
        LOG.error("Failed", e);
    }
    if (wasCreated) {
        context.startService(new Intent(context, RequestPerformerService.class));
    }

    return wasCreated;
}

From source file:org.mariotaku.twidere.receiver.ConnectivityStateReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    if (BuildConfig.DEBUG) {
        Log.d(RECEIVER_LOGTAG, String.format("Received Broadcast %s", intent));
    }//  ww  w. j  av  a 2s .c  o m
    if (!ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction()))
        return;
    final TwidereApplication application = TwidereApplication.Companion.getInstance(context);
    //        application.reloadConnectivitySettings();
    Utils.startRefreshServiceIfNeeded(application);
    final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    if (prefs.getBoolean(KEY_USAGE_STATISTICS, false)
            && prefs.getBoolean(KEY_SETTINGS_WIZARD_COMPLETED, false)) {
        // BEGIN HotMobi
        final NetworkEvent event = NetworkEvent.create(context);
        HotMobiLogger.getInstance(context).log(event);
        // END HotMobi
    }

    final Context appContext = context.getApplicationContext();
    final ConnectivityManager cm = (ConnectivityManager) appContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final boolean isNetworkMetered = ConnectivityManagerCompat.isActiveNetworkMetered(cm);
    final boolean isCharging = Utils.isCharging(appContext);
    if (!isNetworkMetered && isCharging) {
        final long currentTime = System.currentTimeMillis();
        final long lastSuccessfulTime = HotMobiLogger.getLastUploadTime(appContext);
        if ((currentTime - lastSuccessfulTime) > HotMobiLogger.UPLOAD_INTERVAL_MILLIS) {
            appContext.startService(new Intent(appContext, UploadLogsService.class));
        }
    }

}

From source file:org.y20k.transistor.PlayerService.java

public void startActionPlay(Context context, String streamURL, String stationName) {
    mStreamURL = streamURL;//from w  w  w .j a v a2  s .co m
    Log.v(LOG_TAG, "starting playback service: " + mStreamURL);

    // start player service using intent
    Intent intent = new Intent(context, PlayerService.class);
    intent.setAction(ACTION_PLAY);
    intent.putExtra(EXTRA_STREAM_URL, mStreamURL);
    context.startService(intent);

    // put up notification
    NotificationHelper notificationHelper = new NotificationHelper(context);
    notificationHelper.setStationName(stationName);
    notificationHelper.createNotification();
}

From source file:in.dc297.mqttclpro.tasker.FireReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    /*/*from w  ww  . j  a  va2 s .c o m*/
     * Always be strict on input parameters! A malicious third-party app could send a malformed Intent.
     */

    if (!in.dc297.mqttclpro.tasker.Intent.ACTION_FIRE_SETTING.equals(intent.getAction())) {
        if (Constants.IS_LOGGABLE) {
            Log.e(Constants.LOG_TAG,
                    String.format(Locale.US, "Received unexpected Intent action %s", intent.getAction())); //$NON-NLS-1$
        }
        return;
    }
    Intent newIntent = new Intent(context, MyIntentService.class);
    newIntent.putExtras(intent);

    newIntent.setAction(MQTTService.MQTT_PUBLISH);
    context.startService(newIntent);
    //BundleScrubber.scrub(intent);

    //final Bundle bundle = intent.getBundleExtra(in.dc297.mqttclpro.tasker.Intent.EXTRA_BUNDLE);
    //BundleScrubber.scrub(bundle);

    /*if (PluginBundleManager.isBundleValid(bundle))
    {
    final String message = bundle.getString(PluginBundleManager.BUNDLE_EXTRA_STRING_MESSAGE);
    Toast.makeText(context, message, Toast.LENGTH_LONG).show();
    }*/
}

From source file:org.namelessrom.devicecontrol.receivers.BootUpReceiver.java

private void startBootupStuffsAsync(Context ctx) {
    Paper.init(ctx);/* ww  w  .  j  a  v a 2  s  .c  o m*/
    Utils.startTaskerService(ctx);

    BootupConfig bootupConfig = BootupConfig.get();
    boolean isBootup = bootupConfig.isEnabled;
    if (!isBootup) {
        Logger.v(this, "User does not want to restore settings on bootup");
        return;
    }

    int size = bootupConfig.items.size();
    if (size == 0) {
        Logger.v(this, "No bootup items, not starting bootup restoration");
        return;
    }

    final Intent bootupRestorationIntent = new Intent(ctx, BootupService.class);

    if (bootupConfig.isAutomatedRestoration) {
        ctx.startService(bootupRestorationIntent);
        Logger.v(this, "Starting automated bootup restoration");
        return;
    }

    final PendingIntent pi = PendingIntent.getService(ctx, 0, bootupRestorationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final String title = ctx.getString(R.string.app_name);
    final String content = ctx.getString(R.string.bootup_restoration_content);

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx);
    final NotificationCompat.BigTextStyle style = new NotificationCompat.BigTextStyle();
    style.bigText(content);

    builder.setContentTitle(title).setContentText(content).setStyle(style).setOngoing(false)
            .setSmallIcon(R.drawable.ic_bootup_restore).setColor(AppResources.get().getAccentColor())
            .setContentIntent(pi).setAutoCancel(true);
    final Notification notification = builder.build();

    final NotificationManager notificationManager = (NotificationManager) ctx
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(NOTIFICATION_ID, notification);
}