找不到符号NOTIFICATION_SERVICE?

时间:2011-07-27 11:43:38

标签: java android notificationmanager

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);
   }
}

当我尝试构建软件包时,它说

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 个答案:

答案 0 :(得分:24)

我发现这种方式有效:

NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

答案 1 :(得分:10)

这应该是Context.NOTIFICATION_SERVICE

NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

答案 2 :(得分:0)

NotificationManager mNotifyMgr = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

答案 3 :(得分:-1)

你最好试试这个

 NotificationManager nm = (NotificationManager)getSystemService(getApplicationContext().NOTIFICATION_SERVICE);