コード例 #1
0
  public void updateNotification() {
    if (!Preferences.isNotificationEnabled() || !playServicesAvailable) return;

    String title = null;
    String subtitle = null;
    long time = 0;

    if ((this.lastPublishedLocation != null) && Preferences.isNotificationLocationEnabled()) {
      time = this.lastPublishedLocationTime.getTime();

      if ((this.lastPublishedLocation.getGeocoder() != null)
          && Preferences.isNotificationGeocoderEnabled()) {
        title = this.lastPublishedLocation.toString();
      } else {
        title = this.lastPublishedLocation.toLatLonString();
      }
    } else {
      title = this.context.getString(R.string.app_name);
    }

    subtitle =
        ServiceLocator.getStateAsString(this.context)
            + " | "
            + ServiceBroker.getStateAsString(this.context);

    notificationBuilder.setContentTitle(title);
    notificationBuilder
        .setSmallIcon(R.drawable.ic_notification)
        .setContentText(subtitle)
        .setPriority(android.support.v4.app.NotificationCompat.PRIORITY_MIN);
    if (time != 0) notificationBuilder.setWhen(this.lastPublishedLocationTime.getTime());

    this.notification = notificationBuilder.build();
    this.context.startForeground(Defaults.NOTIFCATION_ID, this.notification);
  }