2012-09-24 11 views
18

पर काम नहीं करता है, मैं एंड्रॉइड संस्करणों के माध्यम से अपनी अधिसूचना प्रदर्शित करने के लिए NotificationCompat.Builder का उपयोग करता हूं और अधिसूचना के लिए कस्टम लेआउट का उपयोग करता हूं।
कस्टम लेआउट एंड्रॉइड 3 और ऊपर (एपीआई लेवल 11) पर ठीक काम करता है, लेकिन एपीआई लेवल 10 या उससे कम पर दिखाई नहीं देता है। मैंने एम्यूलेटर में 2.3 और 2.2 पर इसका परीक्षण किया।कस्टम अधिसूचना लेआउट एंड्रॉइड 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, 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(); 

वास्तव में बुनियादी। लेआउट फ़ाइल सही है, यह सुनिश्चित करने के लिए कि मैंने वहां कोई गलती नहीं की है, यह एंड्रॉइड डॉट कॉम पर अधिसूचना ट्यूटोरियल जैसा ही है। ;)
याद रखें: 3.0 और ऊपर ठीक काम करना, लेकिन 2.3 और उससे कम नहीं।

उत्तर

37

यह समर्थन लाइब्रेरी में एक बग हो सकता है - this issue देखें।

आप सीधे contentView लगाने से उसके चारों ओर काम करने के लिए हो सकता है:

not.contentView = contentView; 
+1

ओह, हाँ। कीड़े। बहुत बहुत धन्यवाद, मैं कोशिश करूँगा। – Leandros

+3

लेआउट 2.3 और उससे कम पर अब तक काम करता है, लेकिन मैं जो बटन जोड़ा है उसे क्लिक नहीं कर सकता। यह केवल एंड्रॉइड 3 और उच्चतर पर काम करता है ... – Leandros

+3

@Leandros, नोटिफिकेशन में बटन क्लिक करने के लिए समर्थन एंड्रॉइड 3.0 तक नहीं जोड़ा गया था। – Justin

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