Set As Wallpaper option

pluton

Active Member
Licensed User
Longtime User
Hi everyone

Is it possible that I from my app set a wallpaper on phone

I have 5 images in my app and when user is on that image he has option

Copy to SD and then Set As Wallpaper.
How it is done ?? :sign0104:
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can do it with the Reflection library:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   SetWallPaper(LoadBitmap(File.DirAssets, "small_logo.png"))
End Sub

Sub Activity_Pause(UserClosed As Boolean)
   
End Sub
Sub Activity_Resume

End Sub
Sub SetWallPaper(Bmp As Bitmap)
   Dim r As Reflector
   r.Target = r.RunStaticMethod("android.app.WallpaperManager", "getInstance", _
      Array As Object(r.GetContext), Array As String("android.content.Context"))
   r.RunMethod4("setBitmap", Array As Object(Bmp), Array As String("android.graphics.Bitmap"))
End Sub

You will need to add the following permission to your manifest file:
B4X:
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
See this thread for more information about modifications to the manifest file: PreferenceActivity - Page 2
 
Upvote 0

magarcan

Active Member
Licensed User
Longtime User
Are there any other way to do this?? Using this method we aren't hable to choose wallpaper dimensions, size,...
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
You can do it with the Reflection library:

I tried your code and it works as expected and sets the wallpaper directly (Galaxy Note running Android 4.2.2). But I was wondering if it is possible to show the "crop and pan" wallpaper tool that is part of the Android system, instead of setting wallpaper directly.

Can it be done?
 
Upvote 0

merlin2049er

Well-Known Member
Licensed User
Longtime User
Hi, is it possible to just use the wallpaper that's set as a default in the android os?

I'd like to basically enable/disable that in my app.
 
Upvote 0

chrjak

Active Member
Licensed User
Longtime User
Android doesn't allow you to set a live wallpaper without user intervention. You can send an intent that will show the live wallpaper picker.
And which Code do i have to use?
Or better: Where to find the list of these intent codes?
Regards
 
Upvote 0

chrjak

Active Member
Licensed User
Longtime User
i know i can name my intent how i want but there are many other settings to set. For example: (the sharing intent)
i.Initialize(i.ACTION_SEND, "")
i.SetType("text/plain")
i.PutExtra("android.intent.extra.TEXT", "")
i.WrapAsIntentChooser("")
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
You need to send the same parameters the live wallpaper needs to draw.

Ie: x and width of screen
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
Nope. Im not at home so i cant check. Just open a livewallpaper project and check the parameters it uses. You have to have made one anyway for this to be applicable.
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
This only works if youve made a live wallpaper and it sounds like you havent

Again, this only works with live wallpapers you make yourself.
 
Upvote 0

chrjak

Active Member
Licensed User
Longtime User
I know that. and i made one. but i don't understand what you mean with "parameter"
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
Thats a basic term in programming though

Sub testname(ThisIsAparameter as int) as int
Return ThisIsAparameter
End sub
 
Upvote 0
Top