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
- 2步驟5 – 傳播通知| Adobe Campaign
在此部分,我們將使用Android Notification Manager.Firebase傳播從Adobe Campaign收到的訊息.
- 3《Android》『NotificationManager』- 顯示通知訊息 ...
《Android》『NotificationManager』- 顯示通知訊息(Notifications)的基本用法 ... NotificationManager : 負責整個Android ...
- 4[Android] 25-1 Notification 通知簡介 - 給你魚竿- 痞客邦
Notification會出現在System bar上面主要的結構有三a. 小圖示, 用setSmaillIcon來設置b. 標題, 用setContentTitle來設置c. 內文, 用set...
- 52.5.8 Notification(状态栏通知)详解 - 菜鸟教程
本节引言: 本节带来的是Android中用于在状态栏显示通知信息的控件:Notification,相信大部分学Android都对他都很熟悉,而网上很多关于Notification的使用教程都是 ...