コード例 #1
0
  protected void onHandleIntent(Intent intent) {
    Log.d(TAG, "onHandleIntent");
    if (intent.getBooleanExtra("dismiss", false)) {
      // Case 1: Dismiss intent
      intent.getIntExtra("notification_id", 1);
      cancelNotification();
      stopForeground(true);
      stopSelf(mServiceId);
    } else {
      // Case 2: Initialization for intent calls (ie: called from long pressing a departure)
      // Restriction: only one alarm can be set right now
      cancelNotification();
      mStopIdString = intent.getStringExtra("current_stop");
      mStopName = intent.getStringExtra("stop_name");
      mVehicleIdString = intent.getLongExtra("unique_id", 1);
      timeToRingAlarm = intent.getIntExtra("alarm_time", 5);
      mRestClient.getDeparturesByStop(mStopIdString, mCallback);

      // Log metrics because I'm a sucker for data
      Answers.getInstance()
          .logContentView(
              new ContentViewEvent()
                  .putContentName("NotificationAlarm")
                  .putCustomAttribute("Minutes", intent.getIntExtra("alarm_time", -1)));
    }
  }
コード例 #2
0
 @Override
 public void run() {
   // A runnable task to refresh notification data at a predetermined interval
   // Makes a web call to Retrofit to pull latest info
   mRestClient.getDeparturesByStop(mStopIdString, mCallback);
 }