Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/203.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 通知侦听器不会读取所有已发布的通知_Java_Android_Notifications - Fatal编程技术网

Java 通知侦听器不会读取所有已发布的通知

Java 通知侦听器不会读取所有已发布的通知,java,android,notifications,Java,Android,Notifications,下面是读取通知的简单代码 public void onNotificationPosted(StatusBarNotification sbn) { String pack = sbn.getPackageName(); Bundle extras = sbn.getNotification().extras; String title = (String)extras.getCharSequence("android.title"); String text="

下面是读取通知的简单代码

public void onNotificationPosted(StatusBarNotification sbn) {
    String pack = sbn.getPackageName();
    Bundle extras = sbn.getNotification().extras;
    String title = (String)extras.getCharSequence("android.title");
    String text="";
    if (extras.getCharSequence("android.text") != null) {
        text =(String) extras.getCharSequence("android.text");
        Log.d("service1",text);
    }
    if(text.trim().equals("")) {
        if (extras.getCharSequenceArray("android.textLines") != null) {
            Log.d("service", "in 1st if");
            CharSequence[] charText = extras.getCharSequenceArray("android.textLines");
            if (charText.length > 0) {
                text = (String) charText[charText.length - 1];
                Log.d("service2", text);
            }
        }
    }
    if(text.trim().equals("")) {
        if (extras.getCharSequence("android.infoText") != null) {
            Log.d("service", "in 2nd if");
            text = (String) extras.getCharSequence("android.infoText");
            Log.d("service2", text);
        }
    }
对于白色背景通知,该代码工作得非常好。但是,对于黑色背景的通知,我会收到
text=null

我尝试过使用远程视图。但是,它甚至不读取白色背景通知

public void onNotificationPosted(StatusBarNotification sbn) {
    String pack = sbn.getPackageName();
    Bundle extras = sbn.getNotification().extras;
    String title = (String)extras.getCharSequence("android.title");
    String text="";
    if (extras.getCharSequence("android.text") != null) {
        text =(String) extras.getCharSequence("android.text");
        Log.d("service1",text);
    }
    if(text.trim().equals("")) {
        if (extras.getCharSequenceArray("android.textLines") != null) {
            Log.d("service", "in 1st if");
            CharSequence[] charText = extras.getCharSequenceArray("android.textLines");
            if (charText.length > 0) {
                text = (String) charText[charText.length - 1];
                Log.d("service2", text);
            }
        }
    }
    if(text.trim().equals("")) {
        if (extras.getCharSequence("android.infoText") != null) {
            Log.d("service", "in 2nd if");
            text = (String) extras.getCharSequence("android.infoText");
            Log.d("service2", text);
        }
    }
有人能帮忙吗

编辑: 我已经在API21版本手机上检查了这段代码。我完全同意电池医生,灰色背景中出现的天气通知,使用远程视图,这种方法不会读取这些通知

我收到英国广播公司新闻,
截图
4个应用程序更新
通知


但是,对于可以读懂你的思想的
计算机程序通知和
运动有助于你的第一颗心。
,我只收到包裹名称,标题和文本都为空。

文本与背景有何关联?我不确定这是一个正确的结论。请详细说明您的错误。如果它们是自定义远程视图,您将无法通过这种方式找到。@JoxTraex,请检查编辑部分。文本与背景有何关联?我不确定这是一个正确的结论。请详细说明您的错误。如果它们是自定义远程视图,您将无法通过这种方式找到它。@JoxTraex,请检查编辑部分。