gpt4 book ai didi

java - 找不到符号 NOTIFICATION_SERVICE?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:17:28 49 4
gpt4 key购买 nike

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

最佳答案

我发现这样调用很有效:

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

关于java - 找不到符号 NOTIFICATION_SERVICE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6843736/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com