Android Notification .addAction函数

时间:2016-11-10 08:30:40

标签: android android-notifications

mDatabase.child("reportList").child(i).child("Ambulance_Coming").setValue("Rejected");

以上代码允许我发出通知。问题是,我在通知中添加了两个.addAction。现在,当我按下拒绝按钮时,我只想做这行

   NotificationCompat.Builder builder = new NotificationCompat.Builder(HomeScreenAmbulance.this);
                            builder.setSmallIcon(R.drawable.ic_launcher);
                            builder.setAutoCancel(true);
                            String header = "REPORT RECEIVED:";
                            builder.setContentTitle(header);
                            String body = "Location:"+location;
                            builder.setContentText(body);

                            Intent intent = new Intent("ph.edu.upm.agila.extendthelife.controller.rescuer.ambulance.MainScreenAmbulance");
                            intent.putExtra("FA_id",FA_id);

                            TaskStackBuilder stackBuilder = TaskStackBuilder.create(HomeScreenAmbulance.this);
                            stackBuilder.addParentStack(MainScreenAmbulance.class);
                            stackBuilder.addNextIntent(intent);

                            PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

                            builder.addAction(R.drawable.ic_launcher,"Reject",null);
                            builder.addAction(R.drawable.ic_launcher,"Accept",pendingIntent);

                            builder.setContentIntent(pendingIntent);
                            NotificationManager NM = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                            NM.notify((int) System.currentTimeMillis(),builder.build());

0 个答案:

没有答案