2012-09-25 13 views
7

Tıklanabilir butona sahip özel bir bildirim düzeni oluşturdum. Android 3 (API Seviye 11) veya üstü kadar iyi çalışıyor ancak Android 2.3'te çalışmaz, Notification numaralı telefondan ContentIntent her zaman düzenimi kaplar ve geçersiz kılınabilir. Ben görünümü tıklayamaz, hep Bildirimi tıklayın ve bildirim ve düzeni görüntülemek içinAndroid 2.3'teki Bildirim'de özel görünüm veya daha düşük

Kod başlatın:

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, "Title"); 
     contentView.setTextViewText(R.id.notText, "Text"); 
     contentView.setOnClickPendingIntent(R.id.notButton, secondPendingIntent); 
     contentView.setOnClickPendingIntent(R.id.notContentLayout, pendingIntent); 

     builder 
       .setContentTitle("Title") 
       .setContentText("Text") 
       .setSmallIcon(R.drawable.stat_icon) 
       .setOngoing(true) 
       .setWhen(0) 
       .setTicker("Ticket") 
       .setContent(contentView) 
       .setContentIntent(contentIntent); //this intent override my contentView.setOnClickPendintIntent. I can't click the view. 

     not = builder.build(); 

     not.contentView = contentView; 

Düzeni:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="10dp" > 

    <RelativeLayout 
     android:id="@+id/notContentLayout" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_toLeftOf="@+id/notButton" > 

     <ImageView 
      android:id="@+id/notImage" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_alignParentLeft="true" 
      android:layout_marginLeft="8dp" 
      android:layout_marginRight="23dp" 
      android:contentDescription="@string/image_desc" /> 

     <TextView 
      android:id="@+id/notTitle" 
      style="@style/NotificationTitle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/notImage" /> 

     <TextView 
      android:id="@+id/notText" 
      style="@style/NotificationText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/notTitle" 
      android:layout_toRightOf="@id/notImage" /> 
    </RelativeLayout> 

    <ImageButton 
     android:id="@+id/notButton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:background="@color/transparent" 
     android:contentDescription="@string/image_desc" 
     android:padding="10dp" 
     android:src="@android:drawable/ic_media_pause" /> 

</RelativeLayout> 

Kolay. Ama Android 2.3 veya daha düşük, herhangi bir fikir üzerinde çalışmıyor mu?

cevap

11

Bunu buldum, Android 2.3 veya daha düşük bir sürümü ile mümkün değil.
Clickally Notification düğmeleri yalnızca Android 3 veya daha üstü sürümlerde çalışır.

+1

Belgenin bulunduğu yere bağlantı verebilir misiniz? – Muzikant

+3

Maalesef belge yok, Android Engineer'dan Google + 'dan istedim. – Leandros

+0

@Leandros Bu kodu yazdıktan sonra contentView.setOnClickPendingIntent (R.id.notButton, secondPendingIntent). Düğmeni nasıl kullandın? bir örnek verebilir misiniz, bir yardım olacak. –

İlgili konular