पर अधिसूचना में क्लिक करने योग्य कस्टम दृश्य मैंने एक कस्टम अधिसूचना लेआउट बनाया, जिसमें एक क्लिक करने योग्य बटन है। एंड्रॉइड 3 (एपीआई लेवल 11) या उच्चतर पर अब तक ठीक काम करता है, लेकिन एंड्रॉइड 2.3 पर काम नहीं करता है, ContentIntent
Notification
से हमेशा मेरे लेआउट को ओवरले करता है और ओवरराइड नहीं किया जा सकता है। मैं दृश्य क्लिक नहीं कर सकते, मैं हमेशा अधिसूचना क्लिक करें और अधिसूचना और लेआउट प्रदर्शित करने के लिएएंड्रॉइड 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 या उससे कम, किसी भी विचार पर काम नहीं करते?
क्या आप इसे कहां दस्तावेज कर सकते हैं इसके लिए एक लिंक प्रदान कर सकते हैं? – Muzikant
अफसोस की बात है कि कोई दस्तावेज़ नहीं है, मैंने Google+ के माध्यम से एक एंड्रॉइड इंजीनियर से पूछा। – Leandros
@Leandros इस कोड सामग्री को लिखने के बाद View.setOnClickPendingIntent (R.id.notButton, secondPendingIntent)। आपने अपना बटन कैसे इस्तेमाल किया क्या आप एक उदाहरण दे सकते हैं यह एक मदद होगी। –