{"id":272,"date":"2015-06-03T11:02:26","date_gmt":"2015-06-03T10:02:26","guid":{"rendered":"https:\/\/mokrzycki.eu\/blog\/?p=272"},"modified":"2021-09-07T08:50:07","modified_gmt":"2021-09-07T07:50:07","slug":"change-time-in-genymotion-emulator-simple-java-app","status":"publish","type":"post","link":"https:\/\/mokrzycki.eu\/blog\/2015\/06\/03\/change-time-in-genymotion-emulator-simple-java-app\/","title":{"rendered":"Change time in genymotion emulator &#8211; simple java app"},"content":{"rendered":"\n<p>I made app in executable jar java file for setting time in genymotion emulator.<\/p>\n\n\n\n<p>Here is simple java code and compiled app for setting time in genymotion app. Below code I showed how the app looks like and also added ready jar app to download.<\/p>\n\n\n\n<p>Code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class SetTimeInGenyMotion {\n    private JTextField textField1;\n    private JButton getTimeInProperButton;\n    private JButton setTimeInProperButton;\n    private JButton getTimeAndSetButton;\n    private JPanel panel1;\n    public static final String FORMAT = \"YYYYMMDD.HHmmss\";\n\n    public static void main(String&#91;] args) {\n        new SetTimeInGenyMotion().doStuff();\n    }\n\n    private void doStuff() {\n\n        getTimeInProperButton.addActionListener(new ActionListener() {\n            @Override\n            public void actionPerformed(ActionEvent e) {\n                textField1.setText(getTime());\n            }\n        });\n\n        setTimeInProperButton.addActionListener(new ActionListener() {\n            @Override\n            public void actionPerformed(ActionEvent e) {\n                String time = textField1.getText();\n                setTime(time);\n            }\n        });\n\n        getTimeAndSetButton.addActionListener(new ActionListener() {\n            @Override\n            public void actionPerformed(ActionEvent e) {\n                String time = getTime();\n                setTime(time);\n                textField1.setText(time);\n            }\n        });\n\n        showWindow();\n    }\n\n    private void showWindow() {\n        JFrame frame = new JFrame(\"SetTimeInGenyMotion\");\n        frame.setContentPane(panel1);\n        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\n        frame.setMinimumSize(new Dimension(680, 0));\n        frame.pack();\n        frame.setVisible(true);\n    }\n\n    private void setTime(String time) {\n        try {\n            String command = \"adb shell date -s \" + time;\n\n            Runtime rt = Runtime.getRuntime();\n            Process pr = rt.exec(command);\n            BufferedReader br = new BufferedReader(new InputStreamReader(pr.getErrorStream(), \"UTF-8\"));\n            String l = \"\";\n\n            while ((l = br.readLine()) != null) {\n                System.out.println(l);\n            }\n            br.close();\n\n        } catch (IOException e1) {\n            e1.printStackTrace();\n        }\n    }\n\n    private String getTime() {\n        \/\/adb shell date -s YYYYMMDD.HHmmss\n        \/\/http:\/\/stackoverflow.com\/questions\/7094772\/how-to-set-android-device-date-time-programmatically\n\n        String format = \"YYYYMMdd.HHmmss\";\n        Calendar instance = Calendar.getInstance();\n        String time = getDate(instance.getTimeInMillis(), format);\n        return time;\n    }\n\n    public static String getDate(long milliSeconds, String dateFormat) {\n        \/\/ Create a DateFormatter object for displaying date in specified format.\n        SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);\n        \/\/ Create a calendar object that will convert the date and time value in milliseconds to date.\n        Calendar calendar = Calendar.getInstance();\n        calendar.setTimeInMillis(milliSeconds);\n        return formatter.format(calendar.getTime());\n    }\n}<\/code><\/pre>\n\n\n\n<p>Download:<br \/><a href=\"https:\/\/mokrzycki.eu\/blog\/wp-content\/uploads\/2015\/06\/setTimeInGenyMotion.jar\"><img decoding=\"async\" src=\"https:\/\/mokrzycki.eu\/blog\/wp-content\/uploads\/2015\/06\/pack.png\" alt=\"download\"\/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I made app in executable jar java file for setting time in genymotion emulator. Here&#8230;<\/p>\n","protected":false},"author":1,"featured_media":282,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[502],"tags":[135,5,164,65,160,191,190,186,185,189,188,187,158,184,192],"_links":{"self":[{"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/posts\/272"}],"collection":[{"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/comments?post=272"}],"version-history":[{"count":17,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/posts\/272\/revisions"}],"predecessor-version":[{"id":924,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/posts\/272\/revisions\/924"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/media\/282"}],"wp:attachment":[{"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/media?parent=272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/categories?post=272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/tags?post=272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}