2015-01-20 5 views
7

मुझे आशा है कि यह किसी भी नियम का उल्लंघन नहीं करेगा जैसा कि मैंने कैसे-कैसे-पूछने वाली मार्गदर्शिका के बाद प्रयास किया है।अधिसूचना लिस्टनर सेवा स्टैक्ड अधिसूचनाओं का पाठ नहीं पढ़ रही

मैं अधिसूचना लिस्टनर सेवा का उपयोग कर आने वाली अधिसूचनाओं को पढ़ने की कोशिश कर रहा हूं और यह मेरे लिए काम करता है लेकिन केवल आंशिक रूप से।

इसके प्रकार की पहली अधिसूचना, कहें - व्हाट्सएप मैं टिकर, टेक्स्ट और शीर्षक प्राप्त कर सकता हूं लेकिन फिर नोटिफिकेशन स्टैक अप होने पर मैं अब संदेशों के पाठ को पढ़ नहीं सकता हूं।

मैं स्टैक्ड अप अधिसूचनाओं का पाठ कैसे प्राप्त करूं?

यहाँ कोड मैं वर्तमान में लागू है:

public class NotificationService extends NotificationListenerService { 

    private Context context; 


    @Override 
    public void onCreate() { 
     super.onCreate(); 
     context = getApplicationContext(); 

    } 

    @Override 
    public void onNotificationPosted(StatusBarNotification sbn) { 
     String pack = sbn.getPackageName(); 
     String ticker = sbn.getNotification().tickerText.toString(); 
     Bundle extras = sbn.getNotification().extras; 
     String title = ""; 
     String text = ""; 


     if (extras.containsKey("android.title")) { 
      title = extras.getString("android.title"); 
     } 

     if (extras.containsKey("android.text")) { 
      if (extras.getCharSequence("android.text") != null) { 
       text = extras.getCharSequence("android.text").toString(); 
      } 
     } 
     if (pack != null) { 
      Log.i("Package", pack); 
     } 

     if (ticker != null) { 
      Log.i("ticker", ticker); 
     } 

     if (title != null) { 
      Log.i("Title", title); 
     } 

     if (text != null) { 
      Log.i("Text", text); 
     } 


    } 

    @Override 
    public void onNotificationRemoved(StatusBarNotification sbn) { 

    } 


} 
+0

मेरा मानना ​​है कि यह सही/डिफ़ॉल्ट Android व्यवहार है। मैं अपने बिंदु बनाने के लिए स्रोतों की तलाश में हूं लेकिन मैंने इसी तरह के मुद्दों को देखा: आप केवल पहली बार स्टैक अधिसूचना पढ़ते हैं। – shkschneider

+0

उदाहरण के लिए ऐप एयरड्रॉइड एक ही अधिसूचना लिस्टनर सेवा विधि का उपयोग करता है और यह अधिसूचनाओं को सही ढंग से पढ़ता है, इसलिए मुझे यकीन है कि एक तरीका है कि मुझे – Bended

+0

से अवगत नहीं है क्या आपको इसके लिए कोई जवाब मिला? दस्तावेज़ के अनुसार – user1406716

उत्तर

0

मैं जानता हूँ कि अगर मैं आप missunderstood नहीं है, लेकिन मैं एक कोड है कि के खड़ी सूचनाएं whatsapp हो और एक के बाद logcat एक पर पता चलता है, केवल समस्या है कि मैं मेरा मानना ​​है कि जब मुझे पहला संदेश मिलता है, तो लॉगकैट पर मेरा टेक्स्ट मुझे शून्य दिखाता है, और पहले के बाद, सभी आने वाले संदेश काम कर रहे हैं।

'सार्वजनिक कक्षा अधिसूचना सेवा अधिसूचना लिस्टनर सेवा { संदर्भ संदर्भ बढ़ाती है; @Override

public void onCreate() { 

     super.onCreate(); 
     context = getApplicationContext(); 

    } 
    @Override 
    public void onNotificationPosted(StatusBarNotification sbn) { 

     String pack = sbn.getPackageName(); 
     String ticker = ""; 
     if (sbn.getNotification().tickerText != null) { 
      ticker = sbn.getNotification().tickerText.toString(); 
     } 
     Bitmap bmp; 
     Bundle extras; 
     byte[] byteArrayS; 
     String encoded = null; 

     extras = sbn.getNotification().extras; 
     Log.d("extras", extras.toString()); 

     String contato=""; 
     String texto = ""; 
     String search = "mensagens"; 
      if((extras.getString("android.title").toLowerCase().contains(search.toLowerCase()))){ 
       if(extras.getString("android.title").toLowerCase().contains("Whatsapp".toLowerCase())){ 
        extras.getString("android.title").replace("Whatsapp ",""); 
        Log.d("REPLACE","REPLACE CONCLUÍDO"); 
       } 

       if((extras.getString("android.text").toLowerCase().contains(search.toLowerCase()))){ 
        Log.d("MSG1","MENSAGEM NÃO AUTORIZADA"); 
       } 
      } 

      //TRATA AS NOTIFICAÇÕES FAZENDO COM QUE CADA MENSAGEM ENTRE DE UMA EM UMA DENTRO DA LISTA. 
      if (extras.getCharSequence("android.text") != "") { 
       if(extras.getString("android.summaryText")!= null) { 
        contato = extras.getString("android.title"); 
        texto = extras.getCharSequence("android.text").toString(); 
        Log.d("TEXTO1", texto); 
       } 
      } 
      if(extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES) != null){ 

       if (extras.get("android.textLines") != null) { 
        CharSequence[] charText = (CharSequence[]) extras 
          .get("android.textLines"); 
        Log.d("CHARTEXT",charText.toString()); 
        if (charText.length > 0) { 
         texto = charText[charText.length - 1].toString(); 
         Log.d("TEXTO2",texto); 
        } 

       } 
     } 



     Log.i("ContatoINTENT",contato); 
     if (texto != "") { 
      Log.i("TextoINTENT",texto); 
     } 

`

0

आप Android 7.0+ के साथ काम कर रहे हैं, WhatsApp MessageStyle विस्तारित सूचनाएं उपयोग करता है। यहाँ - https://developer.android.com/training/notify-user/expanded.html#message-style

तरह

MyFriend (5 messages) 
testt 

सूचना से सभी 5 संदेशों को प्राप्त करने के लिए यह करें:

Bundle extras = mysbn.getNotification().extras; 
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)){ 
     Parcelable b[] = (Parcelable[]) extras.get(Notification.EXTRA_MESSAGES); 

     if(b != null){ 
      content = ""; 
      for (Parcelable tmp : b){ 

       Bundle msgBundle = (Bundle) tmp; 
       content = content + msgBundle.getString("text") + "\n"; 

       /*Set<String> io = msgBundle.keySet(); // To get the keys available for this bundle*/ 

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