2012-12-05 14 views
23

मुझे एंड्रॉइड 4.0 और उसके बाद के संस्करण के लिए स्टेटस बार में विस्तार और पतन अधिसूचना लागू करने की आवश्यकता है। मैं इस के लिए गूगल पर खोज की है, लेकिन कार्यान्वयन के लिए किसी भी कोड समाधान हो रही नहीं किया किसी को भी करता है मैं विचार को लागू करने के लिए कैसे इसअधिसूचना विस्तार और संकुचित करें एंड्रॉइड

अग्रिम धन्यवाद है

+0

सेट कर सकते हैं आप अपने अधिसूचना बिछाने रहे हैं:

notification = new NotificationCompat.Builder(context) 

यहाँ एक उदाहरण है। 'रिमोट व्यू 'कस्टम लेआउट, या डिफ़ॉल्ट' अधिसूचनाबिल्डर 'के साथ? मेरे लिए –

उत्तर

37

एक विस्तार योग्य Notification एक NotificationBig View की एक विशेष मामला है। यदि Big View अधिसूचना ड्रॉवर के शीर्ष पर नहीं है, तो यह 'बंद' दिखाया गया है और स्वाइप द्वारा विस्तार योग्य है। Android डेवलपर से उद्धरण:

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

Notification notification = new Notification.BigTextStyle(builder) 
.bigText(myText).build(); 

या

Notification notification = new Notification.BigPictureStyle(builder) 
.bigPicture(
    BitmapFactory.decodeResource(getResources(), 
    R.drawable.my_picture)).build(); 

Here एक ट्यूटोरियल है: इस प्रकार

Big ViewNotification बनाया जा सकता है।

+0

इसके सच में मददगार @Gunnar धन्यवाद – Pratik

+0

@Pratik खुशी है कि यह :) –

+0

मदद की हम एंड्रॉयड 4.0 संस्करणों में विस्तार योग्य अधिसूचना बना सकते हैं? – prateek

0

हम नीचे एंड्रॉइड 4.1 संस्करणों में विस्तारणीय अधिसूचना नहीं बना सकते हैं। लेकिन इसके बजाय हम ऐसा कर सकते हैं कि हम अधिसूचनाओं को ढेर कर सकते हैं और फिर हम अपनी सुंदर कस्टम गतिविधि के लिए लंबित इरादा सेट कर सकते हैं जो सूची में सभी अधिसूचनाएं दिखाता है। उपयोगकर्ता खुश इस :)

30
Notification noti = new Notification.Builder() 
... // The same notification properties as the others 
.setStyle(new Notification.BigPictureStyle().bigPicture(mBitmap)) 
.build(); 

आप

.setStyle(new NotificationCompat.BigTextStyle().bigText(th_alert)) 

बदलने घोषणा ठीक के साथ देखने के लिए होगा !!!

enter image description here आप कोड

Intent intent = new Intent(context, ReserveStatusActivity.class); 
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); 
NotificationManager notificationManager = 
      (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
intent = new Intent(String.valueOf(PushActivity.class)); 
intent.putExtra("message", MESSAGE); 
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); 
stackBuilder.addParentStack(PushActivity.class); 
stackBuilder.addNextIntent(intent); 
// PendingIntent pendingIntent = 
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); 

// android.support.v4.app.NotificationCompat.BigTextStyle bigStyle = new  NotificationCompat.BigTextStyle(); 
// bigStyle.bigText((CharSequence) context); 

notification = new NotificationCompat.Builder(context) 
    .setSmallIcon(R.mipmap.ic_launcher) 
    .setContentTitle(th_title) 
    .setContentText(th_alert) 
    .setAutoCancel(true) 
// .setStyle(new Notification.BigTextStyle().bigText(th_alert) ตัวเก่า 
// .setStyle(new NotificationCompat.BigTextStyle().bigText(th_title)) 
    .setStyle(new NotificationCompat.BigTextStyle().bigText(th_alert)) 
    .setContentIntent(pendingIntent) 
    .setNumber(++numMessages) 
    .build(); 

notification.sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
notificationManager.notify(1000, notification); 

या

private void sendNotification(RemoteMessage.Notification notification, Map<String, String> data) { 
     Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.logo); 

     Intent intent = new Intent(this, MainActivity.class); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); 

     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
       // .setContentTitle(notification.getTitle()) 
       .setContentTitle(getResources().getText(R.string.app_name)) 
       .setContentText(notification.getBody()) 
       .setAutoCancel(true) 
       .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) 
       .setContentIntent(pendingIntent) 
       .setStyle(new NotificationCompat.BigTextStyle().bigText(notification.getBody())) 
       .setContentInfo(notification.getTitle()) 
       .setLargeIcon(icon) 
       .setColor(Color.RED) 
       .setSmallIcon(R.drawable.logo); 

     try { 
      String picture_url = data.get("picture_url"); 
      if (picture_url != null && !"".equals(picture_url)) { 
       URL url = new URL(picture_url); 
       Bitmap bigPicture = BitmapFactory.decodeStream(url.openConnection().getInputStream()); 
       notificationBuilder.setStyle(
         new NotificationCompat.BigPictureStyle().bigPicture(bigPicture).setSummaryText(notification.getBody()) 
       ); 
      } 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 

     notificationBuilder.setDefaults(Notification.DEFAULT_VIBRATE); 
     notificationBuilder.setLights(Color.YELLOW, 1000, 300); 

     NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManager.notify(0, notificationBuilder.build()); 
    } 
+0

सही और पूर्ण उत्तर, धन्यवाद! –

+0

मेरा बिगटेक्स्ट छोटा हो गया है। यह क्लिक पर विस्तार नहीं है – TeodorKolev