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:indrora.atomic.indicator.ConversationIndicator.java

/**
 * Update the colors of the state indicators.
 *///from w  ww. j  a v a 2 s  .co m
public void updateStateColors() {
    int page = pager.getCurrentItem();

    ConversationPagerAdapter adapter = (ConversationPagerAdapter) pager.getAdapter();
    Conversation conversation = adapter.getItem(page);

    Conversation previousConversation = server.getConversation(server.getSelectedConversation());
    if (previousConversation != null) {
        previousConversation.setStatus(Conversation.STATUS_DEFAULT);
    }

    if (conversation.getNewMentions() > 0) {
        Context context = pager.getContext();

        Intent intent = new Intent(context, IRCService.class);
        intent.setAction(IRCService.ACTION_ACK_NEW_MENTIONS);
        intent.putExtra(IRCService.EXTRA_ACK_SERVERID, server.getId());
        intent.putExtra(IRCService.EXTRA_ACK_CONVTITLE, conversation.getName());
        context.startService(intent);
    }

    conversation.setStatus(Conversation.STATUS_SELECTED);
    server.setSelectedConversation(conversation.getName());

    if (page - 2 >= 0) {
        int color = stateProvider.getColorForLowerThan(page - 1);
        leftIndicatorView.setBackgroundColor(color);
        leftIndicatorView
                .setVisibility(color == ConversationPagerAdapter.COLOR_NONE ? View.INVISIBLE : View.VISIBLE);
    } else {
        leftIndicatorView.setVisibility(View.INVISIBLE);
    }

    if (page + 2 < adapter.getCount()) {
        int color = stateProvider.getColorForGreaterThan(page + 1);

        rightIndicatorView.setBackgroundColor(color);
        rightIndicatorView
                .setVisibility(color == ConversationPagerAdapter.COLOR_NONE ? View.INVISIBLE : View.VISIBLE);
    } else {
        rightIndicatorView.setVisibility(View.INVISIBLE);
    }

    titleIndicator.invalidate();
}

From source file:cl.chihau.holaauto.MessageReplyReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(TAG, "onReceive called");

    if (MyMessagingService.REPLY_ACTION.equals(intent.getAction())) {
        int conversationId = intent.getIntExtra(MyMessagingService.CONVERSATION_ID, -1);
        CharSequence reply = getMessageText(intent);
        Log.d(TAG, "Got reply (" + reply + ") for ConversationId " + conversationId);

        // Tell the Service to send another message.
        Intent serviceIntent = new Intent(context, MyMessagingService.class);
        serviceIntent.setAction(MyMessagingService.SEND_MESSAGE_ACTION);
        context.startService(serviceIntent);
    }/* www . ja v  a  2s . com*/
}

From source file:com.example.android.automessagingcodelab.MessageReplyReceiver.java

@Override
public void onReceive(Context context, Intent intent) {
    if (MessagingService.REPLY_ACTION.equals(intent.getAction())) {
        int conversationId = intent.getIntExtra(MessagingService.CONVERSATION_ID, -1);
        CharSequence reply = getMessageText(intent);
        if (conversationId != -1) {
            Log.d(TAG, "Got reply (" + reply + ") for ConversationId " + conversationId);
        }/*from  ww  w.j a  v a  2  s .c  om*/
        // Tell the Service to send another message.
        Intent serviceIntent = new Intent(context, MessagingService.class);
        serviceIntent.setAction(MessagingService.SEND_MESSAGE_ACTION);
        context.startService(serviceIntent);
    }
}

From source file:com.andrew.apollo.utils.MusicUtils.java

/**
 * Changes to the previous track.//from   w  w w . ja va2s. com
 *
 * @NOTE The AIDL isn't used here in order to properly use the previous
 *       action. When the user is shuffling, because {@link
 *       MusicPlaybackService#openCurrentAndNext()} is used, the user won't
 *       be able to travel to the previously skipped track. To remedy this,
 *       {@link MusicPlaybackService#openCurrent()} is called in {@link
 *       MusicPlaybackService#prev()}. {@code #startService(Intent intent)}
 *       is called here to specifically invoke the onStartCommand used by
 *       {@link MusicPlaybackService}, which states if the current position
 *       less than 2000 ms, start the track over, otherwise move to the
 *       previously listened track.
 */
public static void previous(final Context context) {
    final Intent previous = new Intent(context, MusicPlaybackService.class);
    previous.setAction(MusicPlaybackService.PREVIOUS_ACTION);
    context.startService(previous);
}

From source file:uk.co.rotwang.cosm.CosmWidget.java

@Override
public void onUpdate(Context context, AppWidgetManager manager, int[] widgetIds) {
    // To prevent any ANR timeouts, we perform the update in a service
    for (int wid : widgetIds) {
        // Update each widget that requests it
        Intent intent = new Intent(context, UpdateService.class);
        Settings.setWidgetId(intent, wid);
        context.startService(intent);
    }/*from  w ww. ja  va2  s  .  c o  m*/
}

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

@Override
public void startTrigger(Context context, int trigId, String trigDesc) {
    Log.v(TAG, "LocationTrigger: startTrigger(" + trigId + ", " + trigDesc + ")");

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

From source file:org.strongswan.android.logic.VpnStateService.java

/**
 * Disconnect any existing connection and shutdown the daemon, the
 * VpnService is not stopped but it is reset so new connections can be
 * started./*from w  ww. ja  v a 2s  .c o  m*/
 */
public void disconnect() {
    /* reset any potential retry timer and error state */
    resetRetryTimer();
    setError(ErrorState.NO_ERROR);

    /* as soon as the TUN device is created by calling establish() on the
     * VpnService.Builder object the system binds to the service and keeps
     * bound until the file descriptor of the TUN device is closed.  thus
     * calling stopService() here would not stop (destroy) the service yet,
     * instead we call startService() with a specific action which shuts down
     * the daemon (and closes the TUN device, if any) */
    Context context = getApplicationContext();
    Intent intent = new Intent(context, CharonVpnService.class);
    intent.setAction(CharonVpnService.DISCONNECT_ACTION);
    context.startService(intent);
}

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

@Override
public void stopTrigger(Context context, int trigId, String trigDesc) {
    Log.v(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.reminders.types.location.LocationTrigger.java

@Override
public void resetTrigger(Context context, int trigId, String trigDesc) {
    Log.v(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:org.ohmage.triggers.types.location.LocationTrigger.java

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

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