The purpose of the notification is to show the user an issue, and the user has two "YES" or "NO" answer options.
The problem is knowing which button the user has loaded.
Another thing I did not intend to do but that happens is that the user is redirected to an activity, and I did not want it.
If he clicks one of the buttons, he is redirected to "MainActivty", and what I intend to do only this is that mainActivity only receives any information about which button the user has uploaded, in order to make the necessary registrations. My intention is just that the user responds to the question without being redirected at all.
I leave here the piece of code where all this happens. I hope I have been as explicit as possible, and I would like to know if what I have described above is possible.
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
....
int id = (int) System.currentTimeMillis();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.DAY_OF_MONTH, 29);
calendar.set(Calendar.MONTH, 5);
calendar.set(Calendar.YEAR, 2017);
calendar.set(Calendar.HOUR_OF_DAY, 17);
calendar.set(Calendar.MINUTE, 38);
calendar.set(Calendar.SECOND, 00);
AlarmManager alarm = (AlarmManager) this.getSystemService(this.ALARM_SERVICE);
Intent newintent = new Intent(this, Notification_Create.class);
intent.putExtra("id", id);
PendingIntent pending = PendingIntent.getBroadcast(this, id, newintent, PendingIntent.FLAG_UPDATE_CURRENT);
alarm.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pending);
}
}
public class Notification_Create extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int id = extras.getInt("id");
Bundle extras = intent.getExtras();
Intent intentTPC = new Intent(context, MainActivity.class);
intentTPC.putExtra("id", String.valueOf(id));
PendingIntent resultPendingIntent =
PendingIntent.getActivity(context,
0,
intentTPC,
PendingIntent.FLAG_CANCEL_CURRENT
);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setContentTitle("Organização: ")
.setContentText("Tu hoje vais à natação?")
.setContentIntent(resultPendingIntent)
.setAutoCancel(true);
mBuilder.setSmallIcon(R.drawable.ic_button);
mBuilder.addAction(R.drawable.ic_button,"Sim",resultPendingIntent);
mBuilder.addAction(R.drawable.ic_button,"Não",resultPendingIntent);
mBuilder.setPriority(Notification.PRIORITY_MAX);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(id, mBuilder.build());
}
}