Java 类android.support.v4.content.WakefulBroadcastReceiver 实例源码

项目:GitHub    文件:WakefulReceivingService.java   
@Override
protected void onHandleIntent(Intent intent) {
    if (intent.getExtras() != null) {
        String personId = intent.getStringExtra("person_id");
        Realm realm = Realm.getDefaultInstance();
        Person person = realm.where(Person.class).equalTo("id", personId).findFirst();
        final String output = person.toString();
        new Handler(getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                Toast.makeText(getApplicationContext(), "Loaded Person from broadcast-receiver->intent-service: " + output, Toast.LENGTH_LONG).show();
            }
        });
        realm.close();
    }

    // All the work is done, release the wake locks/etc
    WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
项目:AndroidProjectsClient    文件:NotificationIntentService.java   
@Override
protected void onHandleIntent(@Nullable Intent intent) {
    if(intent == null) return;
    try {
        final String action = intent.getAction();
        if(ACTION_CHECK.equals(action)) {
            loadNotifications();
        } else if(ACTION_DELETE.equals(action) && intent.hasExtra("notification")) {
            Editor.getEditor(this).markNotificationThreadRead(
                    ((Notification) intent.getParcelableExtra("notification")).getId()
            );
        }
    } finally {
        Logger.i(TAG, "onHandleIntent: " + intent.toString());
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
项目:dashbar    文件:DashClockService.java   
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    LOGD(TAG, "onStartCommand: " + (intent != null ? intent.toString() : "no intent"));
    enforceCallingPermission(DashClockExtension.PERMISSION_READ_EXTENSION_DATA);

    if (intent != null) {
        String action = intent.getAction();
        if (ACTION_UPDATE_WIDGETS.equals(action)) {
            handleUpdateWidgets(intent);

        } else if (ACTION_UPDATE_EXTENSIONS.equals(action)) {
            handleUpdateExtensions(intent);
        }

        // If started by a wakeful broadcast receiver, release the wake lock it acquired.
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }

    return START_STICKY;
}
项目:RememBirthday    文件:NotificationIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    Log.d(getClass().getSimpleName(), "onHandleIntent, started handling a notification event");
    try {
        String action = intent.getAction();
        if (ACTION_START.equals(action)) {
            Contact contact = intent.getParcelableExtra(EXTRA_CONTACT_NOTIFICATION);
            //TODO processStartNotification(contact);
        }
        if (ACTION_DELETE.equals(action)) {
            processDeleteNotification(intent);
        }
    } finally {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
项目:dashclock    文件:DashClockService.java   
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    LOGD(TAG, "onStartCommand: " + (intent != null ? intent.toString() : "no intent"));
    enforceCallingPermission(DashClockExtension.PERMISSION_READ_EXTENSION_DATA);

    if (intent != null) {
        String action = intent.getAction();
        if (ACTION_UPDATE_WIDGETS.equals(action)) {
            handleUpdateWidgets(intent);

        } else if (ACTION_UPDATE_EXTENSIONS.equals(action)) {
            handleUpdateExtensions(intent);
        }

        // If started by a wakeful broadcast receiver, release the wake lock it acquired.
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }

    return START_STICKY;
}
项目:starcitizeninfoclient    文件:PushIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    String messageType = gcm.getMessageType(intent);

    if (!extras.isEmpty()) { // has effect of unparcelling Bundle
        if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR
                .equals(messageType)) {
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED
                .equals(messageType)) {
        } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE
                .equals(messageType)) {
            if (MyApp.getInstance().isPushEnabled()) {
                sendNotification("Received: " + extras.toString());
            }
        }
    }
    WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
