My app takes a sequence of screenshots, but instead of getting lots of them, I get one screenshot that overwrites itself all the time. I want to get taken screenshots named by the date they were taken (it will make them unique and will solve the problem, i think).
For that I do the following:
$(date +%m.%d.%Y-%H:%M)
Full line:
os.write(("/system/bin/screencap -p /sdcard/fly/$(date +%m.%d.%Y-%H:%M).png").getBytes("ASCII"));
But the files don't appear.
I tried /sdcard/fly/screenshot%d.png
but the files get named exactly like in the code "screenshot%d".
How can I properly name my files according to the date they were taken?
Full code:
package ru.startandroid.develop.p0921servicesimple;
import java.io.IOException;
import java.io.OutputStream;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class MyService extends Service {
final String LOG_TAG = "myLogs";
public void onCreate() {
super.onCreate();
Log.d(LOG_TAG, "onCreate");
}
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(LOG_TAG, "onStartCommand");
someTask();
return super.onStartCommand(intent, flags, startId);
}
public void onDestroy() {
super.onDestroy();
Log.d(LOG_TAG, "onDestroy");
}
public IBinder onBind(Intent intent) {
Log.d(LOG_TAG, "onBind");
return null;
}
void someTask() {
new Thread(new Runnable() {
public void run() {
for (int i = 1; i <= 25; i++) {
Log.d(LOG_TAG, "i = " + i);
try {
Process sh = Runtime.getRuntime().exec("su", null);
OutputStream os = sh.getOutputStream();
os.write(("/system/bin/screencap -p /sdcard/fly/bob.png").getBytes("ASCII"));
os.flush();
os.close();
sh.waitFor();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
}
}