2013-08-15 10 views
32

नहीं दिखा रहा है यह बटन के साथ अधिसूचना स्थापित करने के लिए मेरा कोड है।एंड्रॉइड अधिसूचना बटन

Intent receiverIntent = new Intent(ctx, ResponsivePrefsActivity.class); 
     PendingIntent pReceiverIntent = PendingIntent.getActivity(ctx, 1, receiverIntent, 0); 
     Intent clearIntent = new Intent(ctx, ResponsivePrefsActivity.class); 
     clearIntent.setAction("clear"); 
     PendingIntent pClearIntent = PendingIntent.getActivity(ctx, 1, clearIntent, 0); 

     Intent colorsIntent = new Intent(ctx, ResponsivePrefsActivity.class); 
     colorsIntent.setAction("colors"); 
     PendingIntent pColorsIntent = PendingIntent.getActivity(ctx, 1, colorsIntent, 0); 

     Intent animationIntent = new Intent(ctx, ResponsivePrefsActivity.class); 
     animationIntent.setAction("animation"); 
     PendingIntent pAnimation = PendingIntent.getActivity(ctx, 1, animationIntent, 0); 

     Notification.Builder builder; 
     builder = new Notification.Builder(ctx).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(false) 
       .setContentTitle("Draw Me: A Live Wallpaper").setContentText("Never get bored again!") 
       .setContentIntent(pReceiverIntent).addAction(R.raw.ic_menu_close_clear_cancel, "Clear", pClearIntent) 
       .addAction(R.raw.ic_menu_edit, "Colors", pColorsIntent).addAction(R.raw.ic_menu_play_clip, "Animation", pAnimation); 
     Notification notification = builder.build(); 

     NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); 

     notificationManager.notify(0, notification); 

अधिसूचना दिख रही है लेकिन बटन नहीं हैं। मेरे डिवाइस में एंड्रॉइड 4.1.1 है मैंने इस अधिसूचना को एक टुकड़े में स्थापित किया है। मैं क्या गलत कर रहा हूं? धन्यवाद!

उत्तर

114

मुझे आप कुछ है जो वास्तव में अजीब है सुनाता हूँ। यदि आपके पास अपने ऑनगोइंग अधिसूचना में कुछ भी है, तो आप बटन नहीं देखेंगे। आमतौर पर ऐसा होता है जब आपके पास यूएसबी के माध्यम से पीसी से कनेक्ट किया गया फ़ोन होता है। आशा है कि यह आपकी समस्या हल करे

+7

साल का जवाब ....मैंने अपने द्वारा बनाए गए अंतिम ओएस अपडेट को दोषी ठहराया (4.2.2) लेकिन इसकी सीधी गलती नहीं है .... –

+2

यह उत्तर अधिक अपवर्तनीय है! – Swayam

+17

महान उत्तर। मैं अपने नोटिसिएशन बिल्डर पर .setPriority (Notification.PRIORITY_MAX) को कॉल करके @ कैप्टन ब्लैमो उत्तर का उपयोग करके इसके आसपास भी मिला। यूएसबी – Jake

-1

बस .. अपने code

Notification n = new Notification.Builder(this) 
       .setSmallIcon(R.drawable.icon) 
       .setContentTitle("New mail from " + "[email protected]") 
       .setContentText("Subject") 
       .setContentIntent(pIntent).setAutoCancel(true) 
       .setStyle(new Notification.BigTextStyle().bigText(longText)) 
       .build(); 

     NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
     // Hide the notification after its selected 

     notificationManager.notify(0, n); 

में इस तरह कुछ परिवर्तन करना क्या आप इस में जरूरत जोड़े .. मुझे आशा है कि यह आप में मदद करता है होगा

+0

मैं पहले से ही के रूप में यह देखा जा सकता है है। मुझे setStyle विधि की आवश्यकता नहीं है क्योंकि मुझे छोटे बटन चाहिए। हालांकि मैंने जो सीखा वह यह है कि टैबलेट यूएसबी के माध्यम से पीसी से कनेक्ट होने पर नहीं दिखा रहा था। जब मैंने टैबलेट को डिस्कनेक्ट किया तो बटन दिखाए गए। यह ई-बोडा इंप्रेसपीड ई 200 और सैमसंग गैलेक्सी नोट टैब 10.1 पर जेबी के साथ हो रहा है। यह सिर्फ पागल है, आधा दिन बर्बाद हो गया! किसी और को यह समस्या मिली है? – DraganescuValentin

