Reputation: 8946
I am trying to set notification is a broadcast reciever class..when the phone reboots..
Here is the code
public class OnBootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
aCtx=context.getApplicationContext();
String ns = aCtx.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager)getSystemService(ns);
}
}
I am getting this error "The method getSystemService(String) is undefined for the type OnBootReceiver"
Any one please help :(
Upvotes: 0
Views: 219
Reputation: 68
The getSystemService method is a member of the Context class. You seem to be trying to call it directly without referencing a Context object hence the message "The method getSystemService(String) is undefined for the type OnBootReceiver".
Changing your last line to
NotificationManager mNotificationManager = (NotificationManager)context.getSystemService(ns);
should do the trick for you.
Perhaps your confusion stems from the fact within an Activity object you can simply call the getSystemService method and it works without referencing any object. This is because the Activity class itself is a subclass of Context. Calling getSystemService() without referencing any object works in this case because the object you are calling from is a Context object.
Upvotes: 2