を使用しNotificationCompat.Builder
てAndroidバージョンで通知を表示し、通知にカスタムレイアウトを使用します。
カスタムレイアウトはAndroid3以降(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();
本当に基本的です。レイアウトファイルは正しく、android.comの通知チュートリアルと同じで、間違いがないことを確認しています。;)
覚えておいてください:3.0以降では正常に動作しますが、2.3以下では動作しません。