我使用NotificationCompat.Builder 来显示通知,并且给这个通知自定义了布局。
这个自定义布局在Android 3 或更高版本上可以运行 (API 11),但是不能在API 10 或比这低的版本上运行,我在模拟器中的 2.3 和 2.2 版本上测试。如何解决这个问题?
Builder builder = new NotificationCompat.Builder(getApplicationContext());
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification_layout);
contentView.setImageViewResource(R.id.notImage, R.drawable.stat_icon);
contentView.setTextViewText(R.id.notTitle, getResources().getString(R.string.streamPlaying));
contentView.setTextViewText(R.id.notText, StartActivity.streamName + " " + getResources().getString(R.string.playing));
builder
.setContentTitle(getResources().getString(R.string.streamPlaying))
.setContentText(StartActivity.streamName + " " + getResources().getString(R.string.playing))
.setSmallIcon(R.drawable.stat_icon)
.setContentIntent(pendingIntent)
.setOngoing(true)
.setWhen(0)
.setTicker(StartActivity.streamName + " " + getResources().getString(R.string.playing))
.setContent(contentView);
not = builder.build();
这是NotificationCompat的bug,加上两句
if(android.os.Build.Version.sdk_int<14)
notification.contentView = remoteViews