Android Question Button to My Live Wallpaper

MarcTG

Active Member
Licensed User
Longtime User
I would like to create a button that takes a user directly to my wallpaper and not to the wallpaper chooser/picker.
I know that this question has been asked in the past in this thread:
http://www.b4x.com/android/forum/th...or-livewallpaper-preview-from-a-button.21460/

but the suggested method does not seem to work for me... here's what I have:

B4X:
Dim Intent1 As Intent
Intent1.Initialize("android.service.wallpaper.CHANGE_LIVE_WALLPAPER", "")
Intent1.PutExtra("android.service.wallpaper.extra.LIVE_WALLPAPER_COMPONENT", "com.mycomp.LWP/.WallpaperService")
  StartActivity(Intent1)

When I press on the button nothing happens...

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this:
B4X:
Dim Intent1 As Intent
Intent1.Initialize("android.service.wallpaper.CHANGE_LIVE_WALLPAPER", "")
Dim cn As JavaObject
cn.InitializeNewInstance("android.content.ComponentName", Array As Object("com.mycomp.LWP", ".WallpaperService"))
Intent1.PutExtra("android.service.wallpaper.extra.LIVE_WALLPAPER_COMPONENT", cn)
StartActivity(Intent1)
 
Upvote 0

MarcTG

Active Member
Licensed User
Longtime User
That did not work either, maybe I am doing something wrong. I've attached an example, I used the Libgdx example provided by
Informatix and added an activity and button.
I am still using B4A V3.5.
 

Attachments

  • SetWallpaperTest.zip
    7.8 KB · Views: 200
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've just tried this code with the live wallpaper ball example and it works:
B4X:
Dim Intent1 As Intent
   Intent1.Initialize("android.service.wallpaper.CHANGE_LIVE_WALLPAPER","")
   Dim cn As JavaObject
   cn.InitializeNewInstance("android.content.ComponentName", _
     Array As Object("anywheresoftware.b4a.samples.livewallpaperball", "anywheresoftware.b4a.objects.WallpaperInternalService"))
   Intent1.PutExtra("android.service.wallpaper.extra.LIVE_WALLPAPER_COMPONENT",cn)
   StartActivity(Intent1)
 
Upvote 0

MarcTG

Active Member
Licensed User
Longtime User
Thanks Erel this works perfectly for the ball wallpaper example as well as the smiley example, the only change that has to be made for the smiley (libgdx live wallpaper) is:

B4X:
'("package name", "service name as written in manifest")
Array As Object("com.mycomp.LWP", "anywheresoftware.b4a.libgdx.lgLiveWallpaper")
'the service name for Libgdx live wallpaper is different...

So for my button I send the user to my wallpaper if the user is running jellybean or above, and to the live wallpaper chooser if he is running older versions of android, so the code looks as follows:

B4X:
Dim r As Reflector
Dim Intent1 As Intent
Dim Api As Int
Api = r.GetStaticField("android.os.Build$VERSION", "SDK_INT")

If Api < 16 Then
    Intent1.Initialize("android.service.wallpaper.LIVE_WALLPAPER_CHOOSER","")
    StartActivity(Intent1)

Else
    Intent1.Initialize("android.service.wallpaper.CHANGE_LIVE_WALLPAPER","")
    Dim cn As JavaObject
    '("package name", "service name as written in manifest")
    cn.InitializeNewInstance("android.content.ComponentName", Array As Object("com.mycomp.LWP", "anywheresoftware.b4a.libgdx.lgLiveWallpaper"))
    Intent1.PutExtra("android.service.wallpaper.extra.LIVE_WALLPAPER_COMPONENT",cn)
    StartActivity(Intent1)
End if

FYI, the code for the wallpaper chooser crashes when I am testing it on an emulator running version 2.3.7, but it works perfectly when I test it on my Samsung galaxy S device (music player) which is running version 2.3.5 (same API 10).

if I change that code to:
B4X:
Intent1.Initialize("android.intent.action.SET_WALLPAPER", "")
    Intent1.SetComponent("com.android.wallpaper.livepicker/.LiveWallpaperActivity")

It works as a chooser/picker code on my version 4.1+ emulator and devices (if running it without the if statement shown above), but crashes on both 2.3 device and emulator.

So to sum it up:
- Chooser/picker code 1 crashes with 2.3 emulator (Error 1 -see snapshot) but works on my device running the same API
- Chooser/picker code 2 crashes with 2.3 emulator and device (Error 2 -see snapshot) but works on my emulators and devices running 4.1+ (I did not test 3.0 or 4.0 - but my guess is 4.0 should be ok - 3.0 devices are uncommon so no need to test)

