首页 > 移动平台 > 详细

Get the log from android device

时间:2016-08-07 17:00:08      阅读:370      评论:0      收藏:0      [点我收藏+]

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);

 

 

 

 

 

 

        

 

Get the log from android device

原文:http://www.cnblogs.com/udld/p/4569563.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!