Get the log from android device
Theme:
How to get the log from device ?
Detail: Get the log from device, and write to the local file .
Google Source jar:
Use the methods in ddmlib.jar mostly:
import com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.AndroidDebugBridge.IDeviceChangeListener;
import com.android.ddmlib.IDevice;
The concrete process:
First step : connect the devices through ADB
//import package import com.android.ddmlib.AndroidDebugBridge; import com.android.ddmlib.IDevice; //Creat AndroidDebugBridge 和 device class object private AndroidDebugBridge mBridge; private IDevice mDevice; //Get the device object you want connect String serial_number = "INV121501088"; mBridge = AndroidDebugBridge.createBridge(location, true ); mdevice = findAttachedDevice(deviceIdRegex); //Find the device from the devices through AndroidDebugBridge private IDevice findAttachedDevice(String deviceIdRegex) { Pattern pattern = Pattern.compile(deviceIdRegex); for (IDevice device : mBridge.getDevices()) { String serialNumber = device.getSerialNumber(); if (pattern.matcher(serialNumber).matches()) { return device; } } return null; }
Second step : Get the Log to buffer
1 mPrefStore = new PreferenceStore(); 2 3 mPrefStore.setDefault(LogCatMessageList.MAX_MESSAGES_PREFKEY, 4 LogCatMessageList.MAX_MESSAGES_DEFAULT); 5 6 mLogcatReceiver= new LogCatReceiver(mdevice, mprefStore);
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步