Не можете найти символ NOTIFICATION_SERVICE? - PullRequest
9 голосов
/ 27 июля 2011
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 ]

24 голосов
/ 01 марта 2012

Я обнаружил, что вызов этого пути работает:

NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
10 голосов
/ 27 июля 2011

Это должно быть Context.NOTIFICATION_SERVICE:

NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
0 голосов
/ 20 октября 2016
NotificationManager mNotifyMgr = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
0 голосов
/ 27 июля 2011

Вам лучше попробовать это

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