EDITO 1:
Lo que realizo es que al escribir en un EditText una fecha, la notificación se envía ese día, pero como comento arriba no funcionan correctamente los meses.
Si escribo por ejemplo 12/05 (Fecha de hoy) no se envía la notificación, pero si escribo 12/04 (mes pasado) si se envía correctamente la notificación.
Mi código es el siguiente:
public void setAlarm(Context context) {
alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, MyAlarmReceiver.class);
alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.DAY_OF_MONTH, 5);
calendar.set(Calendar.MONTH, 5);
Log.i(TAG, context.getResources().getString(R.string.app_name) + "05/05 (default)");
alarmMgr.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent);
// Enable {@code SampleBootReceiver} to automatically restart the alarm when the
// device is rebooted.
ComponentName receiver = new ComponentName(context, SampleBootReceiver.class);
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}
public void setAlarm(Context context, String date, int idPersona) {
try {
Log.i(TAG, context.getResources().getString(R.string.app_name) + date);
alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, MyAlarmReceiver.class);
/** Obtiene datos para enviar en bundle **/
intent.putExtra( "notification_id", idPersona);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
baseDatos = new DatabaseHandler(context);
Persona persona = baseDatos.getPersona(idPersona);
intent.putExtra("nombre", persona.getNombre());
intent.putExtra("idPersona", persona.getId());
intent.putExtra("fecha", persona.getFecha());
alarmIntent = PendingIntent.getBroadcast(context, idPersona, intent, 0);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
String myDate[] = date.split("/");
Log.i(TAG, "calendar.set(Calendar.DAY_OF_MONTH, " + myDate[0]);
Log.i(TAG, "calendar.set(Calendar.MONTH, " + myDate[1]);
calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(myDate[0]));
calendar.set(Calendar.MONTH, Integer.parseInt(myDate[1]));
alarmMgr.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent);
// Enable {@code SampleBootReceiver} to automatically restart the alarm when the
// device is rebooted.
ComponentName receiver = new ComponentName(context, SampleBootReceiver.class);
PackageManager pm = context.getPackageManager();
pm.setComponentEnabledSetting(receiver,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}catch (Exception e){
Log.e(TAG, "setAlarm() " + e.getMessage());
}
}