Theme:
How do I 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 ImportCom.android.ddmlib.AndroidDebugBridge; ImportCom.android.ddmlib.IDevice; //creat Androiddebugbridge and Device class object PrivateAndroiddebugbridge Mbridge; PrivateIDevice Mdevice; //Get The device object you want connectString serial_number = "INV121501088"; Mbridge= Androiddebugbridge.createbridge (Location,true ); Mdevice=Findattacheddevice (Deviceidregex); //Find the device from the devices through Androiddebugbridge PrivateIDevice Findattacheddevice (String deviceidregex) {pattern pattern=Pattern.compile (Deviceidregex); for(IDevice device:mBridge.getDevices ()) {String serialnumber=Device.getserialnumber (); if(Pattern.matcher (serialnumber). Matches ()) {returndevice; } } return NULL; }
Second Step:get The Log to buffer
1 New Preferencestore (); 2 3 Mprefstore.setdefault (Logcatmessagelist.max_messages_prefkey,4 Logcatmessagelist.max _messages_default); 5 6 New Logcatreceiver (Mdevice, Mprefstore);
Get the log from Android device