我使用
NotificationCompat.Builder
通过android版本显示我的通知,并使用自定义布局进行通知。
自定义布局在Android 3及更高版本(API Level 11)上运行良好,但在API Level 10或更低版本上不会显示。我在Emulator中的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();
非常基本。布局文件是正确的,与android.com上的通知教程中的相同,以确保我没有在其中犯错误。;)
记住:3.0及以上版本运行良好,但2.3及以下版本则不然。