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.kontalk.service.msgcenter.MessageCenterService.java

public static void requestRosterStatus(final Context context) {
    Intent i = new Intent(context, MessageCenterService.class);
    i.setAction(MessageCenterService.ACTION_ROSTER_LOADED);
    context.startService(i);
}

From source file:org.kontalk.service.msgcenter.MessageCenterService.java

public static void regenerateKeyPair(final Context context) {
    Intent i = new Intent(context, MessageCenterService.class);
    i.setAction(MessageCenterService.ACTION_REGENERATE_KEYPAIR);
    context.startService(i);
}

From source file:org.kontalk.service.msgcenter.MessageCenterService.java

public static void restart(Context context) {
    Log.d(TAG, "restarting message center");
    Intent i = new Intent(context, MessageCenterService.class);
    i.setAction(ACTION_RESTART);/*from w  w w .  j  a va 2 s. co  m*/
    context.startService(i);
}

From source file:org.kontalk.service.msgcenter.MessageCenterService.java

public static void ping(Context context) {
    Log.d(TAG, "ping message center connection");
    Intent i = new Intent(context, MessageCenterService.class);
    i.setAction(ACTION_PING);//from w w w. j a v  a2  s. c  o  m
    context.startService(i);
}

From source file:org.kontalk.service.msgcenter.MessageCenterService.java

public static void test(Context context) {
    Log.d(TAG, "testing message center connection");
    Intent i = new Intent(context, MessageCenterService.class);
    i.setAction(ACTION_TEST);/*from w  w w  .ja  v  a  2  s .  co  m*/
    context.startService(i);
}

From source file:org.kontalk.service.msgcenter.MessageCenterService.java

public static void requestVCard(final Context context, String to) {
    Intent i = new Intent(context, MessageCenterService.class);
    i.setAction(MessageCenterService.ACTION_VCARD);
    i.putExtra(EXTRA_TO, to);//from w  w  w .  j  ava 2s .  co  m
    context.startService(i);
}

From source file:com.cerema.cloud2.files.InstantUploadBroadcastReceiver.java

private void handleNewVideoAction(Context context, Intent intent) {
    Cursor c = null;/*from  w ww  . j  av a 2  s  . co m*/
    String file_path = null;
    String file_name = null;
    String mime_type = null;

    Log_OC.w(TAG, "New video received");

    if (!instantVideoUploadEnabled(context)) {
        Log_OC.d(TAG, "Instant video upload disabled, ignoring new video");
        return;
    }

    Account account = AccountUtils.getCurrentOwnCloudAccount(context);
    if (account == null) {
        Log_OC.w(TAG, "No account found for instant upload, aborting");
        return;
    }

    String[] CONTENT_PROJECTION = { Video.Media.DATA, Video.Media.DISPLAY_NAME, Video.Media.MIME_TYPE,
            Video.Media.SIZE };
    c = context.getContentResolver().query(intent.getData(), CONTENT_PROJECTION, null, null, null);
    if (!c.moveToFirst()) {
        Log_OC.e(TAG, "Couldn't resolve given uri: " + intent.getDataString());
        return;
    }
    file_path = c.getString(c.getColumnIndex(Video.Media.DATA));
    file_name = c.getString(c.getColumnIndex(Video.Media.DISPLAY_NAME));
    mime_type = c.getString(c.getColumnIndex(Video.Media.MIME_TYPE));
    c.close();
    Log_OC.d(TAG, file_path + "");

    if (!isOnline(context) || (instantVideoUploadViaWiFiOnly(context) && !isConnectedViaWiFi(context))) {
        return;
    }

    Intent i = new Intent(context, FileUploader.class);
    i.putExtra(FileUploader.KEY_ACCOUNT, account);
    i.putExtra(FileUploader.KEY_LOCAL_FILE, file_path);
    i.putExtra(FileUploader.KEY_REMOTE_FILE,
            FileStorageUtils.getInstantVideoUploadFilePath(context, file_name));
    i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE);
    i.putExtra(FileUploader.KEY_MIME_TYPE, mime_type);
    i.putExtra(FileUploader.KEY_INSTANT_UPLOAD, true);

    // instant upload behaviour
    i = addInstantUploadBehaviour(i, context);

    context.startService(i);

}

