Search code examples
androiddelphifiremonkeydelphi-xe5systemtime

SYSTEMTIME in FireMonkey


Can you help me. I have a code, but it don't work on Android (who would doubt that).

procedure SetTime(sTime: string);

var
   vsys: _SYSTEMTIME;

begin
  GetLocalTime(vsys);
  vsys.wYear := StrToInt(Copy(sTime,7,4));
  vsys.wMonth := StrToInt(Copy(sTime,4,2));
  vsys.wDay := StrToInt(Copy(sTime,1,2));
  vsys.wHour := StrToInt(Copy(sTime,12,2));
  vsys.wMinute := StrToInt(Copy(sTime,15,2));
  vsys.wSecond := StrToInt(Copy(sTime,18,2));
  SetLocalTime(vsys);
end;

I need a similar code, but to make it work on Android or analogy. Thanks in advance


Solution

  • User applications do not have permission to change the date/time on the device. This is discussed in much more detail here: How to set mobile system time and date in android?

    Perhaps the best you can do then is to invoke the system date/time settings activity. In Java code that would be

    startActivity(new Intent(android.provider.Settings.ACTION_DATE_SETTINGS));
    

    This should be simple enough for you to translate to the Delphi equivalent. This Embarcadero code example covers how to do that: http://docwiki.embarcadero.com/CodeExamples/Seattle/en/FMX.Android_Intents_Sample