Again, thanks Erel for all the help, and sorry for this long post. I just thought a detailed post might help someone that runs into this same issue...


Error 1.png
Error 2.png
 
Last edited:
Upvote 0

MarcTG

Active Member
Licensed User
Longtime User
Thanks Erel,

I found another error :-(, this one seems to be libgdx related (does not occur with Ball example).

The following sequence triggers it:
1- open application
2- press on set wallpaper
3- press on back go back to activity
4- exit application
5- open application

Android AVD gives an error after step 4, while my phone loads the activity in 5 with a blurry layout and text.

Check attached for example
 

Attachments

  • Smileymodified.zip
    7.9 KB · Views: 197
Upvote 0

MarcTG

Active Member
Licensed User
Longtime User
An easy fix seems to be to exit activity after the button is pressed. In that case the back button will not bring you back to activity and will just go back to home screen...
Other suggestions are welcome :)
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Thanks Erel this works perfectly for the ball wallpaper example as well as the smiley example, the only change that has to be made for the smiley (libgdx live wallpaper) is:

B4X:
'("package name", "service name as written in manifest")
Array As Object("com.mycomp.LWP", "anywheresoftware.b4a.libgdx.lgLiveWallpaper")
'the service name for Libgdx live wallpaper is different...

So for my button I send the user to my wallpaper if the user is running jellybean or above, and to the live wallpaper chooser if he is running older versions of android, so the code looks as follows:

B4X:
Dim r As Reflector
Dim Intent1 As Intent
Dim Api As Int
Api = r.GetStaticField("android.os.Build$VERSION", "SDK_INT")

If Api < 16 Then
    Intent1.Initialize("android.service.wallpaper.LIVE_WALLPAPER_CHOOSER","")
    StartActivity(Intent1)

Else
    Intent1.Initialize("android.service.wallpaper.CHANGE_LIVE_WALLPAPER","")
    Dim cn As JavaObject
    '("package name", "service name as written in manifest")
    cn.InitializeNewInstance("android.content.ComponentName", Array As Object("com.mycomp.LWP", "anywheresoftware.b4a.libgdx.lgLiveWallpaper"))
    Intent1.PutExtra("android.service.wallpaper.extra.LIVE_WALLPAPER_COMPONENT",cn)
    StartActivity(Intent1)
End if

FYI, the code for the wallpaper chooser crashes when I am testing it on an emulator running version 2.3.7, but it works perfectly when I test it on my Samsung galaxy S device (music player) which is running version 2.3.5 (same API 10).

if I change that code to:
B4X:
Intent1.Initialize("android.intent.action.SET_WALLPAPER", "")
    Intent1.SetComponent("com.android.wallpaper.livepicker/.LiveWallpaperActivity")

It works as a chooser/picker code on my version 4.1+ emulator and devices (if running it without the if statement shown above), but crashes on both 2.3 device and emulator.

So to sum it up:
- Chooser/picker code 1 crashes with 2.3 emulator (Error 1 -see snapshot) but works on my device running the same API
- Chooser/picker code 2 crashes with 2.3 emulator and device (Error 2 -see snapshot) but works on my emulators and devices running 4.1+ (I did not test 3.0 or 4.0 - but my guess is 4.0 should be ok - 3.0 devices are uncommon so no need to test)

Again, thanks Erel for all the help, and sorry for this long post. I just thought a detailed post might help someone that runs into this same issue...


View attachment 25098 View attachment 25099
It seems that it does not work with an emulator. My attempts are unsuccessful.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Thanks Erel,

I found another error :-(, this one seems to be libgdx related (does not occur with Ball example).

The following sequence triggers it:
1- open application
2- press on set wallpaper
3- press on back go back to activity
4- exit application
5- open application

Android AVD gives an error after step 4, while my phone loads the activity in 5 with a blurry layout and text.

Check attached for example
I'm not able to reproduce this error. Note that when you open the application, your button is not displayed by libGDX (it is not even started).
 
Upvote 0

MarcTG

Active Member
Licensed User
Longtime User
I forgot to mention that your SmileyModified.zip has a missing file: smiley.png.

Really? Weird, I thought I pressed on export to zip... the button is part of the activity (like a settings button). The problem seems to happen when you go from libgdx live wallpaper back to the activity after pressing on the button.

Can you post the full error message from the logs?

I will post the example file again along with an .apk and the log this weekend when i get some free time away from work.

I appreciate both of you helping out on this.
 
Upvote 0
Top