From source file:org.kontalk.service.msgcenter.MessageCenterService.java

public static void retryAllMessages(final Context context) {
    MessagesProviderUtils.retryAllMessages(context);
    Intent i = new Intent(context, MessageCenterService.class);
    i.setAction(MessageCenterService.ACTION_RETRY);
    context.startService(i);
}

From source file:com.android.systemui.ReminderReceiver.java

@Override
public void onReceive(final Context context, Intent intent) {
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    SharedPreferences shared = context.getSharedPreferences(KEY_REMINDER_ACTION, Context.MODE_PRIVATE);

    if (intent.getBooleanExtra("clear", false)) {
        manager.cancel(NOTI_ID);/*from   w  ww . ja v  a2s .  c o  m*/
        // User has set a new reminder but didn't clear
        // This notification until now
        if (!shared.getBoolean("updated", false)) {
            shared.edit().putBoolean("scheduled", false).commit();
            shared.edit().putInt("hours", -1).commit();
            shared.edit().putInt("minutes", -1).commit();
            shared.edit().putInt("day", -1).commit();
            shared.edit().putString("title", null).commit();
            shared.edit().putString("message", null).commit();
        }
    } else {
        String title = shared.getString("title", null);
        String message = shared.getString("message", null);
        if (title != null && message != null) {
            Bitmap bm = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_qs_alarm_on);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setTicker(title)
                    .setContentTitle(title).setContentText(message).setAutoCancel(false).setOngoing(true)
                    .setPriority(NotificationCompat.PRIORITY_HIGH).setSmallIcon(R.drawable.ic_qs_alarm_on)
                    .setLargeIcon(bm).setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE)
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(message));

            int alertMode = Settings.System.getIntForUser(context.getContentResolver(),
                    Settings.System.REMINDER_ALERT_NOTIFY, 0, UserHandle.USER_CURRENT);
            PendingIntent result = null;
            Intent serviceIntent = new Intent(context, ReminderService.class);
            if (alertMode != 0 && !QuietHoursHelper.inQuietHours(context, Settings.System.QUIET_HOURS_MUTE)) {
                context.startService(serviceIntent);
            }

            // Stop sound on click
            serviceIntent.putExtra("stopSelf", true);
            result = PendingIntent.getService(context, 1, serviceIntent, PendingIntent.FLAG_CANCEL_CURRENT);
            builder.setContentIntent(result);

            // Add button for dismissal
            serviceIntent.putExtra("dismissNoti", true);
            result = PendingIntent.getService(context, 0, serviceIntent, PendingIntent.FLAG_CANCEL_CURRENT);
            builder.addAction(R.drawable.ic_sysbar_null,
                    context.getResources().getString(R.string.quick_settings_reminder_noti_dismiss), result);

            // Add button for reminding later
            serviceIntent.putExtra("time", true);
            result = PendingIntent.getService(context, 2, serviceIntent, PendingIntent.FLAG_CANCEL_CURRENT);
            builder.addAction(R.drawable.ic_qs_alarm_on,
                    context.getResources().getString(R.string.quick_settings_reminder_noti_later), result);

            shared.edit().putBoolean("scheduled", false).commit();
            shared.edit().putInt("hours", -1).commit();
            shared.edit().putInt("minutes", -1).commit();
            shared.edit().putInt("day", -1).commit();

            manager.notify(NOTI_ID, builder.build());
        }
    }
    shared.edit().putBoolean("updated", false).commit();
}

From source file:org.kontalk.service.msgcenter.MessageCenterService.java

/** Caches the given registration Id for use with push notifications. */
public static void registerPushNotifications(Context context, String registrationId) {
    Intent i = new Intent(context, MessageCenterService.class);
    i.setAction(ACTION_PUSH_REGISTERED);
    i.putExtra(PUSH_REGISTRATION_ID, registrationId);
    context.startService(i);
}