package com.android.ddmlib.use;
import com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.Client;
import com.android.ddmlib.IDevice;
import com.android.hierarchyviewer.device.DeviceBridge;
public class DDMlibUse implements AndroidDebugBridge.IDeviceChangeListener, AndroidDebugBridge.IClientChangeListener{
public static void main(String args[]) {
DDMlibUse mlibUse = new DDMlibUse();
AndroidDebugBridge.init(true);
AndroidDebugBridge adb = AndroidDebugBridge.createBridge("adb",
false);
adb.addClientChangeListener(mlibUse);
adb.addDeviceChangeListener(mlibUse);
for (;;) {
}
}
@Override
public void deviceConnected(IDevice dev) {
// TODO Auto-generated method stub
System.out.print("deviceConnected ... \n");
System.out.print(dev.toString() + "\n");
System.out.print(dev.getState() + "\n");
System.out.println(dev.getClients().length);
}
@Override
public void deviceDisconnected(IDevice dev) {
// TODO Auto-generated method stub
System.out.print("deviceDisconnected ... \n");
DeviceBridge.removeDeviceForward(dev);
}
@Override
public void deviceChanged(IDevice dev, int changeMask) {
// TODO Auto-generated method stub
System.out.print("deviceChanged ... \n");
System.out.print(dev.toString() + "\n");
System.out.print(dev.getState() + "\n");
System.out.println(dev.getClients().length + "\n");
System.out.println("changeMask " + changeMask + "\n");
}
@Override
public void clientChanged(Client client, int change_code) {
// TODO Auto-generated method stub
System.out.print("clientChanged ... \n");
}
}
结果是 Device 为 ON_LINE,但调用 getClients 方法仅返回 Client 的数组 [0]。我无法获得任何客户端另一件事是当我在设备上启动一个新应用程序时,我永远不会让“changeMask”成为 IDevice.CHANGE_CLIENT_LIST
你能帮助我吗 ?非常感谢我的目的是让设备上的哪个活动在前面,就像 Hierarchyviewer 和 DDMS 所做的那样。