+0

यह सैमसंग एंड्रॉइड डिवाइसों में काफी हद तक एक बग है। तो, आप इस मुद्दे का सामना करने वाले अकेले नहीं हैं। हमेशा की तरह, सैमसंग ने अपने टचविज़ बकवास के साथ एंड्रॉइड कार्यक्षमता तोड़ दी! ... – ChuongPham

26

किसी भी समस्या के साथ किसी के लिए बस एक अनुस्मारक। एंड्रॉयड Notifications Guide के अनुसार, अधिसूचना दो शैलियों में प्रदर्शित कर सकते हैं:

  • सामान्य दृश्य है, जहां कार्रवाई बटन डिफ़ॉल्ट रूप से प्रकट नहीं होते हैं (और उपयोगकर्ता ताकि उन्हें प्रकट करने के लिए के लिए में, सूचना को विस्तृत करना पड़ता है)
  • बिग व्यू, जो अधिसूचना सूची में पहली बार अधिसूचना है, या उपयोगकर्ता ने अधिसूचना का विस्तार किया है, जो दृश्यमान है।

इसलिए क्रम बिग देखें में प्रदर्शित करने के लिए मजबूर करने की अधिसूचना में, हम सभी क्या करना है बस इसे सूचना सूची के शीर्ष पर जगह है। यह जब संपत्ति को 0 पर सेट करके किया जा सकता है जो इसे अधिसूचनाओं में सबसे पुराना बनाता है! (कभी-कभी हालांकि हम इसे नहीं चाहते हैं)। तो

setWhen(0) 

आपकी अधिसूचना पर कॉल करें और आप कर चुके हैं।

+7

या यहां तक ​​कि अधिसूचना की प्राथमिकता MAX को बेहतर भी सेट करें! setPriority (Notification.PRIORITY_MAX) – vkolias

+1

आपको इसे एक उत्तर के रूप में जोड़ना चाहिए था! अच्छा भगवान आपको आशीर्वाद दे सकता है! – Swayam

+3

मैं एंड्रॉइड 4.4 – Calin

21

बटन तब दिखाई नहीं देंगे जब सूची में कोई भी जारी सूचना नहीं है, जैसे मीडिया प्लेयर नियंत्रण, या जब आप टेक्स्ट संपादित कर रहे हों IME स्विचर विकल्प।

सौभाग्य से, यह अधिसूचना की प्राथमिकता को उच्च और उच्च निर्धारित करके आसानी से दूर किया जा सकता है। मैंने कभी भी इस बारे में जानने के लिए अधिसूचना का उपयोग किया है। PRIORITY_MAX, लेकिन PRIORITY_HIGH भी काम करता प्रतीत होता है। इस तरह यह सेट करें:

Notification notification = new Notification.Builder(myContext) 
.setContentTitle(res.getString(R.string.my_title)) 
.setPriority(Notification.PRIORITY_MAX) 
//The rest of your options 
.build(); 
+0

पर यह काम करने के लिए 'setWhen (0)' और 'setPriority (MAX) 'दोनों को रखने के लिए समाप्त हुआ, यह केवल api> = 16, btw के लिए काम करता है –

16

बस ऐसा करें :::

.setPriority(Notification.PRIORITY_MAX) 
.setWhen(0) 

पूरा कोड है:

Notification noti = new Notification.Builder(this) 
      .setContentTitle("New mail from " + "[email protected]") 
      .setContentText("Subject").setSmallIcon(R.drawable.ic_launcher) 
      .setContentIntent(pIntent) 
      .setPriority(Notification.PRIORITY_MAX) 
      .setWhen(0) 
      .addAction(R.drawable.ic_launcher, "Call", pIntent) 
      .addAction(R.drawable.ic_launcher, "More", pIntent) 
      .addAction(R.drawable.ic_launcher, "And more", pIntent).build(); 
संबंधित मुद्दे