With three arguments, shows a notification with title <title> and text <text> and id <id>. This replaces any previous notiifcation with the same id.\n
With one argument, removes the notification with id <id>\n
Example: notify 10 Hello \"Hello, world!\"
- </string>
- <string name="user_or_password_not_set">User or password not set</string>
-</resources>
\ No newline at end of file
+ </string>
+ <string name="user_or_password_not_set">User or password not set</string>
+ <string name="screencap_successful">Screencap successful</string>
+ <string name="screencap_failed">Screencap failed. Remember: the screencap command requires root access</string>
+ <string name="screencap_help">
+ Usage: screencap filename
+ Takes a screen capture and saves it to the given filename as a PNG image file.
+ Example: screencap /storage/sdcard0/screencap.png
+ </string>
+</resources>
}
}
+ /**
+ * Runnable that takes a screen capture and stores it in a file.
+ */
+ private static final class ScreencapRunnable implements Runnable{
+ private final Context context;
+ private final Address replyTo;
+ private final String filename;
+
+ ScreencapRunnable(final Context context, final Address replyTo, final String filename){
+ this.context=context;
+ this.replyTo=replyTo;
+ this.filename=filename;
+ }
+
+ @Override
+ public void run(){
+ final int exitCode;
+ try {
+ exitCode=Runtime.getRuntime().exec(new String[]{
+ "su",
+ "-c",
+ "screencap -p \"" + filename + "\""
+ }).waitFor();
+ } catch (final Exception e){
+ e.printStackTrace();
+ Utils.sendMessage(toNonNull(context), toNonNull(replyTo), screencap_failed);
+ return;
+ }
+
+ if(exitCode == 0 && new File(filename).exists())
+ Utils.sendMessage(toNonNull(context), toNonNull(replyTo), screencap_successful);
+ else
+ Utils.sendMessage(toNonNull(context), toNonNull(replyTo), screencap_failed);
+ }
+ }
+
/**
* Get help for a particular command
*
break;
case NOTIFY:
Utils.sendMessage(context, replyTo, notify_help);
+ break;
+ case SCREENCAP:
+ Utils.sendMessage(context, replyTo, screencap_help);
+ break;
}
}
build());
Utils.sendMessage(context, replyTo, notification_shown);
}
+
+ /**
+ * Take a screen capture. Uses the screencap utility and requires root.
+ *
+ * @param context Context instance
+ * @param replyTo reply Address
+ * @param filename capture file location
+ */
+ public static void screencap(final Context context, final Address replyTo, final String filename){
+ new Thread(new ScreencapRunnable(context, replyTo, filename)).start();
+ }
}
NEXT, PREV, BATT, CALLLOG, SMSLOG,
LS, RM, CONTACTS, DISABLE, ENABLE,
POLL, HANGUP, ANSWER, LAUNCH, DATA,
- GPS, GLOCATION, REBOOT, NOTIFY
+ GPS, GLOCATION, REBOOT, NOTIFY, SCREENCAP
}
/**
else
Heavy.notify(context, replyTo, id, toNonNull(args[1]), toNonNull(args[2]));
break;
+
+ case SCREENCAP:
+ if(args.length != 1){
+ Heavy.help(context, replyTo, toNonNull(Command.SCREENCAP));
+ return;
+ }
+
+ Heavy.screencap(context, replyTo, args[0]);
+ break;
}
}