拍摄android返回Null的屏幕截图?
我想用这段代码拍摄我的根设备的屏幕截图,不仅仅是特定活动的屏幕截图,而是整个屏幕的截图-拍摄android返回Null的屏幕截图?,android,Android,我想用这段代码拍摄我的根设备的屏幕截图,不仅仅是特定活动的屏幕截图,而是整个屏幕的截图- try { Process sh = Runtime.getRuntime().exec("su", null,null); OutputStream os = sh.getOutputStream(); os.write(("/system/bin/screencap -p " + ""+mpath).getBytes("ASCII"));
try {
Process sh = Runtime.getRuntime().exec("su", null,null);
OutputStream os = sh.getOutputStream();
os.write(("/system/bin/screencap -p " + ""+mpath).getBytes("ASCII"));
os.flush();
os.close();
sh.waitFor();
} catch (Exception e)
{
Log.e("TAG_Err", "Error: "+e);
}
在哪里
mpath=Environment.getExternalStorageDirectory.toString+/screenshots.png
现在尝试用-
try
{
Bitmap bMap = BitmapFactory.decodeFile(""+mpath);
ImageView image = (ImageView)findViewById(R.id.imageView1);
image.setImageBitmap(bMap);
}
catch(Exception e)
{
Log.e("TAG_DISPLAY_ERR","error : "+e);
}`
权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
但图像并不像它所说的那样被播放-
无法解码流-java.io.FileNotFound异常。。我也在SD卡中搜索过,没有名为screenshots.png的文件/图像
为什么?
这个代码有什么问题?
我该怎么办?要保存文件,您可以使用
OutputStream fOut = null;
File file = new File(directoyname,imagename);
fOut = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();
MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
直接设置路径,如位图bMap=BitmapFactory.decodeFilempath;@简单的计划:快速响应的thnks。。我试过了,但它不起作用-仍然得到相同的结果。@Simple plan您是对的,但在保存文件时出现了问题。@Toppers-但是这段代码如何从当前屏幕截取屏幕?