www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁(yè) > > 充電吧
[導(dǎo)讀]public class Notification extends Objectimplements Parcelable java.lang.Object ???? android.app.N

public class Notification extends Object
implements Parcelable java.lang.Object ???? android.app.Notification Class Overview

A class that represents how a persistent notification is to be presented to the user using theNotificationManager.

The Notification.Builder has been added to make it easier to construct Notifications.

1、創(chuàng)建NotificationManager對(duì)Notification進(jìn)行管理:


NotificationManager?mNotificationManager?=?(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

2、創(chuàng)建Notification:


Notification?mNotification?=?new?Notification.Builder(getApplicationContext())
		.setContentTitle("notification")
		.setContentText("content")
		.setSmallIcon(R.drawable.ic_launcher)
		.setLargeIcon(mBitmap)
		.setContentIntent(mPendingIntent)
		.setDefaults(Notification.DEFAULT_ALL)
		.build();

3、用NotificationManager的notify()方法將通知顯示:


//void?android.app.NotificationManager.notify(int?id,?Notification?notification)
//id:?An?identifier?for?this?notification?unique?within?your?application.
	mNotificationManager.notify(2,mNotification);


此時(shí)Notification還不能響應(yīng)點(diǎn)擊。

接下來(lái)用PendingIntent實(shí)現(xiàn)點(diǎn)擊:


Intent?intent?=?new?Intent(this,NotificationActivity.class);
//PendingIntent?android.app.PendingIntent.getActivity(Context?context,?int?requestCode,?Intent?intent,?int?flags)
PendingIntent?mPendingIntent?=?PendingIntent.getActivity(this,?0,?intent,?PendingIntent.FLAG_CANCEL_CURRENT);

用Notification.Builder.setContentIntent():

Notification?mNotification?=?new?Notification.Builder(getApplicationContext())
		.setContentIntent(mPendingIntent)

部分關(guān)鍵代碼:


//getResources()在onCreate()里,否則報(bào)空指針context為空
		//Resources?android.content.Context.getResources()
		Intent?intent?=?new?Intent(this,NotificationActivity.class);
		//PendingIntent?android.app.PendingIntent.getActivity(Context?context,?int?requestCode,?Intent?intent,?int?flags)
		PendingIntent?mPendingIntent?=?PendingIntent.getActivity(this,?0,?intent,?PendingIntent.FLAG_CANCEL_CURRENT);
		//將qq.jpg轉(zhuǎn)化為Bitmap,使用它設(shè)置大圖標(biāo)
		Bitmap?mBitmap=BitmapFactory.decodeResource(getApplicationContext().getResources(),?R.drawable.qq);
		NotificationManager?mNotificationManager?=?(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
		
		Notification?mNotification?=?new?Notification.Builder(getApplicationContext())
		.setContentTitle("notification")
		.setContentText("content")
		.setSmallIcon(R.drawable.ic_launcher)
		.setLargeIcon(mBitmap)
		.setContentIntent(mPendingIntent)
		.setDefaults(Notification.DEFAULT_ALL)
		.build();
		/*int?DEFAULT_ALL?Use?all?default?values?(where?applicable).?
		int?DEFAULT_LIGHTS?Use?the?default?notification?lights.?
		int?DEFAULT_SOUND?Use?the?default?notification?sound.?
		int?DEFAULT_VIBRATE?Use?the?default?notification?vibrate.?
		?*/
		/*setLights(int?argb,?int?onMs,?int?offMs)?
Set?the?desired?color?for?the?indicator?LED?on?the?device,?as?well?as?the?blink?duty?cycle?(specified?in?milliseconds).
		setSound(Uri?sound)?
Set?the?sound?to?play.
setVibrate(long[]?pattern)?
Set?the?vibration?pattern?to?use.
long[]?vibrates={0,1000,1000,1000}?notification到來(lái)時(shí)震動(dòng)1s停止1s再震動(dòng)1s
vibrates[0]:靜止時(shí)長(zhǎng)
vibrates[1]:振動(dòng)時(shí)長(zhǎng)
vibrates[2]:靜止時(shí)長(zhǎng)
....?*/
		//void?android.app.NotificationManager.notify(int?id,?Notification?notification)
		//id:?An?identifier?for?this?notification?unique?within?your?application.
		mNotificationManager.notify(2,mNotification);		

將qq.jpg轉(zhuǎn)化為Bitmap


Bitmap?mBitmap=BitmapFactory.decodeResource(getApplicationContext().getResources(),?R.drawable.qq);

還可以設(shè)置Notification到來(lái)時(shí)的振動(dòng),聲音,燈光效果
Notification.Builder setLights(int argb, int onMs, int offMs)Set the desired color for the indicator LED on the device, as well as the blink duty cycle (specified in milliseconds). Notification.Builder setSound(Uri sound)Set the sound to play. Notification.Builder setVibrate(long[] pattern)Set the vibration pattern to use. 或者:


Notification.Builder setDefaults(int defaults)Set which notification properties will be inherited from system defaults.

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

納祥科技推出太陽(yáng)能+Type-C雙充電自行車前燈方案,方案核心模塊包含太陽(yáng)能板、單片機(jī)、三極管、3顆LED燈珠與1200mAh電池,通過(guò)低功耗單片機(jī)與三極管驅(qū)動(dòng),支持強(qiáng)光/弱光/爆閃3種模式,高流明遠(yuǎn)射程,適配多種車型

關(guān)鍵字: 方案開(kāi)發(fā) 電子方案 自行車前燈方案 納祥科技

慕尼黑2025年9月11日 /美通社/ -- 當(dāng)?shù)貢r(shí)間9月9日,賽力斯動(dòng)力在德國(guó)慕尼黑國(guó)際車展期間舉辦技術(shù)發(fā)布與交流會(huì),正式在海外市場(chǎng)推出全新一代賽力斯超級(jí)增程、高效發(fā)動(dòng)機(jī)和新一代分布式電驅(qū)動(dòng)系統(tǒng),同時(shí)與來(lái)自全球的汽車產(chǎn)...

關(guān)鍵字: 慕尼黑 分布式 發(fā)動(dòng)機(jī) 新能源汽車

慕尼黑2025年9月11日 /美通社/ -- 高端智能電動(dòng)汽車品牌問(wèn)界(AITO)在2025年德國(guó)國(guó)際汽車及智慧出行博覽會(huì)(IAA MOBILITY)上,正式發(fā)布了其最新全球產(chǎn)品陣容——專為中東市場(chǎng)深度本地化打造的AIT...

關(guān)鍵字: AI 智能駕駛 測(cè)試 生態(tài)系統(tǒng)

舍弗勒首次為中國(guó)頭部車企大規(guī)模生產(chǎn)高壓逆變磚 天津工廠一年內(nèi)完成量產(chǎn)準(zhǔn)備,逆變器模塊性能參數(shù)顯著提升 與合作伙伴羅姆半導(dǎo)體共研尖端碳化硅技術(shù),效率更高、性能更優(yōu) 模塊化可擴(kuò)展設(shè)計(jì)使逆變磚易于集成,可廣泛...

關(guān)鍵字: 逆變 高壓 逆變器 集成

舍弗勒以"專注驅(qū)動(dòng)技術(shù)的科技公司"為主題亮相IAA MOBILITY 2025(B3館B40展臺(tái)) 合并緯湃科技后首次亮相IAA MOBILITY,展示拓展后的汽車產(chǎn)品組合 憑借在軟件、...

關(guān)鍵字: 電氣 軟件 驅(qū)動(dòng)技術(shù) BSP

拉斯維加斯2025年9月11日 /美通社/ -- 在9月8日至11日舉辦的RE+ 2025展會(huì)上,全球綜合儲(chǔ)能解決方案供應(yīng)商德賽電池(Desay Battery)全面展示了其創(chuàng)新成果,并宣布與深圳市華寶新能源股份有限公司...

關(guān)鍵字: 電池 電芯 人工智能 鋰電

香港2025年 9月12日 /美通社/ -- 全球領(lǐng)先的互聯(lián)網(wǎng)社區(qū)創(chuàng)建者 - 網(wǎng)龍網(wǎng)絡(luò)控股有限公司 ("網(wǎng)龍"或"本公司",香港交易所股票代碼:777)欣然宣布,其子公司My...

關(guān)鍵字: AI 遠(yuǎn)程控制 控制技術(shù) BSP

慕尼黑2025年9月12日 /美通社/ -- 慕尼黑當(dāng)?shù)貢r(shí)間9月10日,在2025德國(guó)國(guó)際汽車及智慧出行博覽會(huì)(IAA MOBILITY)上,國(guó)際獨(dú)立第三方檢測(cè)、檢驗(yàn)和認(rèn)證機(jī)...

關(guān)鍵字: 測(cè)試 慕尼黑 模型 HUBER

上海2025年9月12日 /美通社/ -- 近日,國(guó)際獨(dú)立第三方檢測(cè)、檢驗(yàn)和認(rèn)證機(jī)構(gòu)德國(guó)萊茵TÜV大中華區(qū)(簡(jiǎn)稱"TÜV萊茵")為上海...

關(guān)鍵字: 測(cè)試 信息安全 安全管理 開(kāi)關(guān)

廣州2025年9月12日 /美通社/ -- 9月11日,由國(guó)際獨(dú)立第三方檢測(cè)、檢驗(yàn)和認(rèn)證機(jī)構(gòu)德國(guó)萊茵TÜV大中華區(qū)(簡(jiǎn)稱"TÜV萊茵"...

關(guān)鍵字: 數(shù)字化 供應(yīng)鏈 控制 電子
關(guān)閉