我正在开发一个能够拍摄屏幕截图的应用程序,我发现下面的代码可以让我做到这一点
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();
它使用图像名称保存图像我可以在代码中更改它,但我希望当前日期和时间作为名称。我试着把这个:
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = df.format(c.getTime());
但是将 formattedDate 放在图像的位置后它不起作用