Java 无法解析方法addNotification()
我替换了此选项(它仅允许我在应用程序打开时显示通知): 使用此功能(它允许我在应用程序关闭时显示通知:Java 无法解析方法addNotification(),java,android,android-studio,compiler-errors,Java,Android,Android Studio,Compiler Errors,我替换了此选项(它仅允许我在应用程序打开时显示通知): 使用此功能(它允许我在应用程序关闭时显示通知: public class PushNotificationReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { //at this point the context has the permission to
public class PushNotificationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//at this point the context has the permission to create remote views
addNotification(context);
setResultCode(Activity.RESULT_OK);
}
private void addNotification(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
NotificationChannel channel =
new NotificationChannel("MyNotifications", "MyNotifications", NotificationManager.IMPORTANCE_DEFAULT);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "MyNotifications")
.setContentTitle("Chiamata in arrivo")
.setSmallIcon(R.mipmap.ic_launcher)
.setAutoCancel(true)
.setContentText("Apri FtoF per partecipare alla videochiamata");
NotificationManagerCompat manager = NotificationManagerCompat.from(context);
manager.notify(999, builder.build());
}
}
但现在在第283行出现此错误:无法解析方法“addNotification()”
有人知道为什么吗?
完整代码:
第(111-136)行(283)
多谢各位
public class PushNotificationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
//at this point the context has the permission to create remote views
addNotification(context);
setResultCode(Activity.RESULT_OK);
}
private void addNotification(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
NotificationChannel channel =
new NotificationChannel("MyNotifications", "MyNotifications", NotificationManager.IMPORTANCE_DEFAULT);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "MyNotifications")
.setContentTitle("Chiamata in arrivo")
.setSmallIcon(R.mipmap.ic_launcher)
.setAutoCancel(true)
.setContentText("Apri FtoF per partecipare alla videochiamata");
NotificationManagerCompat manager = NotificationManagerCompat.from(context);
manager.notify(999, builder.build());
}
}