Categories
Android

Setting Android Settings

On the Android platform all the system wide settings that are accessible via the Settings app are also accessible to your app. You just need to add the uses permission WRITE_SETTINGS. Here is a simple Delphi XE5 example for changing the screen timeout.

First you need the following in your uses clause:

Androidapi.JNI.Provider, // JSettings_SystemClass
FMX.Helpers.Android; // SharedActivityContext

Here is the code to read and set the Screen Off Timeout:

function GetScreenOffTimeout: Integer;
begin
  Result := TJSettings_System.JavaClass.getInt(
    SharedActivityContext.getContentResolver,
    TJSettings_System.JavaClass.SCREEN_OFF_TIMEOUT,
    15000);  // 15 seconds is default is not found
end;

function SetScreenOffTimeout(ATimeOut: Integer): Boolean;
begin
  Result := TJSettings_System.JavaClass.putInt(
    SharedActivityContext.getContentResolver,
    TJSettings_System.JavaClass.SCREEN_OFF_TIMEOUT,
    ATimeOut);
end;

In the GetScreenOffTimeout we pass a default value to use if none is found. I passed in 15000, which is 15 seconds, or the smallest value for my phone. The largest value on my phone is 600000, which is 10 minutes. It appears you can set it to any value, even one that the settings app doesn’t explicitly list as an option.

There are lots of other settings available for your adjustment.

12 replies on “Setting Android Settings”

Are these settings global, or do the changes you make only apply to your app? Being able to turn off the SCREEN_OFF_TIMEOUT would be very useful for specific apps, but turning it off globally would be a very bad thing.

These are system wide settings. If you want to keep the screen on for your app you could cache the old timeout and then replace it when your app becomes inactive, or use a WakeLock (I’ll blog about that in the future).

Hi, i need acces to android WiFi settings or enabled the WiFi on start aaplication created in Delphi xe5. Thanks!

hi i’m from korea (south)

i don’t speak English, but i can struggle.

ok.. question.

I want to change the virtual keyboard type in android and ios.

example, style, keyboard sound, keyboard background, keyboard touch effect.

please…

and I’ll return the favour some time.

thank you

You are correct. I was being at bit lazy.

The includes needed in XE7 are

Androidapi.Helpers
Androidapi.JNI.Provider

Thanks

Wade

Comments are closed.