Issue
I built a pc program that works on your desktop and informs you about notifications, power-level, and lets you interact with your smartphone. All over the ADB - so no app on the phone is required. And all that in a stylish way.
But enough for that, it worked until android 5 came along.
The notification dump (adb shell dumpsys notifications) shows different outputs than in sdk <= 19
For example:
The extras region showed me detailed informations about the notifications.
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)
}
This is an example of the android 5 Notification dump. You see, there are only datatypes for strings, not the actual values.
Does anybody know how i can get the actual values? Like some parameters i am missing?
Or do you know an even better way of getting the notifications from the phone to the pc?
Solution
Well, I faced the same problem and it seems it has no solution.
I've looked at the source code and compared it to the version when everything was working. In the version 4.4.4 it was still working. Changes appeared in the version 5.0.0 and the code wasn't changed to the version 5.1.1 (the last source code version we have on the moment I'm writing this post).
So, lets look at the source code that responsible for printing extra section of notification.
As you see, it's everything ok in Android 4.4.4, the code prints string representation of the value. In Android 5.0.0 - 5.1.1 it prints only a type of value, but not the value itself.
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 + " }");
}
Answered By - nicolausYes
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.