Example usage for android.support.v4.content WakefulBroadcastReceiver startWakefulService

List of usage examples for android.support.v4.content WakefulBroadcastReceiver startWakefulService

Introduction

In this page you can find the example usage for android.support.v4.content WakefulBroadcastReceiver startWakefulService.

Prototype

public static ComponentName startWakefulService(Context context, Intent intent) 

Source Link

Usage

From source file:com.actinarium.nagbox.service.NagAlarmReceiver.java

@Override
public void onReceive(Context context, Intent receivedIntent) {
    Intent delegateIntent = new Intent(context, NagboxService.class);
    delegateIntent.setAction(NagboxService.ACTION_ON_ALARM_FIRED);
    // Acquire a lock for this service so it completes before the device goes back to sleep
    WakefulBroadcastReceiver.startWakefulService(context, delegateIntent);
}

From source file:eu.nerdz.app.messenger.GcmBroadcastReceiver.java

@Override
public void onReceive(Context context, Intent intent) {

    ComponentName component = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());

    WakefulBroadcastReceiver.startWakefulService(context, intent.setComponent(component));

    this.setResultCode(Activity.RESULT_OK);

}

From source file:com.packpublishing.asynchronousandroid.chapter6.WakefulSMSDispatcher.java

@Override
public void onReceive(Context context, Intent intent) {
    // Pass right over to SMSDispatcherIntentService class, the wakeful receiver is
    // just needed in case the schedule is triggered while the device
    // is asleep otherwise the service may not have time to trigger the
    // alarm.// ww  w  .  ja v  a  2s  . c om
    intent.setClass(context, SMSDispatcherIntentService.class);
    WakefulBroadcastReceiver.startWakefulService(context, intent);
}

From source file:name.gudong.translate.listener.ListenClipboardService.java

public static void startForWeakLock(Context context, Intent intent) {
    Intent serviceIntent = new Intent(context, ListenClipboardService.class);
    context.startService(serviceIntent);

    intent.putExtra(ListenClipboardService.KEY_FOR_WEAK_LOCK, true);
    Intent myIntent = new Intent(context, ListenClipboardService.class);

    // using wake lock to start service
    WakefulBroadcastReceiver.startWakefulService(context, myIntent);
}

From source file:com.javadog.cgeowear.ListenerService.java

@Override
public void onMessageReceived(MessageEvent messageEvent) {

    //Init: Service should start listening for updates from phone, and the compass activity should be launched
    if (PATH_INIT.equals(messageEvent.getPath())) {
        //Get Dataset from the message
        MessageDataset Dataset = new MessageDataset(DataMap.fromByteArray(messageEvent.getData()));

        //Start the service
        Intent i = new Intent(this, cgeoWearService.class);
        i.setAction(PATH_INIT);/*ww w.  j  a va  2s  .  c o  m*/
        i.putExtra(MessageDataset.KEY_CACHE_NAME, Dataset.getCacheName());
        i.putExtra(MessageDataset.KEY_GEOCODE, Dataset.getGeocode());
        i.putExtra(MessageDataset.KEY_DISTANCE, Dataset.getDistance());
        i.putExtra(MessageDataset.KEY_DIRECTION, Dataset.getDirection());
        i.putExtra(MessageDataset.KEY_WATCH_COMPASS, Dataset.getWatchCompassPref());
        i.putExtra(MessageDataset.KEY_CACHE_LOCATION, Dataset.getCacheLocation());
        WakefulBroadcastReceiver.startWakefulService(getApplicationContext(), i);

        //Distance update
    } else if (PATH_UPDATE_DISTANCE.equals(messageEvent.getPath())) {
        MessageDataset dataset = new MessageDataset(DataMap.fromByteArray(messageEvent.getData()));

        Intent updateIntent = new Intent(PATH_UPDATE_DISTANCE);
        updateIntent.putExtra(MessageDataset.KEY_DISTANCE, dataset.getDistance());

        LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(updateIntent);

        //Direction update
    } else if (PATH_UPDATE_DIRECTION.equals(messageEvent.getPath())) {
        MessageDataset dataset = new MessageDataset(DataMap.fromByteArray(messageEvent.getData()));

        Intent updateIntent = new Intent(PATH_UPDATE_DIRECTION);
        updateIntent.putExtra(MessageDataset.KEY_DIRECTION, dataset.getDirection());

        LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(updateIntent);

        //Update location action
    } else if (PATH_UPDATE_LOCATION.equals(messageEvent.getPath())) {
        MessageDataset dataset = new MessageDataset(DataMap.fromByteArray(messageEvent.getData()));

        Intent updateIntent = new Intent(PATH_UPDATE_LOCATION);
        updateIntent.putExtra(MessageDataset.KEY_LOCATION, dataset.getLocation());

        LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(updateIntent);

        //Kill app (when phone-side app is stopped)
    } else if (PATH_KILL_APP.equals(messageEvent.getPath())) {
        Intent killIntent = new Intent(PATH_KILL_APP);
        LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(killIntent);
    }
}

From source file:org.dodgybits.shuffle.android.server.gcm.GcmIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();/*from w w w . ja  v a2  s.co  m*/
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        /*
         * Filter messages based on message type. Since it is likely that GCM will be
         * extended in the future with new message types, just ignore any message types you're
         * not interested in, or that you don't recognize.
         */
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
            Log.e(TAG, "Send error: " + extras.toString());
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
            Log.d(TAG, "Deleted messages on server: " + extras.toString());
            // If it's a regular GCM message, do some work.
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            Log.i(TAG, "Received message" + extras.toString());
            Intent syncIntent = new Intent(this, SyncSchedulingService.class);
            syncIntent.putExtra(SOURCE_EXTRA, GCM_SOURCE);
            WakefulBroadcastReceiver.startWakefulService(this, syncIntent);
        }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
}