项目:android_external_GmsLib    文件:InstanceIDListenerService.java   
public int onStartCommand(Intent intent, int flags, int startId) {
    synchronized (this) {
        this.counter++;
        if (startId > this.startId) this.startId = startId;
    }
    try {
        if (intent != null) {
            if (ACTION_INSTANCE_ID.equals(intent.getAction()) && intent.hasExtra(EXTRA_GSF_INTENT)) {
                startService((Intent) intent.getParcelableExtra(EXTRA_GSF_INTENT));
                return START_STICKY;
            }

            handleIntent(intent);

            if (intent.hasExtra(EXTRA_FROM))
                WakefulBroadcastReceiver.completeWakefulIntent(intent);
        }
    } finally {
        stop();
    }
    return START_NOT_STICKY;
}
项目:cgeo-wear    文件:cgeoWearService.java   
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    connectGoogleApiClient();
    initLocalVars(intent);
    showOngoingNotification();
    listenForUpdates();
    startCompassActivity();

    if(useWatchCompass) {
        setupLocationUtils(cacheLocation);
        locationUtils.startDirectionalTracking(getApplicationContext());
    }

    WakefulBroadcastReceiver.completeWakefulIntent(intent);

    return START_REDELIVER_INTENT;
}
项目:android_packages_apps_GmsCore    文件:CheckinService.java   
@SuppressWarnings("MissingPermission")
@Override
protected void onHandleIntent(Intent intent) {
    try {
        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(PREF_ENABLE_CHECKIN, false)) {
            LastCheckinInfo info = CheckinManager.checkin(this, intent.getBooleanExtra(EXTRA_FORCE_CHECKIN, false));
            if (info != null) {
                Log.d(TAG, "Checked in as " + Long.toHexString(info.androidId));
                String accountType = AuthConstants.DEFAULT_ACCOUNT_TYPE;
                for (Account account : AccountManager.get(this).getAccountsByType(accountType)) {
                    PeopleManager.loadUserInfo(this, account);
                }
                McsService.scheduleReconnect(this);
                if (intent.hasExtra(EXTRA_CALLBACK_INTENT)) {
                    startService((Intent) intent.getParcelableExtra(EXTRA_CALLBACK_INTENT));
                }
            }
        }
    } catch (Exception e) {
        Log.w(TAG, e);
    } finally {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
        stopSelf();
    }
}
项目:android_packages_apps_GmsCore    文件:McsService.java   
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    synchronized (McsService.class) {
        if (rootHandler != null) {
            if (intent == null) return START_REDELIVER_INTENT;
            wakeLock.acquire(WAKELOCK_TIMEOUT);
            Object reason = intent.hasExtra(EXTRA_REASON) ? intent.getExtras().get(EXTRA_REASON) : intent;
            if (ACTION_CONNECT.equals(intent.getAction())) {
                rootHandler.sendMessage(rootHandler.obtainMessage(MSG_CONNECT, reason));
            } else if (ACTION_HEARTBEAT.equals(intent.getAction())) {
                rootHandler.sendMessage(rootHandler.obtainMessage(MSG_HEARTBEAT, reason));
            } else if (ACTION_SEND.equals(intent.getAction())) {
                handleSendMessage(intent);
            }
            WakefulBroadcastReceiver.completeWakefulIntent(intent);
        } else if (connectIntent == null) {
            connectIntent = intent;
        } else {
            WakefulBroadcastReceiver.completeWakefulIntent(intent);
        }
    }
    return START_REDELIVER_INTENT;
}
项目:Dash    文件:DashClockService.java   
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    LOGD(TAG, "onStartCommand: " + (intent != null ? intent.toString() : "no intent"));

    if (intent != null) {
        String action = intent.getAction();
        if (ACTION_UPDATE_WIDGETS.equals(action)) {
            handleUpdateWidgets(intent);

        } else if (ACTION_UPDATE_EXTENSIONS.equals(action)) {
            handleUpdateExtensions(intent);
        }

        // If started by a wakeful broadcast receiver, release the wake lock it acquired.
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }

    return START_STICKY;
}
项目:Dollars-Android-App    文件:RSSCheckOnBoot.java   
@Override
public void onReceive(Context context, Intent intent) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if(prefs.getBoolean(RSSRelatedConstants.NOTIF_KEYS[0], true) && !prefs.getBoolean(MainActivity.FIRST_OPEN, true)) {
        RSSScheduledServiceHelper.startScheduled(context);
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
项目:getting-ready-for-android-n    文件:SunshineSyncService.java   
@Override
protected void onHandleIntent(Intent intent) {
    Log.i(TAG, "Sync intent received. Fetching data from network.");
    sSunshineSyncEngine.performUpdate();
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
项目:Asynchronous-Android-Programming    文件: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.
    intent.setClass(context, SMSDispatcherIntentService.class);
    WakefulBroadcastReceiver.startWakefulService(context, intent);
}
项目:Asynchronous-Android-Programming    文件:SMSDispatcherIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    try {
        String to = intent.getStringExtra(TO_KEY);
        String text = intent.getStringExtra(TEXT_KEY);
        Log.i("SMS Dispatcher", "Delivering message to " + text);
        SmsManager sms = SmsManager.getDefault();
        Intent deliveredIntent = new Intent("sms_delivered");
        deliveredIntent.putExtra(SMSDispatcher.TO_KEY, to);
        deliveredIntent.putExtra(SMSDispatcher.TEXT_KEY, text);
        sms.sendTextMessage(to, null, text, null, null);
    } finally {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
项目:cosi    文件:CosiLoyaltyCardService.java   
@Override
protected void onHandleIntent(Intent intent) {
    // Do the task here
    Log.i(CosiLoyaltyCardService.class.getName(), "Cosi Service running");

    // Release the wake lock provided by the WakefulBroadcastReceiver.
    WakefulBroadcastReceiver.completeWakefulIntent(intent);

    Device device = Device.registeredDevice();

    // cozy register device url
    designUrl = device.getUrl() + "/ds-api/request/loyaltycard/all/";
    syncUrl = device.getUrl() + "/ds-api/data/";


    // concatenate username and password with colon for authentication
    final String credentials = device.getLogin() + ":" + device.getPassword();
    authHeader = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);

    showNotification();

    if (isNetworkAvailable()) {
        try {
            EventBus.getDefault().post(new LoyaltyCardSyncEvent(SYNC_MESSAGE, "Getting loyalty cards from Cozy..."));
            getRemoteLoyaltyCards();
            mNotifyManager.cancel(notification_id);
            sendChangesToCozy();
            EventBus.getDefault().post(new LoyaltyCardSyncEvent(REFRESH, "Sync OK"));
        } catch (Exception e) {
            e.printStackTrace();
            mSyncRunning = false;
            EventBus.getDefault().post(new LoyaltyCardSyncEvent(SERVICE_ERROR, e.getLocalizedMessage()));
        }
    } else {
        mSyncRunning = false;
        EventBus.getDefault().post(new LoyaltyCardSyncEvent(SERVICE_ERROR, "No Internet connection"));
        mBuilder.setContentText("Sync failed because no Internet connection was available");
        mNotifyManager.notify(notification_id, mBuilder.build());
    }
}
项目:SimpleGCM    文件:GcmRegistrationService.java   
private void releaseWakeLock() {
    if (gcmIntent.getBooleanExtra(Constants.EXTRA_HAS_WAKELOCK, false)) {
        Intent intent = gcmIntent;
        gcmIntent = null;
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    } else {
        gcmIntent = null;
    }
}
项目:xDrip    文件:ExternalStatusService.java   
@Override
protected void onHandleIntent(Intent intent) {

    if (intent == null)
        return;

    try {
        final String action = intent.getAction();
        if (action == null) return;

        if (ACTION_NEW_EXTERNAL_STATUSLINE.equals(action)) {
            String statusline = intent.getStringExtra(EXTRA_STATUSLINE);
            if (statusline != null) {

                if (statusline.length() > MAX_LEN) {
                    statusline = statusline.substring(0, MAX_LEN);
                }

                // store the data
                PersistentStore.setString(EXTERNAL_STATUS_STORE, statusline);
                PersistentStore.setLong(EXTERNAL_STATUS_STORE_TIME, JoH.tsl());

                // notify observers
                NewDataObserver.newExternalStatus();

            }
        }
    } finally {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
项目:xDrip-plus    文件:ExternalStatusService.java   
@Override
protected void onHandleIntent(Intent intent) {

    if (intent == null)
        return;

    try {
        final String action = intent.getAction();
        if (action == null) return;

        if (ACTION_NEW_EXTERNAL_STATUSLINE.equals(action)) {
            String statusline = intent.getStringExtra(EXTRA_STATUSLINE);
            if (statusline != null) {

                if (statusline.length() > MAX_LEN) {
                    statusline = statusline.substring(0, MAX_LEN);
                }

                // store the data
                PersistentStore.setString(EXTERNAL_STATUS_STORE, statusline);
                PersistentStore.setLong(EXTERNAL_STATUS_STORE_TIME, JoH.tsl());

                // notify observers
                NewDataObserver.newExternalStatus();

            }
        }
    } finally {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
项目:coredeathbell    文件:SubscribeService.java   
private void handleOnEnsureSubscribed(Intent intent) {
    try {
        int checkPlayservicesAvailable = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
        if (checkPlayservicesAvailable != ConnectionResult.SUCCESS) {
            // just let the MainActivity take care of it.

            Intent activityIntent = new Intent(getApplicationContext(), MainActivity.class);

            PendingIntent contentIntent = TaskStackBuilder.create(this)
                    .addNextIntentWithParentStack(activityIntent)
                    .getPendingIntent(PENDING_INTENT_PLAY_SERVICES_NOT_AVAILABLE, PendingIntent.FLAG_UPDATE_CURRENT);

            android.support.v4.app.NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.common_ic_googleplayservices)
                    .setContentTitle(getText(R.string.notification_play_services_not_available_title))
                    .setContentText(getText(R.string.notification_play_services_not_available_text))
                    .setAutoCancel(true)
                    .setContentIntent(contentIntent)
                    .addAction(R.drawable.ic_build_black_24dp, getString(R.string.notification_play_services_not_available_action_fix_it), contentIntent);

            NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            notificationManager.notify(NOTIFICATION_PLAY_SERVICES_NOT_AVAILABLE, notification.build());
        } else {
            FirebaseMessaging.getInstance().subscribeToTopic(TOPIC_NON_CORE_BLOCK_MINED);
        }

    } finally {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
项目:WirelessGyroscope    文件:UDPListenerService.java   
@Override
protected void onHandleIntent(Intent intent) {

    // This describes what will happen when service is triggered
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
项目:FMTech    文件:FlushLogsReceiver.java   
protected void onHandleIntent(Intent paramIntent)
{
  Account[] arrayOfAccount = AccountHandler.getAccounts(FinskyApp.get());
  final CountDownLatch localCountDownLatch = new CountDownLatch(arrayOfAccount.length);
  Runnable local1 = new Runnable()
  {
    public final void run()
    {
      localCountDownLatch.countDown();
    }
  };
  int i = arrayOfAccount.length;
  for (int j = 0; j < i; j++)
  {
    Account localAccount = arrayOfAccount[j];
    Object[] arrayOfObject2 = new Object[1];
    arrayOfObject2[0] = FinskyLog.scrubPii(localAccount.name);
    FinskyLog.d("Flushing event logs for %s", arrayOfObject2);
    FinskyApp.get().getEventLogger(localAccount).flush(local1);
  }
  try
  {
    if (!localCountDownLatch.await(((Long)G.flushLogsWaitTimeoutMs.get()).longValue(), TimeUnit.MILLISECONDS))
    {
      Object[] arrayOfObject1 = new Object[1];
      arrayOfObject1[0] = G.flushLogsWaitTimeoutMs.get();
      FinskyLog.d("Logs flushing took more than %d ms. Releasing wake lock.", arrayOfObject1);
    }
    FinskyPreferences.logsFlushScheduleExpiredTimestampMs.put(Long.valueOf(0L));
    WakefulBroadcastReceiver.completeWakefulIntent(paramIntent);
    return;
  }
  catch (InterruptedException localInterruptedException)
  {
    for (;;)
    {
      FinskyLog.d("Logs flushing was interrupted. Releasing wake lock.", new Object[0]);
    }
  }
}
项目:xDrip-Experimental    文件:ExternalStatusService.java   
@Override
protected void onHandleIntent(Intent intent) {

    if (intent == null)
        return;

    final String action = intent.getAction();

    try {

        if (ACTION_NEW_EXTERNAL_STATUSLINE.equals(action)) {
            String statusline = intent.getStringExtra(EXTRA_STATUSLINE);

            if(statusline.length() > MAX_LEN){
                statusline = statusline.substring(0, MAX_LEN);
            }

            if(statusline != null) {
                // send to wear
                if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("wear_sync", false)) {
                    startService(new Intent(this, WatchUpdaterService.class).setAction(WatchUpdaterService.ACTION_SEND_STATUS).putExtra("externalStatusString", statusline));
                    /*By integrating the watch part of Nightwatch we inherited the same wakelock
                     problems NW had - so adding the same quick fix for now.
                     TODO: properly "wakelock" the wear (and probably pebble) services
                    */
                    PowerManager powerManager = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
                    powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
                            "quickFix4").acquire(15000);
                }
            }
        }
    } finally {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
项目:NightWatch    文件:IntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null)
        return;

    final String action = intent.getAction();

    try {
        if (ACTION_NEW_DATA.equals(action)) {
            final double bgEstimate = intent.getDoubleExtra(Intents.EXTRA_BG_ESTIMATE, 0);
            if (bgEstimate == 0)
                return;

            int battery = intent.getIntExtra(Intents.EXTRA_SENSOR_BATTERY, 0);

            final Bg bg = new Bg();
            bg.direction = intent.getStringExtra(Intents.EXTRA_BG_SLOPE_NAME);
            bg.battery = Integer.toString(battery);
            bg.bgdelta = (intent.getDoubleExtra(Intents.EXTRA_BG_SLOPE, 0) * 1000 * 60 * 5);
            bg.datetime = intent.getLongExtra(Intents.EXTRA_TIMESTAMP, new Date().getTime());
            //bg.sgv = Integer.toString((int) bgEstimate, 10);
            bg.sgv = Math.round(bgEstimate)+"";
            bg.raw = intent.getDoubleExtra(Intents.EXTRA_RAW, 0);
            bg.save();

            DataCollectionService.newDataArrived(this, true, bg);
        }
    } finally {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
项目:CalendarTrigger    文件:MuteService.java   
@Override
public void onHandleIntent(Intent intent) {
    new MyLog(this, "onHandleIntent("
              .concat(intent.toString())
              .concat(")"));
    if (intent.getAction() == MUTESERVICE_RESET) {
        doReset();
    }
    updateState(intent);
    WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
项目:actor-platform    文件:PushReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
    Bundle extras = intent.getExtras();
    String messageType = gcm.getMessageType(intent);
    if (!extras.isEmpty()) {
        if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
            ActorSDK.sharedActor().waitForReady();
            if (extras.containsKey("seq")) {
                int seq = Integer.parseInt(extras.getString("seq"));
                int authId = Integer.parseInt(extras.getString("authId", "0"));
                Log.d(TAG, "Push received #" + seq);
                ActorSDK.sharedActor().getMessenger().onPushReceived(seq, authId);
                setResultCode(Activity.RESULT_OK);
            } else if (extras.containsKey("callId")) {
                long callId = Long.parseLong(extras.getString("callId"));
                int attempt = 0;
                if (extras.containsKey("attemptIndex")) {
                    attempt = Integer.parseInt(extras.getString("attemptIndex"));
                }
                Log.d(TAG, "Received Call #" + callId + " (" + attempt + ")");
                ActorSDK.sharedActor().getMessenger().checkCall(callId, attempt);
                setResultCode(Activity.RESULT_OK);
            }
        }
    }
    WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
项目:FreifunkAutoConnectApp    文件:NotificationService.java   
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d(TAG, "onStartCommand");

    // Release the wake lock
    if(intent != null) {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
    return START_STICKY;
}
项目:sync-android    文件:ReplicationService.java   
protected void releaseWakeLock(Intent intent) {
    if (intent != null) {
        // Release the WakeLock if there is one. Calling completeWakefulIntent is safe even if
        // there is no wakelock held.
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
项目:NightWatch    文件:IntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null)
        return;

    final String action = intent.getAction();

    try {
        if (ACTION_NEW_DATA.equals(action)) {
            final double bgEstimate = intent.getDoubleExtra(Intents.EXTRA_BG_ESTIMATE, 0);
            if (bgEstimate == 0)
                return;

            int battery = intent.getIntExtra(Intents.EXTRA_SENSOR_BATTERY, 0);

            final Bg bg = new Bg();
            bg.direction = intent.getStringExtra(Intents.EXTRA_BG_SLOPE_NAME);
            bg.battery = Integer.toString(battery);
            bg.bgdelta = (intent.getDoubleExtra(Intents.EXTRA_BG_SLOPE, 0) * 1000 * 60 * 5);
            bg.datetime = intent.getLongExtra(Intents.EXTRA_TIMESTAMP, new Date().getTime());
            //bg.sgv = Integer.toString((int) bgEstimate, 10);
            bg.sgv = Math.round(bgEstimate)+"";
            bg.raw = intent.getDoubleExtra(Intents.EXTRA_RAW, 0);
            bg.save();

            DataCollectionService.newDataArrived(this, true, bg);
        }
    } finally {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }
}
项目:android_packages_apps_GmsCore    文件:McsService.java   
@Override
public void run() {
    Looper.prepare();
    wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "mcs");
    wakeLock.setReferenceCounted(false);
    synchronized (McsService.class) {
        rootHandler = new Handler(Looper.myLooper(), McsService.this);
        if (connectIntent != null) {
            rootHandler.sendMessage(rootHandler.obtainMessage(MSG_CONNECT, connectIntent));
            WakefulBroadcastReceiver.completeWakefulIntent(connectIntent);
        }
    }
    Looper.loop();
}
项目:easygcm    文件:GcmRegistrationService.java   
private void releaseWakeLock() {
    if (mIntent.getBooleanExtra(EXTRA_HAS_WAKELOCK, false)) {
        Intent intent = mIntent;
        mIntent = null;
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    } else {
        mIntent = null;
    }
}
项目:Schoolbook    文件:NotificationIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    Log.d(getClass().getSimpleName(), "onHandleIntent, started handling a notification event");
    WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
项目:cosi    文件:CosiContactService.java   
@Override
protected void onHandleIntent(Intent intent) {
    // Do the task here
    Log.i(CosiContactService.class.getName(), "Cosi Service running");

    // Release the wake lock provided by the WakefulBroadcastReceiver.
    WakefulBroadcastReceiver.completeWakefulIntent(intent);

    allContacts = new ArrayList<>();

    Device device = Device.registeredDevice();

    // cozy register device url
    designUrl = device.getUrl() + "/ds-api/request/contact/all/";
    syncUrl = device.getUrl() + "/ds-api/data/";


    // concatenate username and password with colon for authentication
    final String credentials = device.getLogin() + ":" + device.getPassword();
    authHeader = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);

    showNotification();

    if (isNetworkAvailable()) {
        try {
            // read local sms log first
            //readContactDatabase();
            EventBus.getDefault().post(new CallSyncEvent(SYNC_MESSAGE, "Getting remote contacts from Cozy..."));
            getRemoteContacts();

            mBuilder.setContentText(getString(R.string.lbl_contacts_sync_done));
            mBuilder.setProgress(0, 0, false);
            mNotifyManager.notify(notification_id, mBuilder.build());

            mNotifyManager.cancel(notification_id);

            sendChangesToCozy();

            mNotifyManager.cancel(notification_id);

            EventBus.getDefault().post(new ContactSyncEvent(REFRESH, "Sync OK"));
        } catch (Exception e) {
            e.printStackTrace();
            mSyncRunning = false;
            EventBus.getDefault().post(new ContactSyncEvent(SERVICE_ERROR, e.getLocalizedMessage()));
        }
    } else {
        mSyncRunning = false;
        EventBus.getDefault().post(new ContactSyncEvent(SERVICE_ERROR, "No Internet connection"));
        mBuilder.setContentText("Sync failed because no Internet connection was available");
        mNotifyManager.notify(notification_id, mBuilder.build());
    }
}
项目:cosi    文件:CosiFileService.java   
@Override
protected void onHandleIntent(Intent intent) {
    // Do the task here
    Log.i(CosiFileService.class.getName(), "Cosi Service running");

    // Release the wake lock provided by the WakefulBroadcastReceiver.
    WakefulBroadcastReceiver.completeWakefulIntent(intent);

    allFiles = new ArrayList<>();

    Device device = Device.registeredDevice();

    // cozy register device url
    folderUrl = device.getUrl() + "/ds-api/request/folder/cosiall/";
    fileUrl = device.getUrl() + "/ds-api/request/file/cosiall/";


    // concatenate username and password with colon for authentication
    final String credentials = device.getLogin() + ":" + device.getPassword();
    authHeader = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);

    showNotification();

    if (isNetworkAvailable()) {
        try {
            // read local sms log first
            new Delete().from(File.class).execute();

            getAllRemoteFolders();
            getAllRemoteFiles();

            mBuilder.setContentText(getString(R.string.lbl_sms_sync_done));
            mBuilder.setProgress(0, 0, false);
            mNotifyManager.notify(notification_id, mBuilder.build());

            if (!allFiles.isEmpty()) {
                mNotifyManager.cancel(notification_id);
                EventBus.getDefault().post(new FileSyncEvent(REFRESH, "Sync OK"));
            } else {
                EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, "Sync failed"));
            }

        } catch (Exception e) {
            e.printStackTrace();
            mSyncRunning = false;
            EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, e.getLocalizedMessage()));
        }
    } else {
        mSyncRunning = false;
        EventBus.getDefault().post(new FileSyncEvent(SERVICE_ERROR, "No Internet connection"));
        mBuilder.setContentText("Sync failed because no Internet connection was available");
        mNotifyManager.notify(notification_id, mBuilder.build());
    }
}
项目:cosi    文件:CosiCallService.java   
@Override
protected void onHandleIntent(Intent intent) {
    // Do the task here
    Log.i(CosiCallService.class.getName(), "Cosi Service running");

    // Release the wake lock provided by the WakefulBroadcastReceiver.
    WakefulBroadcastReceiver.completeWakefulIntent(intent);

    allCalls = new ArrayList<>();

    Device device = Device.registeredDevice();

    // cozy register device url
    designUrl = device.getUrl() + "/ds-api/request/call/all/";
    syncUrl = device.getUrl() + "/ds-api/data/";


    // concatenate username and password with colon for authentication
    final String credentials = device.getLogin() + ":" + device.getPassword();
    authHeader = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);

    showNotification();

    if (isNetworkAvailable()) {
        try {
            // read local sms log first
            readCallLog();
            EventBus.getDefault().post(new CallSyncEvent(SYNC_MESSAGE, "Getting remote calls from Cozy..."));
            getRemoteCalls();

            mBuilder.setContentText(getString(R.string.lbl_sms_sync_done));
            mBuilder.setProgress(0, 0, false);
            mNotifyManager.notify(notification_id, mBuilder.build());

            if (!allCalls.isEmpty()) {
                mNotifyManager.cancel(notification_id);
                sendChangesToCozy();
                EventBus.getDefault().post(new CallSyncEvent(REFRESH, "Sync OK"));
            } else {
                EventBus.getDefault().post(new CallSyncEvent(SERVICE_ERROR, "Sync failed"));
            }

        } catch (Exception e) {
            e.printStackTrace();
            mSyncRunning = false;
            EventBus.getDefault().post(new CallSyncEvent(SERVICE_ERROR, e.getLocalizedMessage()));
        }
    } else {
        mSyncRunning = false;
        EventBus.getDefault().post(new CallSyncEvent(SERVICE_ERROR, "No Internet connection"));
        mBuilder.setContentText("Sync failed because no Internet connection was available");
        mNotifyManager.notify(notification_id, mBuilder.build());
    }
}
项目:cosi    文件:CosiExpenseService.java   
@Override
protected void onHandleIntent(Intent intent) {
    // Do the task here
    Log.i(CosiExpenseService.class.getName(), "Cosi Service running");

    // Release the wake lock provided by the WakefulBroadcastReceiver.
    WakefulBroadcastReceiver.completeWakefulIntent(intent);

    // delete local expenses
    new Delete().from(Expense.class).execute();

    Device device = Device.registeredDevice();

    // cozy register device url
    designUrl = device.getUrl() + "/ds-api/request/expense/all/";
    syncUrl = device.getUrl() + "/ds-api/data/";


    // concatenate username and password with colon for authentication
    final String credentials = device.getLogin() + ":" + device.getPassword();
    authHeader = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);

    showNotification();

    if (isNetworkAvailable()) {
        try {
            EventBus.getDefault().post(new ExpenseSyncEvent(SYNC_MESSAGE, "Getting expenses from Cozy..."));
            getRemoteExpenses();
            mNotifyManager.cancel(notification_id);
            sendChangesToCozy();
            EventBus.getDefault().post(new ExpenseSyncEvent(REFRESH, "Sync OK"));
        } catch (Exception e) {
            e.printStackTrace();
            mSyncRunning = false;
            EventBus.getDefault().post(new ExpenseSyncEvent(SERVICE_ERROR, e.getLocalizedMessage()));
        }
    } else {
        mSyncRunning = false;
        EventBus.getDefault().post(new ExpenseSyncEvent(SERVICE_ERROR, "No Internet connection"));
        mBuilder.setContentText("Sync failed because no Internet connection was available");
        mNotifyManager.notify(notification_id, mBuilder.build());
    }
}
项目:cosi    文件:CosiSmsService.java   
@Override
protected void onHandleIntent(Intent intent) {
    // Do the task here
    Log.i(CosiSmsService.class.getName(), "Cosi Service running");

    // Release the wake lock provided by the WakefulBroadcastReceiver.
    WakefulBroadcastReceiver.completeWakefulIntent(intent);

    allSms = new ArrayList<>();

    Device device = Device.registeredDevice();

    // cozy register device url
    designUrl = device.getUrl() + "/ds-api/request/sms/all/";
    syncUrl = device.getUrl() + "/ds-api/data/";


    // concatenate username and password with colon for authentication
    final String credentials = device.getLogin() + ":" + device.getPassword();
    authHeader = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.NO_WRAP);

    showNotification();

    if (isNetworkAvailable()) {
        try {
            // read local sms log first
            readSmsDatabase();
            EventBus.getDefault().post(new SmsSyncEvent(SYNC_MESSAGE, "Getting remote messages from Cozy..."));
            getRemoteMessages();

            mBuilder.setContentText(getString(R.string.lbl_sms_sync_done));
            mBuilder.setProgress(0, 0, false);
            mNotifyManager.notify(notification_id, mBuilder.build());

            if (!allSms.isEmpty()) {
                mNotifyManager.cancel(notification_id);
                sendChangesToCozy();
                EventBus.getDefault().post(new SmsSyncEvent(REFRESH, "Sync OK"));
            } else {
                EventBus.getDefault().post(new MessageEvent(SERVICE_ERROR, "Sync failed"));
            }

        } catch (Exception e) {
            e.printStackTrace();
            mSyncRunning = false;
            EventBus.getDefault().post(new MessageEvent(SERVICE_ERROR, e.getLocalizedMessage()));
        }
    } else {
        mSyncRunning = false;
        EventBus.getDefault().post(new MessageEvent(SERVICE_ERROR, "No Internet connection"));
        mBuilder.setContentText("Sync failed because no Internet connection was available");
        mNotifyManager.notify(notification_id, mBuilder.build());
    }
}
项目:Complica4    文件:NetworkTrainingService.java   
/**
 * {@inheritDoc}
 */
