2015-04-14 162 views
0

谁能告诉我如何以编程方式在Delphi XE5-8的Android桌面上设置壁纸?
谢谢。如何设置Android壁纸?

+3

http://bit.ly/1FKFpGV –

+0

参见[代码段来设置设备壁纸在Delphi XE7 Firemonkey在Android(HTTP:// WWW。 fmxexpress.com/code-snippet-to-set-the-device-wallpaper-in-delphi-xe7-firemonkey-on-android/)。 –

回答

1

由@LURD链接的复制和@FreeConsulting

这里有一个方法来设置wallpaper.don't知道它是多么正确或错误)。

动态壁纸是不是太大的不同,所以这是一个起点

  1. 使用Java2op生成所有壁纸类的德尔福桥文件。

  2. 新FMX poject

  3. 单位添加到您的使用条款连同:

  4. 窗体上放置如下: Button1的:TButton的; Image1:TImageViewer;

  5. 在设计时加载图像到Image1中。并将Button1设置为在下面。

代码:

procedure TForm1.Button1Click(Sender: TObject); 
Var 
    FWallpaperManager: JWallpaperManager; 
    Factoryoptions: JBitmapFactory_Options; 
    AScreenSize: TPoint; 
    WidthOfScreen, HeightOfScreen: Integer; 
    FFileToOpen: string; 
begin 
    {Create a filename to save the image to} 
    FFiletoopen:= System.IOUtils.TPath.Combine(System.IOUtils.TPath.GetDocumentsPath, 'Thefile.jpg'); 
    {Save the image} 
    Image1.Bitmap.SaveToFile(FFileToOpen); 
    {Create JBitmap options } 
    Factoryoptions:= TJBitmapFactory_Options.Create; 
    {Read up on these in the android API} 
    Factoryoptions.inJustDecodeBounds:= True; 
    Factoryoptions.inPreferQualityOverSpeed:= True; 
    Factoryoptions.inJustDecodeBounds:= False; 
    {Get the wallpaper manager instance} 
    FWallpaperManager:= TJWallpaperManager.Wrap((SharedActivityContext.GetSystemService 
       (TJContext.JavaClass.WALLPAPER_SERVICE) as ILocalObject).GetObjectID); 
    {Load the image we saved} 
    TheBitmaptoShow:= TJBitmapfactory.JavaClass.DecodeFile(StringToJString(FFiletoopen), FactoryOptions); 
    {Only change the wallpaper if the Bitmap loads} 
    if TheBitmaptoShow <> nil then begin 
    {Set the Wallpaper} 
    FWallpaperManager.SetBitmap(TheBitmaptoShow);   
    end; 
end;