Android Notification 通知訊息| Android Fly程式筆記

文章推薦指數: 80 %
投票人數:10人

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(); messageList.add("第一條訊息"); messageList.add("第二條訊息"); messageList.add("第三條訊息"); messageList.add("第四條訊息"); messageList.add("第五條訊息"); valinboxStyle=NotificationCompat.InboxStyle(); messageList.forEach{ inboxStyle.addLine(it); } valnotification=NotificationCompat.Builder(this,packageName) .setContentTitle("多行通知") .setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.logo) .setLargeIcon(BitmapFactory.decodeResource(resources,R.drawable.icon)) .setAutoCancel(true) .setContentIntent(pendingIntent) .setStyle(inboxStyle) .build() notificationManager.notify((0..10000).random(),notification) 6.GithubGithubAndroidChannelNotification文章導覽MaterialDesignSnackbarGithub好用分享AndroidCircleProgressBar(圓形進度條)發表迴響取消回覆搜尋文章搜尋關鍵字:近期文章AndroidAnnotation利用註解也可以MD52021-12-21Android四格驗證碼或密碼2021-12-17Android合成兩張圖片並存到手機相簿2021-11-19請我喝飲料瀏覽統計線上使用者:0今日瀏覽次數:289今日瀏覽者數量:52總瀏覽次數:98,180總瀏覽者:24,040總計文章:147月曆2022年10月一二三四五六日 12345678910111213141516171819202122232425262728293031 «12月  標籤ActivityAdapterPatternAdMobAndroidAnimationAutoCompleteTextViewBitmapBridgePatternCameraCaptchaCardSwipeLayoutClipboardManagerDesignerToastDesignPatternDisplayMetricsEditTextFBFileProviderFingerprintManagerFirebaseFloatWindowGithubGradleJavaJetpackJSONKotlinLiveDataLoadingImagesAnimationLottieMaterialDesignOkhttpPickerViewRecyclerViewRetrofitSchemeSingletonPatternStorageUtilViewWebViewWidgetWindowsZoomInImageViewzxing加密貨幣Chia$34.16XCH2.98%Ethereum$1,347.88ETH2.18%GoogleAndroidandroid版本手機,Google,開放,聯盟,遊戲,版本,軟體,發行,...Android,一個android模擬器,android版本,androidtv,androidp,android模擬器,Kotlin,Java,Androidandroid模擬器,android版本,androidtv,androidp,android模擬器手機,Google,開放,聯盟,遊戲,版本,軟體,發行,,Android,Kotlin,Java,android模擬器,android版本,androidtv,androidp,android模擬器



請為這篇文章評分?