当前位置: 首页>>代码示例>>Java>>正文


Java AndroidDebugBridge.getDevices方法代码示例

本文整理汇总了Java中com.android.ddmlib.AndroidDebugBridge.getDevices方法的典型用法代码示例。如果您正苦于以下问题:Java AndroidDebugBridge.getDevices方法的具体用法?Java AndroidDebugBridge.getDevices怎么用?Java AndroidDebugBridge.getDevices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.android.ddmlib.AndroidDebugBridge的用法示例。


在下文中一共展示了AndroidDebugBridge.getDevices方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDevice

import com.android.ddmlib.AndroidDebugBridge; //导入方法依赖的package包/类
/**
 * 获取得到device对象
 * 
 * @param index
 *            设备序号
 * @return 指定设备device对象
 */
private IDevice getDevice(int index) {
	IDevice device = null;
	// 如果代码有问题请查看API,修改此处的参数值试一下
	// AndroidDebugBridge bridge = AndroidDebugBridge.createBridge("adb",
	// true);
	AndroidDebugBridge bridge = AndroidDebugBridge.createBridge();
	waitDevicesList(bridge);
	IDevice devices[] = bridge.getDevices();

	for (int i = 0; i < devices.length; i++) {
		System.out.println(devices[i].toString());
	}

	if (devices.length < index) {
		System.err.print("没有检测到第" + index + "个设备");
	} else {
		if (devices.length - 1 >= index) {
			device = devices[index];
		} else {
			device = devices[0];
		}
	}
	return device;
}
 
开发者ID:androiddevelop,项目名称:AndroidScreenshot,代码行数:32,代码来源:ScreenShot.java

示例2: getDevices

import com.android.ddmlib.AndroidDebugBridge; //导入方法依赖的package包/类
private IDevice[] getDevices(Project project) {
    List<AndroidFacet> facets = getApplicationFacets(project);
    if (!facets.isEmpty()) {
        AndroidFacet facet;
        if (facets.size() > 1) {
            facet = ModuleChooserDialogHelper.showDialogForFacets(project, facets);
            if (facet == null) {
                return null;
            }
        } else {
            facet = facets.get(0);
        }

        AndroidDebugBridge bridge = facet.getDebugBridge();
        if (bridge == null) {
            log.error("No platform configured");
            return null;
        }

        if (bridge.isConnected() && bridge.hasInitialDeviceList()) {
            return bridge.getDevices();
        }
    }
    return null;
}
 
开发者ID:willowtreeapps,项目名称:resPeeker,代码行数:26,代码来源:ResPeekerToolWindowFactory.java

示例3: getDevice

import com.android.ddmlib.AndroidDebugBridge; //导入方法依赖的package包/类
@Nullable
private IDevice getDevice(String serial) throws InterruptedException {
  AndroidDebugBridge adb = createAdb();

  if (adb == null) {
    System.err.println("Unable to set up adb.");
    System.exit(1);
  }

  IDevice[] allDevices = adb.getDevices();
  for (IDevice device : allDevices) {
    if (device.getSerialNumber().equals(serial)) {
      return device;
    }
  }
  return null;
}
 
开发者ID:facebook,项目名称:buck,代码行数:18,代码来源:InstrumentationTestRunner.java

示例4: getFilteredDevices

import com.android.ddmlib.AndroidDebugBridge; //导入方法依赖的package包/类
@NotNull
private IDevice[] getFilteredDevices(AndroidDebugBridge bridge) {
  final List<IDevice> filteredDevices = new ArrayList<IDevice>();
  for (IDevice device : bridge.getDevices()) {
    if (myFilter == null || myFilter.value(device)) {
      filteredDevices.add(device);
    }
  }
  // Do not filter launching cloud device as they are just unselectable progress markers
  // that are replaced with the actual cloud device as soon as they are up and the actual cloud device will be filtered above.
  return filteredDevices.toArray(new IDevice[filteredDevices.size()]);
}
 
开发者ID:zzz40500,项目名称:ADB-Duang,代码行数:13,代码来源:MyDeviceChooser.java

示例5: runInstr

import com.android.ddmlib.AndroidDebugBridge; //导入方法依赖的package包/类
private static void runInstr() throws Exception {
    AndroidDebugBridge adb =  getBridge();
    IDevice[] devs = adb.getDevices();
    if(devs !=null) {
        for (IDevice dev : devs) {
            CucTestCallable testCallable = new CucTestCallable(
                    new TaratorDevice(dev,logger,timeoutInMs,TimeUnit.MILLISECONDS)
                    , projectName, variantName, testData,
                    resultsDir, coverageDir, timeoutInMs, installOptions, logger);
            testCallable.call();
        }
    }
}
 
开发者ID:apptik,项目名称:tarator,代码行数:14,代码来源:Play1.java

