【问题标题】:How to make a capture screen app on Android如何在 Android 上制作截屏应用
【发布时间】:2013-09-11 09:52:49
【问题描述】:

我想制作一个可以在没有 root 的情况下捕获设备屏幕的应用程序: https://play.google.com/store/apps/details?id=com.icecoldapps.screenshotultimate

但我找不到解决方案。 有人帮我吗?

非常感谢。

【问题讨论】:

  • 你想在什么手机上截屏?
  • @Yume117:任何设备,我都想让应用在我的设备上运行。

标签: android screen screenshot capture


【解决方案1】:

您可以通过使用 adb 执行以下命令以编程方式实现此目的:

adb shell /system/bin/screencap -p /sdcard/img.png

但是,您可以使用以下方法从应用程序中执行相同操作:

Process sh = Runtime.getRuntime().exec("su", null,null); //getting superuser permission to access /system/bin
OutputStream  os = sh.getOutputStream();
os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII")); //executing the command
os.flush();
os.close();
sh.waitFor();

/sdcard/ 中,您将拥有 img.png,这将是您的屏幕截图。

【讨论】:

  • 谢谢扎克斯。但是当我构建并运行时,得到错误:java.io.IOException: Error running exec()。命令:Super User 工作目录:null 环境:null
  • @Tommy:只要您拥有超级用户权限,就不会出现任何异常。我认为您正在尝试使用无根设备。所以在模拟器上试试同样的方法。
  • 是的,我在无根设备上运行。这个应用可以做到:play.google.com/store/apps/…
  • 您是否为您的应用程序添加了 WRITE_EXTERNAL_STORAGE 权限?
  • 是的,我愿意。但是这个错误: Process sh = Runtime.getRuntime().exec("su", null, null);
【解决方案2】:

来自应用的常见问题解答:

我的设备没有可用的“捕获方法”!

如果您的设备没有植根,这是正常的。这就是 Android 安全模型的工作方式;它只是不允许在某些设备上截屏。但是,您可以通过计算机启用设备上的屏幕截图功能。要查看如何执行此操作,请转到“Screenshot Ultimate”>“设置”>“捕获方法”>“无捕获方法帮助”。您可以将手册通过电子邮件发送给自己,以便在您的计算机(Windows、Linux 或 Mac OSX)上完成。

【讨论】:

    【解决方案3】:

    检查这是否可以帮助您。 以下代码将帮助您捕获特定布局的屏幕

    RelativeLayout screenShotLayout=(RelativeLayout)findViewById(R.id.ScreenShotLayout);
    
    Bitmap Bitmapimage=Bitmap.createBitmap(screenShotLayout.getWidth(),screenShotLayout.getHeight(), Config.ARGB_8888);
    screenShotLayout.setDrawingCacheEnabled(true);
    screenShotLayout.buildDrawingCache();
    Bitmapimage=screenShotLayout.getDrawingCache();
    //Bitmapimage is the screenshot of the layout. Do your stuff with it
    

    【讨论】:

    • 感谢 Bhavna,但它只捕获应用程序的当前屏幕
    【解决方案4】:
    // image naming and path  to include sd card  appending name you choose for file
    String mPath = Environment.getExternalStorageDirectory().toString() + "/" + ACCUWX.IMAGE_APPEND;   
    
    // create bitmap screen capture
    Bitmap bitmap;
    View v1 = mCurrentUrlMask.getRootView();
    v1.setDrawingCacheEnabled(true);
    bitmap = Bitmap.createBitmap(v1.getDrawingCache());
    v1.setDrawingCacheEnabled(false);
    
    OutputStream fout = null;
    imageFile = new File(mPath);
    
    try {
        fout = new FileOutputStream(imageFile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
        fout.flush();
        fout.close();
    
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    

    访问文件:

    Uri uri = Uri.fromFile(new File(mPath));
    

    【讨论】:

    • 亲爱的。我想要捕获设备屏幕,而不是从应用程序视图中捕获
    猜你喜欢
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    • 2021-02-05
    • 2011-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-05
    相关资源
    最近更新 更多