[英]How to make a capture screen app on Android
我想制作一个无需root即可捕获设备屏幕的应用程序: https : //play.google.com/store/apps/details?id=com.icecoldapps.screenshotultimate
但是我找不到解决方案。 有人帮我吗?
非常感谢你。
通过编程,您可以通过使用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屏幕截图。
从应用程序的常见问题解答中:
我的设备没有可用的“捕获方法”!
如果您的设备没有植根,这是正常的。 这就是Android安全模型的工作方式。 只是不允许在某些设备上截图。 但是,您可以通过计算机启用设备上的屏幕快照功能。 要查看如何执行此操作,请转到“ Screenshot Ultimate”>“设置”>“捕获方法”>“无捕获方法帮助”。 您可以通过电子邮件将手册发送给自己,以便可以在计算机(Windows,Linux或Mac OSX)上完成该手册。
检查这是否可以帮助您。 以下代码将帮助您捕获特定布局的屏幕
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
// 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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.