I want to be able to print the device debug log on the screen…How can I do this. I have looked everywhere but can only find unity specific info.
Use an Android plugin to read the output of logcat and send back to Unity.
You can use something like this: (code was not tested, but will give you an idea on what to do)
Android code:
final StringBuilder log = new StringBuilder();
ArrayList<String> cmdLine = new ArrayList<String>();
cmdLine.add("logcat");
cmdLine.add("-d");
Process process = Runtime.getRuntime().exec(cmdLine.toArray(new String[0]));
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null)
{
log.append(line);
// TODO: Send results to Unity with UnityPlayer.UnitySendMessage()
}
That seems a bit out of my comfort zone…
But I guess I could learn learn something new. Can you point me in the right direction to do this, from the beginning?
- Prepare setup to create your Android plugin: http://docs.unity3d.com/Documentation/Manual/PluginsForAndroid.html
- Create Android AsyncTask to run this code.
- Create Android function in your plugin to execute your AsyncTask. Something simple like: new LogTask().execute();
- Call this function from Unity: http://docs.unity3d.com/Documentation/Manual/PluginsForAndroid.html
Thanks, I will work on it.
Appreciate you help…![]()