Android 5 ADB通知转储错误数据

标签 android debugging notifications adb

我构建了一个可以在您的桌面上运行的电脑程序,它会通知您有关通知、电量级别的信息,并让您与您的智能手机互动。 遍布 ADB - 因此不需要手机上的任何应用程序。 所有这一切都以时尚的方式进行。

但足够了,它一直有效,直到 android 5 出现。

通知转储(adb shell dumpsys 通知)显示与 sdk 中不同的输出 <= 19

例如:

extras 区域向我显示了有关通知的详细信息。

      extras={
        android.title=String
        android.subText=null
        android.template=String
        android.showChronometer=Boolean (false)
        android.icon=Integer (2130837507)
        android.text=String
        android.progress=Integer (0)
        android.progressMax=Integer (0)
        android.showWhen=Boolean (true)
        android.rebuild.applicationInfo=ApplicationInfo (ApplicationInfo{14a2c165 com.nero.android.htc.sync})
        android.rebuild.contentView=Boolean (true)
        android.bigText=String
        android.infoText=null
        android.originatingUserId=Integer (0)
        android.progressIndeterminate=Boolean (false)
        android.rebuild=Boolean (true)
        android.rebuild.bigView=Boolean (true)
      }

这是 android 5 通知转储的示例。 你看,字符串只有数据类型,没有实际值。

有人知道我怎样才能得到实际值吗?像我缺少的一些参数?

或者您知道将通知从手机发送到电脑的更好方法吗?

最佳答案

嗯,我遇到了同样的问题,但似乎没有解决方案。

我查看了源代码并将其与一切正常时的版本进行了比较。 在 4.4.4 版本中它仍然有效。版本 5.0.0 中出现了更改,代码未更改为版本 5.1.1(我写这篇文章时我们拥有的最后一个源代码版本)。

那么,让我们看看负责打印额外通知部分的源代码。

如您所见,在 Android 4.4.4 中一切正常,代码打印值的字符串表示形式。 在 Android 5.0.0 - 5.1.1 中它只打印一种类型的值,而不是值本身。

Android 4.4.4.

if (notification.extras != null && notification.extras.size() > 0) {
    pw.println(prefix + "  extras={");
    for (String key : notification.extras.keySet()) {
        pw.print(prefix + "    " + key + "="); // <====== print key name
        Object val = notification.extras.get(key);
        if (val == null) {
            pw.println("null");
        } else {
            pw.print(val.toString()); // <====== print value here
            if (val instanceof Bitmap) {
                pw.print(String.format(" (%dx%d)",
                        ((Bitmap) val).getWidth(),
                        ((Bitmap) val).getHeight()));
            } else if (val.getClass().isArray()) {
                pw.println(" {");
                final int N = Array.getLength(val);
                for (int i=0; i<N; i++) {
                    if (i > 0) pw.println(",");
                    pw.print(prefix + "      " + Array.get(val, i));
                }
                pw.print("\n" + prefix + "    }");
            }
            pw.println();
        }
    }
    pw.println(prefix + "  }");
}

Android 5.0.0 - 5.1.1.

if (notification.extras != null && notification.extras.size() > 0) {
    pw.println(prefix + "  extras={");
    for (String key : notification.extras.keySet()) {
        pw.print(prefix + "    " + key + "="); // <====== print key name
        Object val = notification.extras.get(key);
        if (val == null) {
            pw.println("null");
        } else {
            pw.print(val.getClass().getSimpleName()); // <===== print a type, not a value itself
            if (val instanceof CharSequence || val instanceof String) {
                // redact contents from bugreports
            } else if (val instanceof Bitmap) {
                pw.print(String.format(" (%dx%d)",
                        ((Bitmap) val).getWidth(),
                        ((Bitmap) val).getHeight()));
            } else if (val.getClass().isArray()) {
                final int N = Array.getLength(val);
                pw.println(" (" + N + ")");
            } else {
                pw.print(" (" + String.valueOf(val) + ")");
            }
            pw.println();
        }
    }
    pw.println(prefix + "  }");
}

关于Android 5 ADB通知转储错误数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29673899/

相关文章:

Android:将带有可播放视频的 Intent 发送到电报应用程序

.net - 为什么并行堆栈不显示任何任务?

compiler-errors - 每10分钟发送一次电子邮件通知

java - 如何在 Android CalendarView 中的深色主题应用程序中显示浅色主题?

android - 在phonegap媒体插件中将声音文件的音量设置为0会引发nullpointer异常?

javascript - 在 Visual Studio 中从 ASP.NET 调试 javascript

debugging - 控制Fujitsu Softune调试器

ios - 具有动态警报主体的 Swift 本地通知

android - Android 中的空游标

android - 在 Web View 中访问响应 header