android 4.1版本的NotificationCompat兼容性问题

android4.1之后推荐使用NotificationCompat和他的附属类如NotificationCompat.builder来构建通知,但是NotificationCompat.builder的setContent(RemoteViews view)方法在2.3以前的系统上会失效,RemoteViews主要是用来自定义通知的样式的

android 4.1的写法:

RemoteViews view = new RemoteViews(this.getPackageName(), R.layout.notification);
NotificationCompat.Builder build = new NotificationCompat.Builder(
				getApplication()).setSmallIcon(R.drawable.taoquan)
				.setContent(view)
				.setAutoCancel(true);

 android 2.3的写法:

Notification notify = build.build();
notify.contentView = view;  //和老的Notification一样

猜你喜欢

转载自yanfeijun.iteye.com/blog/1918176