Reputation: 764
Using NotificationCompat.Builder
, I am creating a incoming call notification, PRIORITY_HIGH
notification with vibrate and ongoing set to true.
When notify()
is called it also starts the ringtone player, playing the ringtone.
Currently this works perfectly. The answer and decline actions work fine, the only nuance is if you swipe away the notification, its demoted to the status bar (that is fine) but I also want the ringtone player to stop at this point.
Is there a way I can be told, or tell that the heads up notification has been swiped up into the status bar?
Answer in comment to accepted answer.
Problem was resolved by adding ringtone to the builder with .setSound(). Thanks A.A
Upvotes: 2
Views: 418
Reputation: 6849
what you need is a deleteIntent
deleteIntent
The intent to execute when the notification is explicitly dismissed by the user, either with the "Clear All" button or by swiping it away individually. This probably shouldn't be launching an activity since several of those will be sent at the same time.
You can set the PendingIntent
to a BroadcastReceiver
and then perform any action you want.
Intent intent = new Intent(this, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), 0, intent, 0);
Builder builder = new Notification.Builder(this):
builder.setDeleteIntent(pendingIntent);
And for the BroadcastReceiver
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// stop your ringtone here
}
}
Upvotes: 2