Reputation: 453
package com.test.app;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class runOnBoot extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
}
}
When I try to build the package, it says
compile:
[javac] Compiling 2 source files to /home/mrburns/Desktop/myapp/bin/classes
[javac] /home/mrburns/Desktop/myapp/src/com/test/app/runOnBoot.java:14: cannot find symbol
[javac] symbol : variable NOTIFICATION_SERVICE
[javac] location: class runOnBoot
[javac] NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
[javac] ^
[javac] 1 error
BUILD FAILED
Upvotes: 13
Views: 16647
Reputation: 11
This should be
notificationManager = (NotificationManager) getSystemService(android.content.Context.NOTIFICATION_SERVICE);
Upvotes: 0
Reputation: 21
For those using Kotlin, the following line performs the same functionality as the other answers here.
val nm = context?.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
Upvotes: 2
Reputation: 35
NotificationManager mNotifyMgr = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Upvotes: 0
Reputation: 516
I found calling this way works:
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Upvotes: 30
Reputation: 5020
You should better try this
NotificationManager nm = (NotificationManager)getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
Upvotes: -2
Reputation: 11027
This should be Context.NOTIFICATION_SERVICE
:
NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Upvotes: 10