コード例 #1
0
  /**
   * Used to return from the notification to the main activity
   *
   * @return PendingIntent THe intent to create
   */
  private PendingIntent getPendingIntent() {
    Intent intent = new Intent(mController.getApplicationContext(), MainActivity.class);
    intent.setFlags(
        Intent.FLAG_ACTIVITY_CLEAR_TASK
            | Intent.FLAG_ACTIVITY_NO_ANIMATION
            | Intent.FLAG_ACTIVITY_NEW_TASK);

    return PendingIntent.getActivity(
        mController.getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  }
コード例 #2
0
  private PendingIntent getBroadcastIntent(String command) {
    PendingIntent pi;

    Intent intent = new Intent(mController.getApplicationContext(), BalataNotifierService.class);
    intent.putExtra("COMMAND", command);

    pi =
        PendingIntent.getService(
            mController.getApplicationContext(), 12345, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    return pi;
  }
コード例 #3
0
  public void stopNotification() {
    NotificationManager notify_manager =
        (NotificationManager)
            mController.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);

    notify_manager.cancel(NOTIFY_ID);
  }
コード例 #4
0
  public void updateNotification() {
    if (!mNotificationVisible) return;

    NotificationManager notify_manager =
        (NotificationManager)
            mController.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);

    notify_manager.notify(NOTIFY_ID, createNotification());
  }
コード例 #5
0
  public Notification createNotification() {
    mNotifyBuild =
        new NotificationCompat.Builder(mController.getApplicationContext())
            .setContentTitle(mController.getString(R.string.balatafm))
            .setSmallIcon(R.drawable.ic_notification)
            .setContentIntent(getPendingIntent());

    mNotifyBuild.setContentText(getNotificationString());

    if (mPlayerState.isBuffering()) {
      mNotifyBuild.setProgress(0, 0, true);
    } else {
      if (mPlayerState.isPlaying()) {
        mNotifyBuild.addAction(R.drawable.player_stop, "Stop", getBroadcastIntent("stop"));
        mNotifyBuild.setOngoing(true);
      } else {
        mNotifyBuild.addAction(R.drawable.player_play, "Play", getBroadcastIntent("play"));
      }
    }

    mNotificationVisible = true;
    return mNotifyBuild.build();
  }