本文整理汇总了Java中com.android.ddmlib.IDevice.isOnline方法的典型用法代码示例。如果您正苦于以下问题:Java IDevice.isOnline方法的具体用法?Java IDevice.isOnline怎么用?Java IDevice.isOnline使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.ddmlib.IDevice
的用法示例。
在下文中一共展示了IDevice.isOnline方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onData
import com.android.ddmlib.IDevice; //导入方法依赖的package包/类
public void onData(SocketIOClient client, String jsonStr, AckRequest ack)
throws Exception {
InstallBean bean = JsonUtil.jsonTobean(jsonStr, InstallBean.class);
logger.info(jsonStr);
if(bean != null){
List<String> serialNumberList = bean.getSerialNumberList();
String apkPath = bean.getApkPath();
if(serialNumberList != null && apkPath != null && FileUtil.isFileExist(apkPath)){
for(String serialNumber : serialNumberList){
DeviceEntity deviceEntity = DeviceContainerHandler.getDevice(serialNumber);
if(deviceEntity != null){
IDevice idevice = deviceEntity.getIdevice();
if(idevice != null && idevice.isOnline()){
executorService.execute(new Runnable() {
@Override
public void run() {
SystemWSSender.msg(client,"设备["+deviceEntity.getSerialNumber()+"] 开始安装应用");
try {
idevice.installPackage(apkPath, true);
SystemWSSender.msg(client,"设备["+deviceEntity.getSerialNumber()+"] 应用安装成功");
} catch (InstallException e) {
logger.error(serialNumber+":安装apk["+apkPath+"] 出错",e);
SystemWSSender.error(client,"设备["+serialNumber+"]apk安装出错,原因:"+e.getMessage());
}
}
});
}
}
}
}
}
}
示例2: jButton3ActionPerformed
import com.android.ddmlib.IDevice; //导入方法依赖的package包/类
/**
* 点击测试连接按钮
*
* @param evt
*/
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JFrame frame = new JFrame("设备连接测试");
LayoutManager layout = new GridLayout(2, 2);
frame.setLayout(layout);
frame.setBounds(20, 20, 300, 100);
frame.setVisible(true);
frame.setResizable(false);
frame.setLocationRelativeTo(null);
TextField textFiled1 = new TextField("可用设备数");
textFiled1.setEditable(false);
connectedCountDeviceTextField.setEditable(false);
frame.getContentPane().add(textFiled1);
frame.getContentPane().add(connectedCountDeviceTextField);
TextField textFiled2 = new TextField("总设备数");
textFiled2.setEditable(false);
totalCountDeviceTextField.setEnabled(false);
frame.getContentPane().add(textFiled2);
frame.getContentPane().add(totalCountDeviceTextField);
// 设备数监听
Thread countDeviceThread = new Thread(new Runnable() {
@Override
public void run() {
int connected = 0, total = 0;// 已在线设备数,总设备数
AndroidDebugBridge bridge = AdbUtil.getADBInstance();
if (bridge != null) {
try {
while (!Thread.currentThread().isInterrupted()) {
IDevice[] devices = bridge.getDevices();
if (devices != null) {
total = devices.length;
connected = 0;
for (IDevice device : devices) {
if (device != null && device.isOnline()) {
connected++;
}
}
}
connectedCountDeviceTextField.setText(String.format("%d", connected));
totalCountDeviceTextField.setText(String.format("%d", total));
Thread.sleep(500);
}
} catch (InterruptedException e) {
logger.info("设备数目监听线程退出");
}
}
}
}, "CountDeviceThread");
countDeviceThread.start();
/* 窗口退出,退出线程 */
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
countDeviceThread.interrupt();
}
});
}