Android Notification 通知訊息| Android Fly程式筆記
文章推薦指數: 80 %
Android Notification 通知訊息 · 1.Android8.0以上一定要設置Channel渠道. if (Build. · 2.一般通知 · 3.進度條通知 · 4.大圖片通知 · 5.多行通知 · 6.Github.
跳至主要內容AndroidNotification通知訊息Android8.0以上一定要設置Channel渠道一般通知進度條通知大圖片通知多行通知Github1.Android8.0以上一定要設置Channel渠道if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.O){
valchannel=NotificationChannel(packageName,"Demo",NotificationManager.IMPORTANCE_HIGH)
notificationManager=getSystemService(Context.NOTIFICATION_SERVICE)asNotificationManager
notificationManager.createNotificationChannel(channel)
}
2.一般通知valintent=Intent(this,SecondMainActivity::class.java)
valpendingIntent=PendingIntent.getActivity(this,0,intent,0)
valnotification=NotificationCompat.Builder(this,packageName)
.setContentTitle("通知")
.setContentText("收到一條消息")
.setSmallIcon(R.drawable.logo)
.setLargeIcon(BitmapFactory.decodeResource(resources,R.drawable.icon))
.setWhen(System.currentTimeMillis())
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.build()
notificationManager.notify((0..10000).random(),notification)
3.進度條通知valnotification=NotificationCompat.Builder(this,packageName)
.setContentTitle("圖片下載")
.setContentText("下載中")
.setSmallIcon(R.drawable.logo)
.setWhen(System.currentTimeMillis())
.setStyle(
NotificationCompat.BigPictureStyle()
.bigPicture(BitmapFactory.decodeResource(resources,R.drawable.icon))
)
.setProgress(100,0,false)
thread{
for(iin0..100step5){
notification.setProgress(100,i,false)
notificationManager.notify(0,notification.build())
Thread.sleep(250)
}
notification.setProgress(0,0,false)
.setContentText("下載完成")
notificationManager.notify(0,notification.build())
Thread.sleep(1000)
notificationManager.cancel(0)
}
notificationManager.notify(0,notification.build())
4.大圖片通知valintent=Intent(this,SecondMainActivity::class.java)
valpendingIntent=PendingIntent.getActivity(this,0,intent,0)
valnotification=NotificationCompat.Builder(this,packageName)
.setContentTitle("大圖通知")
.setContentText("收到一條消息")
.setSmallIcon(R.drawable.logo)
.setWhen(System.currentTimeMillis())
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setStyle(
NotificationCompat.BigPictureStyle()
.bigPicture(BitmapFactory.decodeResource(resources,R.drawable.icon))
)
.build()
notificationManager.notify((0..10000).random(),notification)
5.多行通知valintent=Intent(this,SecondMainActivity::class.java)
valpendingIntent=PendingIntent.getActivity(this,0,intent,0)
valmessageList=ArrayList
延伸文章資訊
- 1Android Studio 訊息通知Notification的方法 - YouTube
- 2Day 28 - Notification通知 - iT 邦幫忙
Android初學筆記系列第28 篇. Ivan. 6 年前‧ 16057 瀏覽. 1. Notification是顯示在狀態列(Status bar)的訊息,並在展開後可以顯示更多內容,常用在...
- 3Android Notification 實作(基本) - Medium
想要學得很完整可以直接看官方的Codelabs教學https://developer.android.com/codelabs/advanced-android-kotlin-training-...
- 4Android Notification 通知訊息| Android Fly程式筆記
Android Notification 通知訊息 · 1.Android8.0以上一定要設置Channel渠道. if (Build. · 2.一般通知 · 3.進度條通知 · 4.大圖片通知...
- 5Android通知- Android開發教學 - 極客書
setContentText("Hi, This is Android Notification Detail!"); 通知有很多可選的屬性,可以設置。要更多地了解它們,請參考Notificat...