qarasique
qarasique

Reputation: 231

How to get debug logs in runtime?

Debug console in Android Studio prints me these messages:

W/ViewRootImpl[LauncherSettingsActivity]: Dropping event due to no window focus: MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=154.80649, y[0]=462.0374, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=598901019, downTime=598899893, deviceId=5, source=0x1002 }
W/ViewRootImpl[LauncherSettingsActivity]: Dropping event due to no window focus: MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=157.665, y[0]=464.89352, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=598901037, downTime=598899893, deviceId=5, source=0x1002 }
W/ViewRootImpl[LauncherSettingsActivity]: Dropping event due to no window focus: MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=145.26581, y[0]=451.9532, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=598900932, downTime=598899893, deviceId=5, source=0x1002 }
W/ViewRootImpl[LauncherSettingsActivity]: Dropping event due to no window focus: MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=146.27205, y[0]=455.41583, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=598900950, downTime=598899893, deviceId=5, source=0x1002 }
W/ViewRootImpl[LauncherSettingsActivity]: Dropping event due to no window focus: MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=147.81523, y[0]=456.0499, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=598900966, downTime=598899893, deviceId=5, source=0x1002 }
W/ViewRootImpl[LauncherSettingsActivity]: Dropping event due to no window focus: MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0]=152.30963, y[0]=459.04367, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=1, eventTime=598900984, downTime=598899893, deviceId=5, source=0x1002 }
...

Is there any way to access these logs in runtime? I would like to get MotionEvents from logs and dispatch them manually to an activity, like that: someActivity.dispatchTouchEvent(myMotionEvent)

Upvotes: 1

Views: 112

Answers (1)

Artemy Kilin
Artemy Kilin

Reputation: 186

Run logcat in your app

Process process = Runtime.getRuntime().exec("logcat -d -s -vtime *");

Now your logs will be available via the process.getInputStream()

You may also specify other flags for logcat command line

https://developer.android.com/studio/command-line/logcat

PS. Though I think an attempt to use the logs within application to manage motion events is a really bad idea.

Upvotes: 1

Related Questions