Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AndroidAppmethodCode SnippetDelphiFiremonkey

Code Snippet To Set The Device Wallpaper In Delphi XE7 Firemonkey On Android

| Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

Delphi XE7 Firemonkey Android Wallpaper Code Snippet | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSDeveloper Todd Frankson has posted a code snippet for setting the device wallpaper in Android with Delphi XE7 Firemonkey. The original post is on the Embarcadero Forum but I have duplicated it here. Android has a class called the WallpaperManager which allows you to set the system wallpaper and the code uses this class. Additionally the code uses the Android BitmapFactory class. Todd recommends using the Java2op tool to generate the necessary files but you can also access the Object Pascal wrapper code for WallpaperManager on Github as well (and BitmapFactory). The code is pretty straightforward. A TImageViewer is used to save a JPEG out to the filesystem. The JPEG is loaded into the BitmapFactory and then the bitmap is set via the WallpaperManager. This code should also work with Appmethod. Here is the code snippet:
Here's a way to Set the wallpaper.don't know how right or wrong it is).

Live wallpaper is not to much different, so this is a starting point

1. Use Java2op to generate the delphi bridge files of all the wallpaper classes.

2 New Fmx poject
3. Add the units to your uses clause along with:
4. place the following on the form:
Button1: TButton;
Image1: TImageViewer;

5. Load an image into Image1 in design time. and set Button1 onclick to below.

procedure TForm1.Button1Click(Sender: TObject);

Factoryoptions: JBitmapFactory_Options;
aScreenSize: TPoint;
Widthofscreen, Heightofscreen: Integer;
{Create a filename to save the image to}
{Save the image}
{Create  JBitmap options }
{Read up on these in the android API}
Factoryoptions.inJustDecodeBounds := true;
Factoryoptions.inJustDecodeBounds := false;
{Get the wallpaper manager instance}
(TJContext.JavaClass.WALLPAPER_SERVICE) as  ILocalObject).GetObjectID);
{Load the image we saved}
{Only change the wallpaper if the Bitmap loads}
if TheBitmaptoShow <>NIL then
{Set the Wallpaper}

Head over and see the post on the Embarcadero forum for Delphi XE7 Firemonkey on Android.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts

Unleashing Creativity With Song Writer AI: A Deep Dive


How To Build Stable Diffusion Text To Image Prompts


FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes


Ryzen 9 5950x: One Billion Lines Of Delphi Code Compiled In ~5 Minutes On 16 Cores

Sign up for our Newsletter and
stay informed

Leave a Reply