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);
时间: 2024-07-28 19:27:37

Get the log from android device的相关文章

在Android Studio中打开Android Device Monitor时报错的解决方法

在Android Studio中打开Android Device Monitor时报以下错误时(Android-SDK\tools\lib\monitor-x86_64\configuration\1491536029820.log),请关闭Android Studio后以管理员的模式打开Android Studio后即可解决此问题. !SESSION 2017-04-07 11:33:49.545 -----------------------------------------------

android studio 启动android device monitor 报java虚拟机启动失败

在使用android studio 启动android device monitor 观察log日志的时候时常会报java虚拟机启动失败, 在网上找了好久,最后在知乎回答上得到了解决方案.记录一下,方便以后查看也希望可以帮到大家! 先把错误图片放上来吧. 出现这种情况我猜应该是启动内存不够了,当然如果你是8g应该就不会存在这个问题了. 如果出现了这个问题怎么解决呢.很简单找到sdk目录下的tools\lib\monitor-x86目录下 有个monitor.ini用记事本将其打开,在最后一下几个

3 Possible Ways for Real-Time Video Streaming Between Camera and Android Device Read more at http://

You can use your robot to send real-time video images, and this could be a very interesting DIY robotic application. In this article, we make an overview of three possible ways for real-time streaming between a camera mounted on a robot and an Androi

Android Device Orientation

最近在处理相机拍照的方向问题,在Android Device的Orientation问题上有了些疑问,就顺便写个Demo了解下Android Device Orientation究竟是怎么个判断. Android Device Orientation的使用场景其实最常见的就是视频播放软件了,它会随着你摆弄手机的方向,来调整一个最适合的画面旋转让用户观看.官方API文档里对Android Device Orientation有这么一句话: public abstract void onOrient

解决Android studio 中的 Android Device Monitor 中 File Explorer 无法打开data目录的方法(转载 http://www.jianshu.com/p/d8a9a2918c61)

Android Device Monitor 文件管理的常见问题  (转自http://www.jianshu.com/p/d8a9a2918c61) 作者 knightaoko 关注 2017.03.21 11:41* 字数 2750 阅读 770评论 5喜欢 9 Android Device Monitor 是 Android Studio 中用于监测模拟器或真机运行状态的一款开发者工具.但开发者在使用它的过程中往往会遇到很多问题,尤其对于新手.本文分析了实际学习中遇到的问题,包括:1. F

Eclipse: Android Device Chooser - Unknown Target

公司最近所有的项目都使用到了Android开发手机(或PDA)应用.所需要的Android开发技术并不是非常复杂,因为我们的底层方法全部使用WebServcie写好了,做Android开发的人员只需要调用和画界面就可以了.由于很多项目组都需要使用Android开发技术,这逐渐引起了我的兴趣.况且,我最近写的WCF框架中由于跟传统的WebService相比Android调用的方法大不一样,所以我有必要把Android开发这一块搞定.我认为所有的技术不过是生产力,能方便的转化为生产力的就是好技术.所

Android Device Administration 设备管理器——一键锁屏的实现

Android Device Administration 设备管理器--锁屏的实现 最近研究了一下安全这一块的内容,当然,我是比较水的,所以也拿不出什么好知识点,但是有一些冷门的东西我还是可以聊聊的,就拿这个锁屏来说吧,我们现在市面上有一些一键锁屏的软件 我们可以看到,是数不胜数的,所以,其实他一开始使用的时候,都需要请求设备管理器 我们可以看到,只有当我们激活的时候,我们才可以使用它,那么,他到底是什么东西呢?其实,当我们激活之后,我们可以在我们手机的设置--安全--设备管理器里面看到他的所

Android news Display Owner Info on Your Android Device in Case It Gets Lost

Display Owner Info on Your Android Device in Case It Gets Lost The latest versions of Android include a handy feature that you might not know about: the option to display your contact information on the lockscreen, which can be used if you misplace y

6.5、Android Studio的Android Device Monitor

Android Device Monitor是一个独立的工具,可以对Android应用进行调试和分析.Android Device Monitor无需安装整合在一个IDE中,比如像Android Studio,提供如下工具: 1. DDMS 2. Tracer for OpenGL ES 3. Hierarchy Viewer 4. Systrace 5. Traceview 6. Pixel Perfect magnification viewer 运行Android Device Monit