How to Update the Terminal's Time Setting: Difference between revisions

From wizarPOS
No edit summary
No edit summary
Line 1: Line 1:
== By auto update ==
Open wifi, connect it to network, the date and time will be auto updated.
== By manual ==
From Setting>Date&time, close "Automatic time zone" ,"Automatic date&time", and then set date, time.
== By API ==
Use the android system clock method to change the system time.
Use the android system clock method to change the system time.
== Permissions ==
=== Permissions ===
   android.permission.CLOUDPOS_SETTIME
   android.permission.CLOUDPOS_SETTIME
The app declares the permission in the manifest.
The app declares the permission in the manifest.


== Download ==
=== Demo source===
follows is the snippet code:
follows is the snippet code:
<syntaxhighlight lang="java">
<syntaxhighlight lang="java">

Revision as of 06:14, 17 December 2018

By auto update

Open wifi, connect it to network, the date and time will be auto updated.

By manual

From Setting>Date&time, close "Automatic time zone" ,"Automatic date&time", and then set date, time.

By API

Use the android system clock method to change the system time.

Permissions

 android.permission.CLOUDPOS_SETTIME

The app declares the permission in the manifest.

Demo source

follows is the snippet code:

public static void setDateTime(int year, int month, int day, int hour, int minute) throws IOException, InterruptedException {
 
        Calendar c = Calendar.getInstance();
        c.set(Calendar.YEAR, year);
        c.set(Calendar.MONTH, month-1);
        c.set(Calendar.DAY_OF_MONTH, day);
        c.set(Calendar.HOUR_OF_DAY, hour);
        c.set(Calendar.MINUTE, minute);
         
        long when = c.getTimeInMillis();
        if (when / 1000 < Integer.MAX_VALUE) {
            SystemClock.setCurrentTimeMillis(when);
        }
        long now = Calendar.getInstance().getTimeInMillis();
        //Log.d(TAG, "set tm="+when + ", now tm="+now);
 
        if(now - when > 1000)
            throw new IOException("failed to set Date."); 
         
    }

Please download the whold project demo