Listener on a button inside a notification

Asked

Viewed 89 times

0

I’m making an app that plays a radio stream, and when it starts playing, I create a custom notification with 2 buttons, one to pause/play and one to remove the notification and stop the stream, but I was unsuccessful and the buttons do nothing, I read about Pendingintent and Broadcastreceiver but without success, someone can help me?

The codes of the buttons:

    Intent it = new Intent(MyService.this,MainActivity.class);
    it.setAction("tocando");
    it.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pi = PendingIntent.getActivity(MyService.this, 0, it, 0);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
    builder.setSmallIcon(R.drawable.ic_launcher);
    builder.setContentIntent(pi);
    Intent itt = new Intent(getApplicationContext(),MyBroadcast.class);
    itt.putExtra("comand", "pause");
    PendingIntent pitt = PendingIntent.getBroadcast(getApplicationContext(),23424324, itt, 0);
    RemoteViews view = new RemoteViews(getPackageName(), R.layout.notificacao);
    view.setOnClickPendingIntent(R.id.pause, pitt);
    builder.setContent(view);
    Notification not = builder.build();
  • Does it by any chance cause an error in Logcat ? If yes, put your button codes and Logcat error as well.

  • It generates nothing :( if possible I wanted an example because it’s hard

  • That part’s not really my thing, 'cause it’s been a while Android, but do so, post the button code because with them here it is easier someone help you and increases the chance of an answer that clarifies your doubt. :)

  • No one...?? :(

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.