2012-09-25 13 views
7

पर अधिसूचना में क्लिक करने योग्य कस्टम दृश्य मैंने एक कस्टम अधिसूचना लेआउट बनाया, जिसमें एक क्लिक करने योग्य बटन है। एंड्रॉइड 3 (एपीआई लेवल 11) या उच्चतर पर अब तक ठीक काम करता है, लेकिन एंड्रॉइड 2.3 पर काम नहीं करता है, ContentIntentNotification से हमेशा मेरे लेआउट को ओवरले करता है और ओवरराइड नहीं किया जा सकता है। मैं दृश्य क्लिक नहीं कर सकते, मैं हमेशा अधिसूचना क्लिक करें और अधिसूचना और लेआउट प्रदर्शित करने के लिएएंड्रॉइड 2.3 या कम

कोड शुरू:

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; 

लेआउट:

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

आसान। लेकिन एंड्रॉइड 2.3 या उससे कम, किसी भी विचार पर काम नहीं करते?

उत्तर

11

मुझे यह पता चला, यह एंड्रॉइड 2.3 या उससे कम के साथ संभव नहीं है।
क्लिक करने योग्य Notification बटन केवल एंड्रॉइड 3 या उच्चतम पर काम करते हैं।

+1

क्या आप इसे कहां दस्तावेज कर सकते हैं इसके लिए एक लिंक प्रदान कर सकते हैं? – Muzikant

+3

अफसोस की बात है कि कोई दस्तावेज़ नहीं है, मैंने Google+ के माध्यम से एक एंड्रॉइड इंजीनियर से पूछा। – Leandros

+0

@Leandros इस कोड सामग्री को लिखने के बाद View.setOnClickPendingIntent (R.id.notButton, secondPendingIntent)। आपने अपना बटन कैसे इस्तेमाल किया क्या आप एक उदाहरण दे सकते हैं यह एक मदद होगी। –

संबंधित मुद्दे