mrb*_*rns 9 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);
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试构建软件包时,它说
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
Run Code Online (Sandbox Code Playgroud)
小智 24
我发现这种方式有效:
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Run Code Online (Sandbox Code Playgroud)
Shl*_*blu 10
这应该是Context.NOTIFICATION_SERVICE:
NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11364 次 |
| 最近记录: |