本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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()]);
}
示例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();
}
}
}
示例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());
}
}
}
示例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()]);
}
示例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;
}
示例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()]);
}
示例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()]);
}
示例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;
}
示例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();
}
});
}
示例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);
}
示例14: devices
import com.android.ddmlib.AndroidDebugBridge; //导入方法依赖的package包/类
public static IDevice[] devices(AndroidDebugBridge adb) {
return adb.getDevices();
}
示例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.");
}
}
}