Using Log.d() on Android Studio, I print a relatively long json, only a part of it is displayed, and I want to view the complete one, what should I do?
Ofcourse, separating the content is a way we can think of directly, but isn't it not so cool?
You can break the answer into chunks and display them one by one:
var str = jsonObj.toString()
var k = 1000; //or a smaller value, idk..
for (i in 0..str.length step k) {
Log.d(yourTag, str.substring(i, minOf(i + k, str.length)))
}
Related
I am currently trying to understand the output of my batterystats after following the instructions listed here by Google: https://developer.android.com/studio/command-line/dumpsys#inspect_machine-friendly_output
In the identifiers section there is something call "pwi" or Power Use Item and it mentions that it can be read as label/mAh, but when I look at my output I do not seem to understand what it is telling me.
10254 l pwi uid 84.8 0 51.0 112
Is 84.8 the label and 0 is the mAh? What kind of information can I learn from this?
So what I've been able to find is that the line is being printed in: https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/os/BatteryStats.java
search for POWER_USE_ITEM_DATA using the search webpage Find button tool. I think what you are seeing is dumpLine on line #4563,
private static final String POWER_USE_ITEM_DATA = "pwi";
final ProportionalAttributionCalculator proportionalAttributionCalculator =
new ProportionalAttributionCalculator(context, stats);
final List<UidBatteryConsumer> uidBatteryConsumers = stats.getUidBatteryConsumers();
for (int i = 0; i < uidBatteryConsumers.size(); i++) {
UidBatteryConsumer consumer = uidBatteryConsumers.get(i);
dumpLine(pw, consumer.getUid(), category, POWER_USE_ITEM_DATA, "uid",
formatCharge(consumer.getConsumedPower()),
proportionalAttributionCalculator.isSystemBatteryConsumer(consumer) ? 1 : 0,
formatCharge(consumer.getConsumedPower(BatteryConsumer.POWER_COMPONENT_SCREEN)),
formatCharge(
proportionalAttributionCalculator.getProportionalPowerMah(consumer)));
}
which appears to have the right number of fields and the '0' you are referring to is a boolean flag (system process==1 perhaps), otherwise the later items represent mAh.
In the code search site, you can click on ProportionalAttributionCalculator class to see the method's source code. I believe that file is where the other battery stats are output, so your output may require context values displayed elsewhere.
I have a simple array that takes rows from a database and assigns a distance column as a key.
let output = {};
for (let dataRow of sqllite.rows) {
output[dataRow.distance] = dataRow;
}
In testing in Chrome browser on PC, it takes less than a second to complete, but on an Android device, it just hangs.
What's the best way to handle this?
Thanks
Mark
After a stab in the dark, this fixed it. Changing from Typescript to Javascript.
let output = {};
for (var outputIndex in sqllite.rows) {
output[sqllite.rows[outputIndex].distance] = sqllite.rows.rows[outputIndex];
}
No idea why TS is slower
For some reason, when I restart my PhoneGap app - it looses the localStorage vales that were stored before! I'm saving them in the normal way:
localStorage.setItem("foo","value");
This stores it just fine. However, when you restart the app (or leave the device off for a random amount of time), it seems to randomly loose the data. I've found a heck of a lot of posts about this - but no definative answer on how to get it to be persistent in a PhoneGap Build WebView app,
Any suggestions are much welcomed!
This seems to be quite a common problem with WebView apps:
Android 2.3.6 + Phonegap + localStorage
Android - Making Webview DomStorage persistant after app closed
I can't find a solution that works with PhoneGap Build apps though
An actual example I'm using, is:
var current_id = parseInt(currentId) + 1;
localStorage.setItem("entry_"+current_id,save_string);
localStorage.setItem("entryId",current_id);
..and then to extract it (not that this is important, as the problem is with the data going missing, and not with accessing it)
for (var i = 0; i < localStorage.length; i++){
if (localStorage.key(i).match("entry_")) {
outputString += "\n" + localStorage.getItem(localStorage.key(i));
}
}
I'm wondering if maybe upgrading from PhoneGap Build cli-5.2.0 to cli-6.0.0 may help. I will do this, and give it a whirl.
I guess another option, would be to use a SQL database to locally store the device (its just a bit trickier to setup, and means re-writing my code)
UPDATE: Not the ideal solution - but I have now moved the app over to use WebSQL for the app. It was a bit tricky to get the hang of (never used it before) - but seems to do the job, and shouldn't loose the data :)
EDIT
i tried it like this and it worked:
var current_id = parseInt(currentId) + 1;
localStorage.setItem("entry_"+current_id,save_string);
localStorage.setItem("entryId",current_id);
/*
//this is for checking, what is stored in localStorage
console.log("length: " + localStorage.length);
for(var i = 0; i < localStorage.length; i++) {
console.log(localStorage.key(i));
}
*/
var myEntryIdFromStorage = localStorage.getItem("entryId");
var myItem = localStorage.getItem("entry_" + myEntryIdFromStorage);
Old answer for clarification
How do you get your localstorage?
normally you should store items like you did:
var permanentStorage = window.localstorage;
permanentStorage.setItem("foo", "bar");
and get them back by initializing the permanentStorage the same way and:
//assuming you have permanentStorage in the same script file
//or else you have to initialize it again:
//var permanentStorage = window.localstorage;
var myItem = permanentStorage.getItem("foo");
console.log("myItem: " + myItem);
The method store item uses two parameters: the identifier and the data itself. Please check, that the identifier with which you store your data is the same as the one, with which you get it back.
Do you get any errors? Is the return (stored in my example in myItem) null or undefined or just an empty string? Does this fail in the browser or on the device?
You could clarify your question by providing more code or error messages!
addressBar = (AutoCompleteTextView) mActivity.findViewById(package.R.id.addressBar);
TouchUtils.tapView(this, addressBar);
sendKeys("1"); //Works
sendKeys("G M A I L"); // Works - Result would be "gmail"
sendKeys("G M A I L . C O M"); // Doesn't work
sendKeys("{.}"); // Doesn't work
sendKeys("gmail") // Doesn't work
sendKeys("G M A I L {.} C O M") //Doesn't work
I am writing android test scripts using "InstrumentationTestCase2". I actually want to sendkeys - "gmail.com" but, unable to send special character "."(Dot)
For '.' (period or dot) you can try the int equivalent values of it.
Like,
sendKeys(56);
From Android-Docs
public static final int KEYCODE_PERIOD
Key code constant: '.' key.
Constant Value: 56 (0x00000038)
"The sequence of keys is a string containing the key names as specified in KeyEvent, without the KEYCODE_ prefix." (sendKeys documentation)
So you can use NUMPAD_DOT in the sendKeys string.
e.g.
sendKeys("G M A I L NUMPAD_DOT C O M");
For Further information see :
(http://developer.android.com/reference/android/test/InstrumentationTestCase.html#sendKeys(java.lang.String))
sendKeys(56); // for special character "." (Dot)
Have you tried the following:
getInstrumentation().sendStringSync("Do.You#Love.IT???");
works like magic and makes life a lot simpler!
I'm just getting my toes wet. Using Eclipse, and am not far beyond HelloAndroid. If I have a gallery image loaded onto the screen, and I want to play around with getPixel, where do I send the resulting RGB value output so that I can read it?
Thanks.
Define a:
private static final String TAG = "YOUR TAG";
Use the Log class doing:
Log.d(TAG, "RGB is " + rgb);
You can see logs with logcat.
I believe the proper way would be to write:
Log.d(TAG, String.format("RGB is %d", rgb));