Android 移动设备上的程序化截屏

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3582603/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:50:34  来源:igfitidea点击:

Programmatic screencapture on mobile device

androidscreenshot

提问by wolfgang

I would like to implement some sort of remote assistance tool (like vnc) for Android. Is there the possibility to capture a screen programmatically on the device?

我想为 Android 实现某种远程协助工具(如 vnc)。是否可以在设备上以编程方式捕获屏幕?

回答by DonGru

Something like that might work for you:

类似的东西可能对你有用:

View v = view.getRootView();
v.setDrawingCacheEnabled(true);
Bitmap b = v.getDrawingCache();

回答by aaronsnoswell

There is a long discussion of this on android-developers, but the short answer is: You can't programatically take a screenshot of an android device's screen at the moment, unless

android-developers上对此进行了长时间的讨论,但简短的回答是:您目前无法以编程方式截取 android 设备屏幕的屏幕截图,除非

  1. You have root access on that phone, or
  2. Your application is a system application
  1. 您在该手机上拥有 root 访问权限,或者
  2. 您的应用程序是系统应用程序

The Android Manifest permission READ_FRAME_BUFFERexists (see the api docs here), but can presently only be used by system applications. There are various reasons for this, one being that it is a security risk. If an background can take a screenshot of the phone's screen at any time, then people could use OCR techniques to sniff user's passwords as they were typed in, among other private information.

Android 清单权限READ_FRAME_BUFFER存在(请参阅此处的 api 文档),但目前只能由系统应用程序使用。造成这种情况的原因有很多,其中之一是存在安全风险。如果背景可以随时截取手机屏幕的屏幕截图,那么人们就可以使用 OCR 技术来嗅探用户输入的密码以及其他私人信息。

So no, a VNC application is not possible at the moment without root. To take a screenshot from your computer (while the phone is plugged in via usb) you can use DDMS.

所以不,VNC 应用程序在没有 root 的情况下目前是不可能的。要从您的计算机(通过 USB 插入手机时)​​截取屏幕截图,您可以使用DDMS

回答by Kuba

You can try the following library: http://code.google.com/p/android-screenshot-library/Android Screenshot Library (ASL) enables to programmatically capture screenshots from Android devices without requirement of having root access privileges. Instead, ASL utilizes a native service running in the background, started via the Android Debug Bridge (ADB) once per device boot.

您可以尝试使用以下库:http: //code.google.com/p/android-screenshot-library/Android 屏幕截图库 (ASL) 能够以编程方式从 Android 设备捕获屏幕截图,而无需具有 root 访问权限。相反,ASL 使用在后台运行的本机服务,每次设备启动时通过 Android 调试桥 (ADB) 启动一次。

回答by Sagar V.

I think its possible in kitkat using the adb command for screen capture. You can use this command to record screen as a video

我认为在 kitkat 中使用 adb 命令进行屏幕捕获是可能的。您可以使用此命令将屏幕录制为视频

adb shell screenrecord /sdcard/demo.mp4

You can find more details here

您可以在此处找到更多详细信息

you can execute the adb command from your app.Check the answer here

您可以从您的应用程序执行 adb 命令。检查这里的答案

回答by Jawad Zeb

put it in onClick ..

把它放在 onClick ..

Bitmap bitmap = takeScreenshot();
saveBitmap(bitmap);

and write funtcion..

并写函数..

public Bitmap takeScreenshot() {
   View rootView = findViewById(android.R.id.content).getRootView();
   rootView.setDrawingCacheEnabled(true);
   return rootView.getDrawingCache();
}

public void saveBitmap(Bitmap bitmap) {
    File imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
    FileOutputStream fos;
    try {
        fos = new FileOutputStream(imagePath);
        bitmap.compress(CompressFormat.PNG, 100, fos);
        fos.flush();
        fos.close();
    } catch (FileNotFoundException e) {
        Log.e("GREC", e.getMessage(), e);
    } catch (IOException e) {
        Log.e("GREC", e.getMessage(), e);
    }
}

回答by Ma99uS

The VNC-type remote tol does exist for "SOME" android devices (mainly Samsung):
TeamViewer QuickSupport
https://play.google.com/store/apps/details?id=com.teamviewer.quicksupport.market
Dos anyone knows how that tool gets screen capturing, and why it supports only limited set of devices?

“某些”Android 设备(主要是三星)确实存在 VNC 类型的远程工具:
TeamViewer QuickSupport
https://play.google.com/store/apps/details?id=com.teamviewer.quicksupport.market
有谁知道如何那个工具可以截屏,为什么它只支持有限的一组设备?