Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法解析方法addNotification()_Java_Android_Android Studio_Compiler Errors - Fatal编程技术网

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

}