国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

Android 通知欄的使用方法

瀏覽:3日期:2022-09-18 14:31:22
目錄一、設(shè)置通知內(nèi)容二、創(chuàng)建渠道三、設(shè)置通知欄的點擊操作四、顯示通知一、設(shè)置通知內(nèi)容

//CHANNEL_ID,渠道ID,Android 8.0及更高版本必須要設(shè)置 NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) //設(shè)置小圖標(biāo) .setSmallIcon(R.drawable.notification_icon) //設(shè)置標(biāo)題 .setContentTitle(textTitle) //設(shè)置內(nèi)容 .setContentText(textContent) //設(shè)置等級 .setPriority(NotificationCompat.PRIORITY_DEFAULT);二、創(chuàng)建渠道

在 Android 8.0 及更高版本上提供通知,需要在系統(tǒng)中注冊應(yīng)用的通知渠道。

private void createNotificationChannel() {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { CharSequence name = getString(R.string.channel_name); String description = getString(R.string.channel_description); //不同的重要程度會影響通知顯示的方式 int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance); channel.setDescription(description); NotificationManager notificationManager = getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel);} }

上述代碼應(yīng)該在應(yīng)用啟動時立即執(zhí)行,可以放在 Application 中進(jìn)行初始化。

三、設(shè)置通知欄的點擊操作

一般點擊通知欄會打開對應(yīng)的 Activity 界面,具體代碼如下:

//點擊時想要打開的界面 Intent intent = new Intent(this, AlertDetails.class); //一般點擊通知都是打開獨立的界面,為了避免添加到現(xiàn)有的activity棧中,可以設(shè)置下面的啟動方式 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); //創(chuàng)建activity類型的pendingIntent,還可以創(chuàng)建廣播等其他組件 PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.notification_icon) .setContentTitle('My notification') .setContentText('Hello World!') .setPriority(NotificationCompat.PRIORITY_DEFAULT) //設(shè)置pendingIntent .setContentIntent(pendingIntent) //設(shè)置點擊后是否自動消失 .setAutoCancel(true); 四、顯示通知

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); //notificationId 相當(dāng)于通知的唯一標(biāo)識,用于更新或者移除通知 notificationManager.notify(notificationId, builder.build());

還有很多特殊功能,可以直接查看官網(wǎng)教程進(jìn)行設(shè)置。

以上就是Android 通知欄的使用方法的詳細(xì)內(nèi)容,更多關(guān)于Android 通知欄的使用的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 一个人看的www片免费视频中文 | 日本毛片在线观看 | 亚洲精品一区最新 | 国产成人精品magnet | 成人7777| xxxxx性欧美 xxxx肥婆性bbbb欧美 | 在线观看日本亚洲一区 | 在线观看免费av网 | 久久视精品 | 免费黄网在线观看 | 日韩一区二区在线视频 | 日韩欧美一区二区三区久久 | 久久久久久久久久久久久久久久久 | 成人免费高清视频网址 | 91久久亚洲国产成人精品性色 | 国产精品久久久久毛片真精品 | 久久精品毛片 | 免费一级毛片视频 | 欧美精品日日鲁夜夜添 | 欧美日韩一本 | 欧美日韩精品免费一区二区三区 | 作爱视频在线免费观看 | 亚洲欧美综合视频 | 国产一级爱 | 亚洲一区二区三区首页 | 日韩精品免费一区二区三区 | 亚洲高清一区二区三区 | 99亚洲自拍 | 高清欧美性狂猛bbbbbbxxxx | 亚洲精品国产男人的天堂 | 成人在线观看国产 | 老师张开腿让我爽了一夜视频 | 手机看片神马午夜片 | 精品欧美一区二区三区四区 | 久久精品国产精品青草色艺 | xxxx肥婆性bbbb欧美 | 中日韩美中文字幕 | 亚洲精品国产精品国自产观看 | 中文字幕在线网址 | 中文字幕一区日韩在线视频 | 亚洲www在线 |