One of the final goals of my app is to send notifications to the user at a certain time. My alarm manager is working correctly now my problem is are notifications that are not shown.
The goal is to show a notification after 10 seconds but I'm not receiving any kind of notification.
My code to send notifications:
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager mNM;
mNM = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, "Teste",
System.currentTimeMillis());
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);
notification.setLatestEventInfo(context, "TESTE" , "Teste", contentIntent);
mNM.notify(0, notification);
}
}
I call the receiver through my alarm manager:
PendingIntent alarmIntent;
Intent intent = new Intent(context, AlarmReceiver.class);
alarmIntent = PendingIntent.getActivity(context, 0, intent, 0);
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.SECOND, 10);
long firstTime = calendar.getTimeInMillis();
AlarmManager am = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, firstTime, alarmIntent);
I added it to my AndroidManifest.xml :
<receiver android:process=":remote" android:name="AlarmReceiver"></receiver>