Android notification with buttons on it

前端 未结 6 645
暖寄归人
暖寄归人 2020-11-30 02:06

I\'m trying to make a notification with 2 buttons on it:

  • one takes me back to the activity
  • the other closes it

Has anyone got an idea o

6条回答
  •  野性不改
    2020-11-30 02:53

    You can simply add action Buttons in your Notification by setting action to your Notification.Builder and defining PendingIntent for each action

    below is the sample code:

        NotificationCompat.Builder mBuilder =
                    new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.notification_icon)
                    .setContentTitle("My notification")
                    .setContentText("Hello World!")
           .addAction(R.drawable.action_posetive,"posetive",PendingIntent.getActivity(0,intent,0))
    .addAction(R.drawable.action_clear,"clear",PendingIntent.getActivity(0,intent,0));
            NotificationManager mNotificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(0, mBuilder.build());
    

提交回复
热议问题