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:eu.faircode.adblocker.ServiceSinkhole.java

public static void run(String reason, Context context) {
    Intent intent = new Intent(context, ServiceSinkhole.class);
    intent.putExtra(EXTRA_COMMAND, Command.run);
    intent.putExtra(EXTRA_REASON, reason);
    context.startService(intent);
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

public static void stop(String reason, Context context) {
    Intent intent = new Intent(context, ServiceSinkhole.class);
    intent.putExtra(EXTRA_COMMAND, Command.stop);
    intent.putExtra(EXTRA_REASON, reason);
    context.startService(intent);
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

public static void start(String reason, Context context) {
    Intent intent = new Intent(context, ServiceSinkhole.class);
    intent.putExtra(EXTRA_COMMAND, Command.start);
    intent.putExtra(EXTRA_REASON, reason);
    context.startService(intent);
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

public static void reloadStats(String reason, Context context) {
    Intent intent = new Intent(context, ServiceSinkhole.class);
    intent.putExtra(EXTRA_COMMAND, Command.stats);
    intent.putExtra(EXTRA_REASON, reason);
    context.startService(intent);
}

From source file:com.google.android.libraries.cast.companionlibrary.cast.BaseCastManager.java

protected void startReconnectionService(long mediaDurationLeft) {
    if (!isFeatureEnabled(CastConfiguration.FEATURE_WIFI_RECONNECT)) {
        return;/*from www . ja  va 2 s  .  co m*/
    }
    LOGD(TAG, "startReconnectionService() for media length lef = " + mediaDurationLeft);
    long endTime = SystemClock.elapsedRealtime() + mediaDurationLeft;
    mPreferenceAccessor.saveLongToPreference(PREFS_KEY_MEDIA_END, endTime);
    Context applicationContext = mContext.getApplicationContext();
    Intent service = new Intent(applicationContext, ReconnectionService.class);
    service.setPackage(applicationContext.getPackageName());
    applicationContext.startService(service);
}

From source file:com.mfcoding.locationBP.receivers.LocationChangedReceiver.java

/**
 * When a new location is received, extract it from the Intent and use
 * it to start the Service used to update the list of nearby places.
 * //  ww w. ja  v a 2 s .  c o  m
 * This is the Active receiver, used to receive Location updates when 
 * the Activity is visible. 
 */
@Override
public void onReceive(Context context, Intent intent) {
    String locationKey = LocationManager.KEY_LOCATION_CHANGED;
    String providerEnabledKey = LocationManager.KEY_PROVIDER_ENABLED;
    if (intent.hasExtra(providerEnabledKey)) {
        if (!intent.getBooleanExtra(providerEnabledKey, true)) {
            Intent providerDisabledIntent = new Intent(
                    PlacesConstants.ACTIVE_LOCATION_UPDATE_PROVIDER_DISABLED);
            context.sendBroadcast(providerDisabledIntent);
        }
    }
    if (intent.hasExtra(locationKey)) {
        Location location = (Location) intent.getExtras().get(locationKey);
        Log.d(TAG,
                "Actively Updating location lat:" + location.getLatitude() + " lng:" + location.getLongitude());
        Intent updateServiceIntent = new Intent(context,
                PlacesConstants.SUPPORTS_ECLAIR ? EclairPlacesUpdateService.class
                        : LocationUpdateService.class);
        updateServiceIntent.putExtra(PlacesConstants.EXTRA_KEY_LOCATION, location);
        updateServiceIntent.putExtra(PlacesConstants.EXTRA_KEY_RADIUS, PlacesConstants.DEFAULT_RADIUS);
        updateServiceIntent.putExtra(PlacesConstants.EXTRA_KEY_FORCEREFRESH, true);
        context.startService(updateServiceIntent);

        //      Intent locUpdateIntent = new Intent(PlacesConstants.ACTIVE_LOCATION_UPDATE);
        //      context.sendBroadcast(locUpdateIntent);
    }
}

From source file:com.google.sample.castcompanionlibrary.cast.BaseCastManager.java

protected void startReconnectionService(long mediaDurationLeft) {
    if (!isFeatureEnabled(FEATURE_WIFI_RECONNECT)) {
        return;//from   w  w  w. j a v a 2  s  . c o m
    }
    LOGD(TAG, "startReconnectionService() for media length lef = " + mediaDurationLeft);
    long endTime = SystemClock.elapsedRealtime() + mediaDurationLeft;
    Utils.saveLongToPreference(mContext.getApplicationContext(), PREFS_KEY_MEDIA_END, endTime);
    Context applicationContext = mContext.getApplicationContext();
    Intent service = new Intent(applicationContext, ReconnectionService.class);
    service.setPackage(applicationContext.getPackageName());
    applicationContext.startService(service);
}

From source file:com.owncloud.android.files.services.TransferRequester.java

/**
 * Private implementation of retry.//from   ww  w  .  j a v  a 2  s.c  o m
 *
 * @param context           Caller {@link Context}
 * @param account           OC account where the upload will be retried.
 * @param upload            Persisted upload to retry.
 * @param requestedFromWifiBackEvent true if the retry was requested because wifi connection was back,
 *                                   false otherwise
 */
private void retry(Context context, Account account, OCUpload upload, boolean requestedFromWifiBackEvent) {
    if (upload != null) {
        Intent intent = new Intent(context, FileUploader.class);
        intent.putExtra(FileUploader.KEY_RETRY, true);
        intent.putExtra(FileUploader.KEY_ACCOUNT, account);
        intent.putExtra(FileUploader.KEY_RETRY_UPLOAD, upload);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
                && (upload.getCreatedBy() == CREATED_AS_CAMERA_UPLOAD_PICTURE
                        || upload.getCreatedBy() == CREATED_AS_CAMERA_UPLOAD_VIDEO
                        || requestedFromWifiBackEvent)) {
            // Since in Android O the apps in background are not allowed to start background
            // services and camera uploads feature may try to do it, this is the way to proceed
            if (requestedFromWifiBackEvent) {
                intent.putExtra(FileUploader.KEY_REQUESTED_FROM_WIFI_BACK_EVENT, true);
            }
            context.startForegroundService(intent);
        } else {
            context.startService(intent);
        }
    }
}

From source file:com.owncloud.android.files.services.TransferRequester.java

/**
 * Call to upload several new files//from   w w  w . j  a v  a  2  s .co m
 */
public void uploadNewFiles(Context context, Account account, String[] localPaths, String[] remotePaths,
        String[] mimeTypes, Integer behaviour, Boolean createRemoteFolder, int createdBy) {
    Intent intent = new Intent(context, FileUploader.class);

    intent.putExtra(FileUploader.KEY_ACCOUNT, account);
    intent.putExtra(FileUploader.KEY_LOCAL_FILE, localPaths);
    intent.putExtra(FileUploader.KEY_REMOTE_FILE, remotePaths);
    intent.putExtra(FileUploader.KEY_MIME_TYPE, mimeTypes);
    intent.putExtra(FileUploader.KEY_LOCAL_BEHAVIOUR, behaviour);
    intent.putExtra(FileUploader.KEY_CREATE_REMOTE_FOLDER, createRemoteFolder);
    intent.putExtra(FileUploader.KEY_CREATED_BY, createdBy);

    if ((createdBy == CREATED_AS_CAMERA_UPLOAD_PICTURE || createdBy == CREATED_AS_CAMERA_UPLOAD_VIDEO)
            && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        // Since in Android O the apps in background are not allowed to start background
        // services and camera uploads feature may try to do it, this is the way to proceed
        context.startForegroundService(intent);
    } else {
        context.startService(intent);
    }
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

public static void reload(String reason, Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (prefs.getBoolean("enabled", false)) {
        Intent intent = new Intent(context, ServiceSinkhole.class);
        intent.putExtra(EXTRA_COMMAND, Command.reload);
        intent.putExtra(EXTRA_REASON, reason);
        context.startService(intent);
    }//from   w  w w.ja va 2s .com
}