位置: 编程技术 - 正文
推荐整理分享PC获取手机截图、复制文件、安装APK(手机截取电脑屏幕),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:电脑手机截图快捷键,手机截取电脑屏幕,手机屏幕截图在电脑的什么文件夹,手机截取电脑屏幕,pc获取手机截图的软件,手机截图用电脑怎么找,手机截图用电脑怎么找,pc获取手机截图的软件,内容如对您有帮助,希望把文章链接给更多的朋友!
我在eoe上的帖子的链接
PC获取手机截图、复制文件、安装 ,添加了 从电脑中文件复制到设备、将APK文件安装到设备的功能。(ddmlib.jar这个包在SDK目录下tools中lib文件夹下)
package cc.practise;import java.text.SimpleDateFormat;public class Main { /** * @param args */ public static void main(String[] args) { DeviceManager dm = new DeviceManager(0); //支持多个手机端设备管理,0表示第一个连接的设备 dm.getScreenShot(" "手机截图_"toDateTime(System.currentTimeMillis())); // screenShot.InstallPackage(" dm.getFileList();//获取手机存储目录列表 dm.pullFile("D:\","/mnt/sdcard/","music.aac");//将电脑中 dm.InstallPackage("D:\WoChaCha.apk");//将一个apk文件安装到手机中 } //日期的转换 private static String toDateTime(long time) { //初始化Formatter的转换式。 SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒"); return formatter.format(time); }}[/mw_shl_code]DeviceManager类[mw_shl_code=java,true]package cc.practise;import java.awt.image.BufferedImage;import java.awt.image.RenderedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;import com.android.ddmlib.AdbCommandRejectedException;import com.android.ddmlib.AndroidDebugBridge;import com.android.ddmlib.FileListingService;import com.android.ddmlib.FileListingService.FileEntry;import com.android.ddmlib.IDevice;import com.android.ddmlib.InstallException;import com.android.ddmlib.RawImage;import com.android.ddmlib.ShellCommandUnresponsiveException;import com.android.ddmlib.SyncException;import com.android.ddmlib.TimeoutException;public class DeviceManager { public IDevice device ; /** * 构造函数,默认获取第一个设备 */ public DeviceManager(){ AndroidDebugBridge.init(false); device = this.getDevice(0); device.getFileListingService(); System.out.println("设备信息:""getAvdName"device.getAvdName()"--getName"device.getAvdName()"--getSerialNumber"device.getSerialNumber()"--getProperty"device.getProperty("what")); fileList=device.getFileListingService(); } /** * 构造函数,指定设备序号 * @param deviceIndex 设备序号 */ public DeviceManager(int deviceIndex){ AndroidDebugBridge.init(false); // device = this.getDevice(deviceIndex); } /** * 直接抓取屏幕数据 * @return 屏幕数据 */ public RawImage getScreenShot(){ RawImage rawScreen = null; if(device!=null){ try { rawScreen = device.getScreenshot(); } catch (TimeoutException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (AdbCommandRejectedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }else{ System.err.print("没有找到设备"); } return rawScreen; } /** * 获取图片byte[]数据 * @return 图片byte[]数据 */ public byte[] getScreenShotByteData(){ RawImage rawScreen = getScreenShot(); if(rawScreen != null){ return rawScreen.data; } return null; } /** * 抓取图片并保存到指定路径 * @param path 文件路径 * @param fileName 文件名 */ public void getScreenShot(String path,String fileName){ System.out.println("设备信息:""getAvdName"device.getAvdName()"--getName:--"device.getAvdName()"--getSerialNumber"device.getSerialNumber()"--getProperty"device.getProperty("what")); RawImage rawScreen = getScreenShot(); if(rawScreen!=null){ Boolean landscape = false; int width2 = landscape ? rawScreen.height : rawScreen.width; int height2 = landscape ? rawScreen.width : rawScreen.height; BufferedImage image = new BufferedImage(width2, height2, BufferedImage.TYPE_INT_RGB); if (image.getHeight() != height2 || image.getWidth() != width2) { image = new BufferedImage(width2, height2, BufferedImage.TYPE_INT_RGB); } int index = 0; int indexInc = rawScreen.bpp >> 3; for (int y = 0; y < rawScreen.height; y) { for (int x = 0; x < rawScreen.width; x, index = indexInc) { int value = rawScreen.getARGB(index); if (landscape) image.setRGB(y, rawScreen.width - x - 1, value); else image.setRGB(x, y, value); } } try { ImageIO.write((RenderedImage) image, "PNG", new File(path "/" fileName ".png")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } /** * 获取得到device对象 * @param index 设备序号 * @return 指定设备device对象 */ private IDevice getDevice(int index) { IDevice device = null; AndroidDebugBridge bridge = AndroidDebugBridge .createBridge();// 如果代码有问题请查看API,修改此处的参数试一下 waitDevicesList(bridge); IDevice devices[] = bridge.getDevices(); for (int i = 0; i < devices.length; i) { System.out.println(devices.toString()); } if(devices.length < index){ //没有检测到第index个设备 System.err.print("没有检测到第" index "个设备"); } else { if (devices.length-1>=index) { device = devices[index]; } else { device = devices[0]; } } return device; } /** * 等待查找device * @param bridge */ private void waitDevicesList(AndroidDebugBridge bridge) { int count = 0; while (bridge.hasInitialDeviceList() == false) { try { Thread.sleep(); count; } catch (InterruptedException e) { } if (count > ) { System.err.print("等待获取设备超时"); break; } } } public void InstallPackage(String apkFilePath) { try { device.installPackage(apkFilePath, false, ""); } catch (InstallException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private FileListingService fileList; private FileEntry temp; /** * 测试打印出存储目录列表 * @return */ public String[] getFileList() { fileList=device.getFileListingService(); FileEntry[] arrayFileEntry; try { // String str=fileList.getRoot().findChild(fileList.DIRECTORY_SDCARD).getFullPath(); arrayFileEntry=fileList.getChildrenSync(fileList.getRoot()); // System.out.println("print story path:"fileList.getRoot().findChild(fileList.DIRECTORY_SDCARD).getFullPath()); for (int i = 0; i < arrayFileEntry.length; i) { if(arrayFileEntry.getFullPath().equals("/mnt")) { System.out.println("我找到mnt目录了!"); FileEntry[] array=fileList.getChildrenSync(arrayFileEntry); if(array!=null) for (int j = 0; j < array.length; j) { System.out.println("mnt目录下:"array[j].getFullPath()); } } System.out.println("Path:"arrayFileEntry.getFullPath()); } } catch (TimeoutException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (AdbCommandRejectedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ShellCommandUnresponsiveException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } /** * 将一个文件从电脑上复制到手机指定的目录下 * @param localPath:本地的目录 * @param remotePath:手机的目录 * @param fileName:文件名称 */ public void pullFile(String localPath,String remotePath,String fileName) { /* try { FileEntry[] arrayTemp=fileList.getChildrenSync(temp); for (int i = 0; i < arrayTemp.length; i) { if(arrayTemp.getFullPath().equals(remotePath)) { System.out.println("I find ttpod path!"); }else { System.out.println("没有找到设备中的目录:"remotePath); } System.out.println("arrayTemp:"arrayTemp.getFullPath()); }*/ try { device.pushFile(localPathfileName,remotePathfileName); } catch (SyncException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (AdbCommandRejectedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TimeoutException e) { // TODO Auto-generated catch block e.printStackTrace(); } /*} catch (SyncException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (AdbCommandRejectedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TimeoutException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ShellCommandUnresponsiveException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ }}ORMLite完全解析(四) 官方文档第四章、在Android中使用 官方文档的第四章原标题是UsingWithAndroid,看过前面的文档友友,看到这里可能会有点晕乎,因为从一开始就在介绍ORMLite在Android中的介绍,但是到第四章
android(6) 扇形菜单实现 一.扇形菜单的实现:借鉴了大神们的源码,那我们来看一下扇形菜单是怎么实现的:效果图:主界面布局:RelativeLayoutxmlns:android=
Android 进行单元测试难在哪-part1 原文链接:AgainstAndroidUnitTests原文作者:MatthewDupree译文出自:开发技术前线www.devtf.cn译者:chaossss校对者:tiiime状态:完成正如我在序中所说,在Android中难于进
标签: 手机截取电脑屏幕
本文链接地址:https://www.jiuchutong.com/biancheng/384301.html 转载请保留说明!友情链接: 武汉网站建设