2014-04-16 6 views
5

मुझे एंड्रॉइड में डिफ़ॉल्ट अधिसूचना के बजाय एक कस्टम अधिसूचना बनाने की आवश्यकता है। वर्तमान अधिसूचना की तरह छविएंड्रॉइड में कस्टम अधिसूचना कैसे बनाएं

enter image description here

नीचे मैं इसे पसंद को अनुकूलित चाहते हैं एक आइकन, शीर्षक और संदेश है इस

enter image description here

मैं कैसे इस

+1

यहाँ http://codeversed.com/expandable-notifications-android/ – upenpat

उत्तर

7

अधिसूचना विचार

सामान्य देखें:

आपके मामले में, तुम सिर्फ एक कोशिश अधिसूचना में बड़ी तस्वीर प्रदर्शित करने के लिए, दे Notification.BigPictureStyle चाहते एक क्षेत्र जो 64 डीपी लंबा है। यहां तक ​​कि यदि आप एक बड़ी दृश्य शैली के साथ अधिसूचना बनाते हैं, तो यह विस्तारित होने तक सामान्य दृश्य में दिखाई देगा।

Content title 
Large icon 
Content text 
Content info 
Small icon 
Notification time 

सामान्य दृश्य की तरह enter image description here

बिग देखें - एक अधिसूचना की बड़ी दृश्य दिखाई देता है केवल जब अधिसूचना का विस्तार किया गया है, जो होता है, जब अधिसूचना अधिसूचना दराज के शीर्ष पर है या जब उपयोगकर्ता एक इशारा के साथ अधिसूचना फैलता है। विस्तृत सूचनाएं पहली बार Android 4.1 JellyBean [API 16] में पेश की गई थीं। Expandable notifications को Notification.Style नामक समृद्ध अधिसूचना शैली ऑब्जेक्ट्स का समर्थन करने के लिए डिज़ाइन किया गया था। इस लिंक expandable-notifications-android

आधिकारिक docs

+0

चेक वहाँ कस्टम लेआउट होने की जरूरत है क्या होगा अगर? – IteratioN7T

3

प्राप्त कर सकते हैं Expanded layouts कहा जाता है कि जो जेली बीन संस्करण से सीधे उपलब्ध है।

सूचनाएं की 2 बार देखा गया हैं:

  1. सामान्य देखें
  2. बिग देखें

एक सूचना की बड़ी दृश्य दिखाई देता है केवल जब अधिसूचना का विस्तार किया गया है, जो होता है जब अधिसूचना पर है अधिसूचना दराज के शीर्ष, या जब उपयोगकर्ता एक इशारा के साथ अधिसूचना का विस्तार करता है। विस्तृत सूचनाएं पहली बार एंड्रॉइड 4.1 जेलीबीन [एपीआई 16] में पेश की गई थीं। - सामान्य ध्यान में रखते हुए एक अधिसूचना में प्रकट होता है

Bitmap remote_picture = null; 

// Create the style object with BigPictureStyle subclass. 
NotificationCompat.BigPictureStyle notiStyle = new 
     NotificationCompat.BigPictureStyle(); 
notiStyle.setBigContentTitle("Big Picture Expanded"); 
notiStyle.setSummaryText("Nice big picture."); 

try { 
     remote_picture = BitmapFactory.decodeStream(
       (InputStream) new URL(sample_url).getContent()); 
} catch (IOException e) { 
     e.printStackTrace(); 
} 

// Add the big picture to the style. 
notiStyle.bigPicture(remote_picture); 
0

पर अधिक जानकारी आपको लगता है कि जरूरत remoteview NotificationCompat उपयोग कर सकते हैं करने के लिए

बिग देखें जैसा

enter image description here

जाओ।नीचे मैं सेट अपने कस्टम लेआउट
activity_downlaodactivity

NotificationManager manager = (NotificationManager)  getSystemService(Context.NOTIFICATION_SERVICE); 
    RemoteViews contentView = new RemoteViews(getPackageName(),R.layout.activity_downlaodactivity); 


    android.support.v4.app.NotificationCompat.Builder mBuilder = 
      new android.support.v4.app.NotificationCompat.Builder(this) 
      .setContent(contentView) 

    manager.notify(0, mBuilder.build()); 
4

मैं निम्नलिखित http://developer.android.com/wear/notifications/creating.html

के लिए सूचना बनाएं कोड जोड़ें usingby अधिसूचना बनवाने के नाम पर रखा गया।

// Specify the 'big view' content to display the long 
// event description that may not fit the normal content text. 
BigTextStyle bigStyle = new NotificationCompat.BigTextStyle(); 
bigStyle.bigText(eventDescription); 

NotificationCompat.Builder notificationBuilder = 
     new NotificationCompat.Builder(this) 
     .setSmallIcon(R.drawable.ic_event) 
     .setLargeIcon(BitmapFractory.decodeResource(
       getResources(), R.drawable.notif_background)) 
     .setContentTitle(eventTitle) 
     .setContentText(eventLocation) 
     .setContentIntent(viewPendingIntent) 
     .addAction(R.drawable.ic_map, 
       getString(R.string.map), mapPendingIntent) 
     .setStyle(bigStyle); 
संबंधित मुद्दे