2012-09-25 10 views
7

Utworzono niestandardowy układ powiadomień z klikalnym przyciskiem. Działa do tej pory dobrze na systemie Android 3 (poziom API 11) lub nowszym, ale nie działa w systemie Android 2.3, ContentIntent z Notification zawsze nakłada się na mój układ i nie można go przesłonić. nie mogę kliknij widok, zawsze kliknij powiadomienie i rozpocząćKlikalny widok niestandardowy w Powiadomieniu w systemie Android 2.3 lub niższym

kod do wyświetlania powiadomień i układ:

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; 

układ:

<?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> 

Easy. Ale nie działa na Androida 2.3 lub niższych, żadnych pomysłów?

Odpowiedz

11

Znalazłem to, to po prostu niemożliwe z Androidem 2.3 lub niższym. Przyciski Clickably Notification działają tylko w systemie Android 3 lub nowszym.

+1

Czy możesz podać link do miejsca, w którym jest udokumentowany? – Muzikant

+3

Niestety nie ma dokumentu, poprosiłem inżyniera Androida przez Google+. – Leandros

+0

@Leandros Po napisaniu tego kodu contentView.setOnClickPendingIntent (R.id.notButton, secondPendingIntent). Jak wykorzystałeś swój przycisk. czy możesz dać przykład, że będzie to pomoc. –

Powiązane problemy