Sorry for stupid question... I try to integrate a notification bar on AlarmManager class (same code runs perfectly in a new activity).
Context context = getApplicationContext(); and
Intent notificationIntent = new Intent(this, AlarmManager.class);
is not correct does this?
public class AlarmReceiver extends BroadcastReceiver {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager;
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Alarm worked.", Toast.LENGTH_LONG).show();
mNotificationManager = (NotificationManager) context.getSystemService(ns);
int icon = android.R.drawable.stat_notify_chat;
CharSequence tickerText = "tickerText";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "Title";
CharSequence contentText = "Text";
Intent notificationIntent = new Intent(this, AlarmManager.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, notification);