18
NotificationCompat.Builder
을 사용하여 Android 버전을 통해 알림을 표시하고 알림을 위해 맞춤 레이아웃을 사용합니다.
맞춤 레이아웃은 Android 3 이상 (API 레벨 11)에서 제대로 작동하지만 API 레벨 10 이하에서는 표시되지 않습니다. 에뮬레이터에서 2.3 및 2.2에서 테스트했습니다.Android 2.3 이하에서는 맞춤 알림 레이아웃이 작동하지 않습니다.
Heres는 내 코드 :
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 이하에서는 작동하지 않아야합니다.
오, 그래. 버그. 고마워, 나는 그것을 시도 할 것이다. – Leandros
레이아웃은 2.3 이하에서 작동하지만 추가 한 버튼을 클릭 할 수 없습니다. 이것은 Android 3 이상에서만 작동합니다 ... – Leandros
@Leandros, 알림 버튼 클릭에 대한 지원은 Android 3.0까지 추가되지 않았습니다. – Justin