2
I use RTP_WAKEUP to "wake up" my device when it realizes that it has notifications to release and in fact I can release notifications for 10/15 or even 20 minutes, but when I try to release a notification in 2 hours or even days this does not occur...
I leave here part of the code where I draw up the whole process. What’s wrong with me for this to happen?
Class where I create the alarm, to launch the notification.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.DAY_OF_MONTH, 25);
calendar.set(Calendar.MONTH, 6);
calendar.set(Calendar.YEAR, 2017);
calendar.set(Calendar.HOUR_OF_DAY, 20);
calendar.set(Calendar.MINUTE, 40);
calendar.set(Calendar.SECOND, 07);
// Obtém um alarm manager
AlarmManager alarmManager = (AlarmManager) getContext().getSystemService(getContext().ALARM_SERVICE);
// O id a ser usado no pending intent
int id = (int) System.currentTimeMillis();
// Prepare the intent which should be launched at the date
Intent intent = new Intent(getContext(), CriarNotificacao.class);
intent.putExtra("id", id);
// Obtém o pending intent
PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Regista o alerta no sistema.
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.DAY_OF_MONTH, 25);
calendar.set(Calendar.MONTH, 6);
calendar.set(Calendar.YEAR, 2017);
calendar.set(Calendar.HOUR_OF_DAY, 20);
calendar.set(Calendar.MINUTE, 40);
calendar.set(Calendar.SECOND, 07);
// Obtém um alarm manager
AlarmManager alarmManager = (AlarmManager) getContext().getSystemService(getContext().ALARM_SERVICE);
// O id a ser usado no pending intent
int id = (int) System.currentTimeMillis();
// Prepare the intent which should be launched at the date
Intent intent = new Intent(getContext(), CriarNotificacao.class);
intent.putExtra("id", id);
// Obtém o pending intent
PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Regista o alerta no sistema.
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
Class where I make the notification
public class CriarNotificacao extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
int id = extras.getInt("id");
PendingIntent resultPendingIntent =
PendingIntent.getActivity(context,
0,
intent,
PendingIntent.FLAG_CANCEL_CURRENT
);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setContentTitle("titulo")
.setContentText("mensagem")
.setContentIntent(resultPendingIntent)
.setAutoCancel(true);
mBuilder.setSmallIcon(R.drawable.ic_cake);
Intent resultIntent = new Intent(context, MainActivity.class);
resultIntent.putExtra("id", String.valueOf(id));
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(1500);
mNotificationManager.notify(id, mBuilder.build());
}
}
The problem is the device not "waking up", only "waking up" when the period is small (10/15 or up to 20 minutes) or has nothing to do with the "waking up", but rather because the period is long (2 hours or even days)?
– ramaral
@ramaral when the time exceeds a longer time, ie when I try to schedule a notification to from here for example +40 minutes it just does nothing, the notification does not appear
– Wouva
@ramaral and when I open the app again the notification (the one I scheduled for the +40 minutes) that was not shown appears...although the time that should have appeared has already expired
– Wouva
the strangest thing is that I have already put a relatively large interval about 20 minutes, and the application even not being open the notification appeared at the scheduled time, I very soon tested for the 40 minutes and nothing happened....
– Wouva
What I want you to clarify is whether this has anything to do with the device being "awake" or not.
– ramaral
@ramaral I think so...
– Wouva
I think the phone only wakes up when time is relatively "small"
– Wouva