日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 芯聞號 > 充電吧
[導讀]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對Notification進行管理:


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);


此時Notification還不能響應點擊。

接下來用PendingIntent實現(xià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)

部分關鍵代碼:


//getResources()在onCreate()里,否則報空指針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,使用它設置大圖標
		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到來時震動1s停止1s再震動1s
vibrates[0]:靜止時長
vibrates[1]:振動時長
vibrates[2]:靜止時長
....?*/
		//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);

還可以設置Notification到來時的振動,聲音,燈光效果
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.

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