@Override
public int onStartCommand(Intent intent, int flags, int id) {
    /*
     * Check alarm.
     */
    setupAlarm();

    /*
     * Release wake-up lock.
     */
    if (intent.getAction() == Intent.ACTION_BOOT_COMPLETED) {
        WakefulBroadcastReceiver.completeWakefulIntent(intent);
    }

    /*
     * Single training cycle.
     */
    (new AsyncTask<Void, Void, Void>() {
        /**
         * Network training.
         */
        @Override
        protected Void doInBackground(Void... params) {
            loadNetwork();

            annTrainingError = trainNetwork();
            storeOnRemote = net;

            saveNetwork();

            /*
             * Stop service.
             */
            NetworkTrainingService.this.stopSelf();
            return null;
        }
    }).execute();

    return START_NOT_STICKY;
}
项目:ClinicalTrialTracker    文件:RssDownloadingSchedulingService.java   
@Override
protected void onHandleIntent(Intent intent) {
    // BEGIN_INCLUDE(service_onhandle)
    int count = 0;
    boolean connection_flag = true;

    ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager
            .getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    NetworkInfo mMobile = connManager
            .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (mMobile!=null&&mMobile.isAvailable())
        connection_flag=mMobile.isConnected()&&mWifi.isConnected();
    else connection_flag=mWifi.isConnected();

    mFeedProvider = new FeedProvider(this);
    mFeedProvider.openToRead();
    channelList = mFeedProvider.getAllChannelsByDate();
    mFeedProvider.close();

    deleteOutdatedArticles(channelList);

    if (connection_flag&&isConnectedToServer(URL, 5 * 1000)) {


        rssFeedList = downloadFeedFromUrl(channelList);
        if (rssFeedList != null)
            count = syncDatabaseWithFeed(rssFeedList);

        // If the app got new feeds from one or more channels, it will send
        // a notification to the user. Otherwise, it
        // remains silent.
        if (0 != count) {
            sendNotification(getString(R.string.string_synchronized)
                    + count);
            // TODO How to show tell the user which channel get updated??
            if (Constants.LOGD)
                Log.i(TAG, "New item");
        } else {
            if (Constants.LOGD)
                sendNotification(getString(R.string.string_failed));
            if (Constants.LOGD)
                Log.i(TAG, "No new Item. :-(");
        }
    }else {
        if (Constants.LOGD)
            sendNotification("No internet connection");
    }


    // Release the wake lock provided by the BroadcastReceiver.
    WakefulBroadcastReceiver.completeWakefulIntent(intent);
    // END_INCLUDE(service_onhandle)
}
项目:muzei    文件:TaskQueueService.java   
@Override
public int onStartCommand(final Intent intent, int flags, final int startId) {
    if (intent.getAction() == null) {
        stopSelf();
        return START_NOT_STICKY;
    }

    String action = intent.getAction();
    if (ACTION_DOWNLOAD_CURRENT_ARTWORK.equals(action)) {
        // Handle internal download artwork request
        new DownloadArtworkTask(this) {
            PowerManager.WakeLock lock;

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                // This is normally not started by a WakefulBroadcastReceiver so request a
                // new wakelock.
                PowerManager pwm = (PowerManager) getSystemService(POWER_SERVICE);
                lock = pwm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
                lock.acquire(DOWNLOAD_ARTWORK_WAKELOCK_TIMEOUT_MILLIS);
            }

            @Override
            protected void onPostExecute(Boolean success) {
                super.onPostExecute(success);
                if (success) {
                    cancelArtworkDownloadRetries();
                } else {
                    scheduleRetryArtworkDownload();
                }
                if (lock.isHeld()) {
                    lock.release();
                }
                WakefulBroadcastReceiver.completeWakefulIntent(intent);
                stopSelf(startId);
            }
        }.execute();

    }
    return START_REDELIVER_INTENT;
}