package user.example.test;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import android.app.AlertDialog.*;
import android.app.Dialog;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Build;
import android.view.*;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onCreate(Bundle savedInstanceState) {
Notification.Builder builder = new Notification.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher_round)
.setContentTitle("標題")
.setContentText("訊息內容")
.setAutoCancel(true);
NotificationChannel channel = new NotificationChannel("channel_1", "123", NotificationManager.IMPORTANCE_LOW);
NotificationManager notifyManger = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notifyManger.createNotificationChannel(channel);
notifyManger.notify(1, builder.build());
}
}
new NotificationChannel會顯示紅色
Android Notification Channel(通知渠道)
https://badgameshow.com/fly/android-notification%e9%80%9a%e7%9f%a5/fly/android/