12
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
4

4 回答 4

26

我发现这样调用是有效的:

NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
于 2012-03-01T09:54:49.973 回答
9

这应该是Context.NOTIFICATION_SERVICE

NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
于 2011-07-27T11:46:00.743 回答
0
NotificationManager mNotifyMgr = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
于 2016-10-20T13:43:30.800 回答
-2

你最好试试这个

 NotificationManager nm = (NotificationManager)getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
于 2011-07-27T11:57:11.793 回答