我使用NotificationCompat.Builder
通过android版本显示我的通知,并对通知使用自定义布局。
自定义布局在Android3和更高版本(API级别11)上运行良好,但在API级别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和更低版本下就不行了。
https://stackoverflow.com/questions/12574386
复制相似问题