Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.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 Android通知没有任何作用_Java_Android_Android Notifications - Fatal编程技术网

Java Android通知没有任何作用

Java Android通知没有任何作用,java,android,android-notifications,Java,Android,Android Notifications,我的英语很差。我想要一个关于按钮按下的通知,按钮按下工作正常,因为祝酒词“没问题!”正在显示,但不要做任何事情。当按下按钮时,我在logcat中发现一个警告: W/libEGL: EGLNativeWindowType 0x75cc082010 disconnect failed 我知道我必须使用CHANNEL_ID,但这并不更好。祝酒词显示 public void sendNotification() { Toast.makeText(this, "ITS OKAY!", Toast

我的英语很差。我想要一个关于按钮按下的通知,按钮按下工作正常,因为祝酒词“没问题!”正在显示,但不要做任何事情。当按下按钮时,我在logcat中发现一个警告:

W/libEGL: EGLNativeWindowType 0x75cc082010 disconnect failed
我知道我必须使用CHANNEL_ID,但这并不更好。祝酒词显示

public void sendNotification() {
    Toast.makeText(this, "ITS OKAY!", Toast.LENGTH_SHORT).show();
    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this, "CHANNEL_ID")
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle("It is my notification's Title!")
                    .setContentText("Notification Body!");
    NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, mBuilder.build());
}

我想要一个通知,但我的代码没有做任何事情,只是祝酒!:(

如前所述,您必须为比Android O更新的版本创建通知通道。如文档中所述,您可以这样做:

 createNotificationChannel();
 Notification notification = new NotificationCompat.Builder(this, "channelID")
              .setSmallIcon(R.drawable.notification_icon)
              .setContentTitle("My notification")
              .setContentText("Much longer text that cannot fit one line...")
              .build();


 private void createNotificationChannel() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
        NotificationChannel serviceChannel = new NotificationChannel(
                "channelID",
                "Channel Name",
                importance
        );

        NotificationManager manager = getSystemService(NotificationManager.class);
        manager.createNotificationChannel(serviceChannel);
    }
}

如前所述,您必须为比Android O更新的版本创建通知通道。如文档中所述,您可以这样做:

 createNotificationChannel();
 Notification notification = new NotificationCompat.Builder(this, "channelID")
              .setSmallIcon(R.drawable.notification_icon)
              .setContentTitle("My notification")
              .setContentText("Much longer text that cannot fit one line...")
              .build();


 private void createNotificationChannel() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
        NotificationChannel serviceChannel = new NotificationChannel(
                "channelID",
                "Channel Name",
                importance
        );

        NotificationManager manager = getSystemService(NotificationManager.class);
        manager.createNotificationChannel(serviceChannel);
    }
}

您必须先创建通知通道,然后才能发送通知请在
Android fundamentals 08.1:Notifications上遵循google提供的此代码实验室:并获取详细信息:您必须先创建通知通道,然后才能发送通知请在
Android fundamentals上遵循google提供的此代码实验室08.1:通知
:并获得详细的完整活动:谢谢您,先生!工作顺利!谢谢您,先生!工作顺利!