2012-09-24 13 views
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以下では正常に動作しません。

答えて

37

これはサポートライブラリのバグである可能性があります。this issueを参照してください。

あなたが直接contentViewを適用することによって、それを回避する必要がある場合があります

not.contentView = contentView; 
+1

そうそう。バグ。ありがとう、私はそれを試してみましょう。 – Leandros

+3

レイアウトは2.3以下で動作しますが、追加したボタンはクリックできません。これはAndroid 3以降でのみ動作します... – Leandros

+3

@Leandros、通知のボタンをクリックするためのサポートはAndroid 3.0まで追加されませんでした。 – Justin

関連する問題