Taking screenshot of android returning Null? -
i want take screenshot of screen of rooted device ( not of particular activity of whole screen ) code -
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); }
where
mpath= environment.getexternalstoragedirectory().tostring() + "/screenshots.png";
now trying display -
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); }`
permissions :
<uses-permission android:name="android.permission.write_external_storage" /> <uses-permission android:name="android.permission.read_external_storage" />
but image not being dosplayed saying - unable decode stream - java.io.filenotfound exception .. searched in sdcard , there no file/image name screenshots.png .
why ? wrong code ? should ?
to save file can use
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());
Comments
Post a Comment