我正试着在点击开始按钮时创建通知消息,但点击按钮后通知中心什么都没有,有什么 idea 吗?
使用IDEA在Android 14上进行测试.
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val channelId = intent?.getStringExtra("channel_id") ?: "default_id"
val pendingIntent = intent?.getParcelableExtra("pending_intent", PendingIntent::class.java)
val initializationThread = Thread {
val args = arrayOf("-Xmx2048m", "-Dwz-path=wz", "-Djava.net.preferIPv4Stack=true")
Server.getInstance(applicationContext)
Server.main(args)
}
initializationThread.start()
val notificationManager = getSystemService(ComponentActivity.NOTIFICATION_SERVICE) as NotificationManager
val channel = NotificationChannel(channelId, "OpenMapleServer Channel", NotificationManager.IMPORTANCE_DEFAULT)
notificationManager.createNotificationChannel(channel)
val builder = NotificationCompat.Builder(this, "1")
builder.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("OpenMapleServer Notification")
.setContentText("OpenMapleServer is Running")
.setContentIntent(pendingIntent)
.setChannelId("1")
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
val notification = builder.build()
notificationManager.notify(0, notification);
startForeground(startId, notification)
return START_STICKY
}