I am developing an app which is able to take screen shots and I found the following code which allows me to do that
Toast.makeText(this, formattedDate, Toast.LENGTH_SHORT).show();
Process sh = Runtime.getRuntime().exec("su", null,null);
OutputStream os = sh.getOutputStream();
os.write(("/system/bin/screencap -p " + "/sdcard/img.png").getBytes("ASCII"));
os.flush();
It saves the image with image name I can change it in code but I want the current date and time as the name. I tried puttinge this:
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = df.format(c.getTime());
But after putting formattedDate at the place of image it does not work