示例6: initDevices

import com.android.ddmlib.AndroidDebugBridge; //导入方法依赖的package包/类
private static void initDevices() throws Exception {
    AndroidDebugBridge adb = Nuts.initAdbSync(timeoutInMs);
    IDevice[] devs = adb.getDevices();
    if(devs !=null) {
        for (IDevice dev : devs) {
            System.out.println("DEVICE: " + dev);
            dev.uninstallPackage(testData.getApplicationId());
            dev.uninstallPackage(testData.getTestedApplicationId());
        }
    }
}
 
开发者ID:apptik,项目名称:tarator,代码行数:12,代码来源:Play1.java

示例7: getDevicesWithValidDeviceId

import com.android.ddmlib.AndroidDebugBridge; //导入方法依赖的package包/类
@NotNull
private static IDevice[] getDevicesWithValidDeviceId(@NotNull AndroidDebugBridge bridge) {
  final List<IDevice> result = new ArrayList<IDevice>();

  for (IDevice device : bridge.getDevices()) {
    if (device.isOnline()) {
      final String deviceId = AndroidDbUtil.getDeviceId(device);

      if (deviceId != null && deviceId.length() > 0) {
        result.add(device);
      }
    }
  }
  return result.toArray(new IDevice[result.size()]);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:AndroidDataSourcePropertiesDialog.java

示例8: getDeviceById

import com.android.ddmlib.AndroidDebugBridge; //导入方法依赖的package包/类
@Nullable
private static IDevice getDeviceById(@NotNull AndroidDebugBridge debugBridge, @NotNull String deviceId) {
  for (IDevice device : debugBridge.getDevices()) {
    if (deviceId.equals(getDeviceId(device))) {
      return device;
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:AndroidDbUtil.java

示例9: getFilteredDevices

import com.android.ddmlib.AndroidDebugBridge; //导入方法依赖的package包/类
@NotNull
private IDevice[] getFilteredDevices(AndroidDebugBridge bridge) {
  final List<IDevice> filteredDevices = new ArrayList<IDevice>();
  for (IDevice device : bridge.getDevices()) {
    if (myFilter == null || myFilter.value(device)) {
      filteredDevices.add(device);
    }
  }
  // Do not filter launching cloud devices as they are just unselectable progress markers
  // that are replaced with the actual cloud devices as soon as they are up and the actual cloud devices will be filtered above.
  if (myCloudConfigurationProvider != null) {
    filteredDevices.addAll(myCloudConfigurationProvider.getLaunchingCloudDevices());
  }
  return filteredDevices.toArray(new IDevice[filteredDevices.size()]);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:DeviceChooser.java

示例10: getFilteredDevices

import com.android.ddmlib.AndroidDebugBridge; //导入方法依赖的package包/类
@NotNull
private IDevice[] getFilteredDevices(AndroidDebugBridge bridge) {
  final List<IDevice> filteredDevices = new ArrayList<IDevice>();
  for (IDevice device : bridge.getDevices()) {
    if (myFilter == null || myFilter.value(device)) {
      filteredDevices.add(device);
    }
  }
  // Do not filter launching cloud devices as they are just unselectable progress markers
  // that are replaced with the actual cloud devices as soon as they are up and the actual cloud devices will be filtered above.
  return filteredDevices.toArray(new IDevice[filteredDevices.size()]);
}
 
开发者ID:layerlre,项目名称:ADBWIFI,代码行数:13,代码来源:MyDeviceChooser.java

示例11: getDevice

import com.android.ddmlib.AndroidDebugBridge; //导入方法依赖的package包/类
private static DeviceResult getDevice(Project project) {
    List<AndroidFacet> facets = getApplicationFacets(project);
    if (!facets.isEmpty()) {
        AndroidFacet facet = facets.get(0);
        String packageName = AdbUtil.computePackageName(facet);
        AndroidDebugBridge bridge = AndroidSdkUtils.getDebugBridge(project);
        if (bridge == null) {
            error("No platform configured");
            return null;
        }
        int count = 0;
        while (!bridge.isConnected() || !bridge.hasInitialDeviceList()) {
            try {
                Thread.sleep(100);
                count++;
            } catch (InterruptedException e) {
                // pass
            }

            // let's not wait > 10 sec.
            if (count > 100) {
                error("Timeout getting device list!");
                return null;
            }
        }

        IDevice[] devices = bridge.getDevices();
        if (devices.length == 1) {
            return new DeviceResult(devices, facet, packageName);
        } else if (devices.length > 1) {
            return askUserForDevice(facet, packageName);
        } else {
            return null;
        }

    }
    error("No devices found");
    return null;
}
 
开发者ID:layerlre,项目名称:ADBWIFI,代码行数:40,代码来源:AdbWifiConnect.java

示例12: jButton3ActionPerformed

import com.android.ddmlib.AndroidDebugBridge; //导入方法依赖的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();
		}
	});
}
 
开发者ID:GroupControlDroid,项目名称:GroupControlDroidClient,代码行数:68,代码来源:Entrance.java

示例13: getDevice

import com.android.ddmlib.AndroidDebugBridge; //导入方法依赖的package包/类
private DeviceResult getDevice(AnActionEvent anActionEvent) {
    List<AndroidFacet> facets = getApplicationFacets(anActionEvent.getProject());
    if (!facets.isEmpty()) {

        AndroidFacet facet = null;

        String androidFacetName = getAndroidFacetName(anActionEvent);

        if (androidFacetName != null) {
            for (AndroidFacet androidFacet : facets) {
                if (androidFacet.getModule().getName().equals(androidFacetName)) {
                    facet = androidFacet;
                }
            }
            if (facet == null) {
                return null;
            }

        } else {

            if (facets.size() > 1) {
                facet = ModuleChooserDialogHelper.showDialogForFacets(anActionEvent.getProject(), facets);
                if (facet == null) {
                    return null;
                }
            } else {
                facet = facets.get(0);
            }
        }
        String packageName =facet.getAndroidModuleInfo().getPackage();
        AndroidDebugBridge bridge = AndroidSdkUtils.getDebugBridge(anActionEvent.getProject());
        if (bridge == null) {
            error("No platform configured");
            return null;
        }

        if (bridge.isConnected() && bridge.hasInitialDeviceList()) {

            IDevice[] devices = bridge.getDevices();
            if (devices.length == 1) {
                return new DeviceResult(anActionEvent, devices[0], facet, packageName);
            } else if (devices.length > 1) {
                return askUserForDevice(anActionEvent, facet, packageName);
            } else {
                return new DeviceResult(anActionEvent, null, facet, null);
            }
        }
    }
    return new DeviceResult(anActionEvent, null, null, null);
}
 
开发者ID:zzz40500,项目名称:ADB-Duang,代码行数:51,代码来源:BaseAction.java

示例14: devices

import com.android.ddmlib.AndroidDebugBridge; //导入方法依赖的package包/类
public static IDevice[] devices(AndroidDebugBridge adb) {
    return adb.getDevices();
}
 
开发者ID:apptik,项目名称:tarator,代码行数:4,代码来源:Nuts.java

示例15: init

import com.android.ddmlib.AndroidDebugBridge; //导入方法依赖的package包/类
@Override
public void init() throws DeviceException {
    AndroidDebugBridge.initIfNeeded(false /*clientSupport*/);

    AndroidDebugBridge bridge = AndroidDebugBridge.createBridge(
            adbLocation.getAbsolutePath(), false /*forceNewBridge*/);

    long timeOut = 30000; // 30 sec
    int sleepTime = 1000;
    while (!bridge.hasInitialDeviceList() && timeOut > 0) {
        try {
            Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
            throw new DeviceException(e);
        }
        timeOut -= sleepTime;
    }

    if (timeOut <= 0 && !bridge.hasInitialDeviceList()) {
        throw new DeviceException("Timeout getting device list.");
    }

    IDevice[] devices = bridge.getDevices();

    if (devices.length == 0) {
        throw new DeviceException("No connected devices!");
    }

    final String androidSerial = System.getenv("ANDROID_SERIAL");
    final Boolean isValidSerial = androidSerial != null && !androidSerial.isEmpty();
    final List<IDevice> filteredDevices = Lists.newArrayListWithCapacity(devices.length);
    for (IDevice iDevice : devices) {
        if (!isValidSerial || iDevice.getSerialNumber().equals(androidSerial)) {
            filteredDevices.add(iDevice);
        }
    }

    if (filteredDevices.isEmpty()) {
        throw new DeviceException(String.format(
                "Connected device with serial %s not found!", androidSerial));
    }

    for (IDevice device : filteredDevices) {
        if (device.getState() == IDevice.DeviceState.ONLINE) {
            localDevices.add(new ConnectedDevice(device));
        } else {
            iLogger.info(
                    "Skipping device '%s' (%s): Device is %s%s.",
                    device.getName(), device.getSerialNumber(), device.getState(),
                    device.getState() == IDevice.DeviceState.UNAUTHORIZED ? ",\n"
                            + "    see http://d.android.com/tools/help/adb.html#Enabling" : "");
        }
    }

    if (localDevices.isEmpty()) {
        if (isValidSerial) {
            throw new DeviceException(String.format(
                    "Connected device with serial $1%s is not online.",
                    androidSerial));
        } else {
            throw new DeviceException("No online devices found.");
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:65,代码来源:ConnectedDeviceProvider.java


注:本文中的com.android.ddmlib.AndroidDebugBridge.getDevices方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。