现在的位置: 首页 > 综合 > 正文

Notification

2017年11月28日 ⁄ 综合 ⁄ 共 1197字 ⁄ 字号 评论关闭

左边的大图为 largeIcon

右边的Android小机器人为smallIcon

若不设置largeIcon,则为以下样式

setTicket:设置Notification出来时在状态栏显示的信息

另外,setContentInfo("ContentInfo")和setNumber(4);其显示位置一致

	public void notify(View view) throws Exception
	{
		//Notification add Light/Sound/Vibrate
		int defaultType = 0;
		defaultType |= Notification.DEFAULT_LIGHTS;
		defaultType |= Notification.DEFAULT_SOUND;
		defaultType |= Notification.DEFAULT_VIBRATE;
		
		NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
		builder.setDefaults(defaultType);
//		builder.setContentInfo("ContentInfo");
		builder.setNumber(4);
		builder.setContentText("ContentText");
		builder.setContentTitle("ContentTitle");
		
		builder.setSmallIcon(R.drawable.ic_launcher);
		builder.setLargeIcon(BitmapFactory.decodeStream(getAssets().open("a.png")));
		builder.setTicker("Ticker");
		builder.addAction(android.R.drawable.ic_delete, "Delete1", null);
		builder.addAction(android.R.drawable.ic_delete, "Delete2", null);
		
		builder.setStyle(new NotificationCompat.BigTextStyle()
				.setBigContentTitle("BigTextTitle")
				.setSummaryText("SummaryText")
				.bigText("BigTextBigText"));
		
		Notification notification = builder.build();
		NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
		manager.notify(1, notification);
	}

【上篇】
【下篇】

抱歉!评论已关闭.