Android Tutorial Android Live Wallpaper tutorial

mcmanu

Active Member
Licensed User
Longtime User
Issue 4.0.4

When i Programm a Livewallpaper and want to set it, it crashes every time under Ics 4.0.4
How can i fix that?
 

mcmanu

Active Member
Licensed User
Longtime User
Check the logs and find the error message.


Thats the Example that you have Posted -->

Logs


LogCat connected to: B4A-Bridge: samsung GT-I9100-359585041223105
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (service1) Create **
** Service (service1) Start **
Connected to B4A-Bridge (Wifi)
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:anywheresoftware.b4a.samples.livewallpaperball
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Service (wallpaperservice) Create **
wallpaperservice_service_create (java line: 234)
java.lang.NoSuchFieldError: anywheresoftware.b4a.BA.isService
at anywheresoftware.b4a.objects.WallpaperInternalService$LWManager.Initialize(WallpaperInternalService.java:62)
at anywheresoftware.b4a.samples.livewallpaperball.wallpaperservice._service_create(wallpaperservice.java:234)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
at anywheresoftware.b4a.samples.livewallpaperball.wallpaperservice.onCreate(wallpaperservice.java:38)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2264)
at android.app.ActivityThread.access$1600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4511)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
at dalvik.system.NativeStart.main(Native Method)
** Service (wallpaperservice) Create **
wallpaperservice_service_create (java line: 234)
java.lang.NoSuchFieldError: anywheresoftware.b4a.BA.isService
at anywheresoftware.b4a.objects.WallpaperInternalService$LWManager.Initialize(WallpaperInternalService.java:62)
at anywheresoftware.b4a.samples.livewallpaperball.wallpaperservice._service_create(wallpaperservice.java:234)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
at anywheresoftware.b4a.samples.livewallpaperball.wallpaperservice.onCreate(wallpaperservice.java:38)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2264)
at android.app.ActivityThread.access$1600(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1212)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4511)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
at dalvik.system.NativeStart.main(Native Method)
 

bloxa69

Active Member
Licensed User
Longtime User
Erel,
I'm still struggling to make LWP smooth and anti-aliased. Even though I load bitmaps without scaling, they are still not smooth enough, especially the ones I need to rotate. I've tried this, but it doesn't work:
B4X:
Sub SetAntiAlias (c As Canvas)
    Dim r As Reflector
    Dim NativeCanvas As Object
    r.Target = c
    NativeCanvas = r.GetField("canvas")
    Dim PaintFlagsDrawFilter As Object
    PaintFlagsDrawFilter = r.CreateObject2("android.graphics.PaintFlagsDrawFilter", _
        Array As Object(0, 1), Array As String("java.lang.int", "java.lang.int"))
    r.Target = NativeCanvas
    r.RunMethod4("setDrawFilter", Array As Object(PaintFlagsDrawFilter), Array As String("android.graphics.DrawFilter"))
End Sub

I found a piece of Java code to enable antialiasing on LWP. I don't know if there is a way to translate it to B4A script anyhow?

B4X:
package com.mydomain.wallpapers.mywallpaper;

import rajawali.wallpaper.Wallpaper;
import android.content.Context;

public class MyWallpaper extends Wallpaper {
    private MyWallpaperRenderer mRenderer;

    public Engine onCreateEngine() {
        mRenderer = new MyWallpaperRenderer(this);

        // -- the last parameter (true) indicates that we want to use multi-sampling / anti-aliasing
        return new WallpaperEngine(this.getSharedPreferences(SHARED_PREFS_NAME,
                Context.MODE_PRIVATE), getBaseContext(), mRenderer, true);
    }
}
 

trebun

Member
Licensed User
Longtime User
Mh.

I will implement a settings page for my Live Wallpaper.

I read this tiny help:

http://www.b4x.com/forum/basic4andr...roid-live-wallpaper-tutorial-4.html#post77786

I do:

1.) Create a wallpaper.xml:
B4X:
<?xml version="1.0" encoding="utf-8"?>
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
  android:thumbnail="@drawable/icon" android:description="@string/description"
  android:settingsActivity="de.duzka.livewallpaper.settings" 
/>

2.)Make the wallpaper.xml read-only!

3.) Create a new activity module, called "Settings"

4.) Load my layout:

B4X:
Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("settingsLayout")

End Sub

See the attachment, my wallpaper gives a force close...

Whats wrong...?

Oh, I use LiveWallpaper 1.01

Regards,
trebun
 

Attachments

  • lwp.jpg
    63.7 KB · Views: 347

trebun

Member
Licensed User
Longtime User
Look at the unfiltered logs on the IDE to see the cause of that error.

Mh.

Its hard to understand:

Permission Denial: starting Intent { cmp=net.flyercircle.livewallpaper/.settings (has extras) [...]

Maybe my error, but how can I fix it?

Full Error:

Have anyone a solution for me?

Regards,
trebun

//Edit: Another question: Is it the right way to do every hour something with "LWM.StartTicking(3600000)" or is another solution better?
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Add this line to the manifest editor:
B4X:
SetActivityAttribute(settings, android:exported, true)

Another question: Is it the right way to do every hour something with "LWM.StartTicking(3600000)" or is another solution better?
It will work as long as Android doesn't kill your process. It will probably be better to use a service and call StartServiceAt.
 

trebun

Member
Licensed User
Longtime User
Add this line to the manifest editor:
B4X:
SetActivityAttribute(settings, android:exported, true)

:sign0098:

Thank you, it works!

It will work as long as Android doesn't kill your process. It will probably be better to use a service and call StartServiceAt.

Ok - I will try!

Big thanks and "Guten Rutsch" [ I don't know what it is in english ;-) ]
 

trebun

Member
Licensed User
Longtime User
@Erel

StartServiceAt is my friend - Thank you!

Another question about the preview: If I change some settings from my settingscreen, how can I update the preview"-view" from the live wallpaper?

Regards,
trebun
 

FJS

Active Member
Licensed User
Longtime User
Access Wallpaper menu directly

Hello,
Is there a way to access directly the livewallpaper menu through a button and not having to go over the hold finger on the screen --> LiveWallpapers --> Pick Wallpaper... process? I've seen some LiveWallpapers on the market that get you to the set as wallpaper screen directly through a button. Skipping all the Wallpaper selection process.
Thanks,
Jorge
 

trebun

Member
Licensed User
Longtime User

Yes,
take a look:

http://www.b4x.com/forum/basic4andr...id-live-wallpaper-tutorial-11.html#post124053

http://www.b4x.com/forum/basic4andr...id-live-wallpaper-tutorial-11.html#post124080
 

trebun

Member
Licensed User
Longtime User
Mkay, I have some troubles to stretch the wallpaper background.

The LiveWallpaperImage example does the same effect - but I don't know about the usage from OffsetX,Y... :/

Maybe there is an example to scale the wallpaper with the right ratio?

My Code (from the LiveWallpaperImage):
B4X:
Sub LWM_OffsetChanged (Engine As LWEngine)
   If Flyer.IsInitialized  Then
      Engine.Rect.Left = -Engine.CurrentOffsetX 
      Engine.Rect.Top = -Engine.CurrentOffsetY 
      Engine.Rect.Right = -Engine.CurrentOffsetX + Engine.FullWallpaperWidth 
      Engine.Rect.Bottom = -Engine.CurrentOffsetY + Engine.FullWallpaperHeight
      Engine.Canvas.DrawBitmap(Flyer, Null, Engine.Rect)
      
      Log("Engine.Rect.Left: " & Engine.CurrentOffsetX)
      Log("Engine.Rect.Top: " & Engine.CurrentOffsetY)
      Log("Engine.Rect.Right: " & (Engine.CurrentOffsetX + Engine.FullWallpaperWidth))
      Log("Engine.Rect.Bottom: " & (Engine.CurrentOffsetY + Engine.FullWallpaperHeight))
   Else
      Engine.Canvas.DrawColor(Colors.Black)
      Engine.Canvas.DrawText(AResMap.Get("other_placeholder_on_screen"), 120dip, 120dip, Typeface.DEFAULT_BOLD, 30, Colors.White, "LEFT")
   End If
   
   Engine.RefreshAll
End Sub

Called when a new flyer is downloaded. :/

Regards,
trebun
 

Attachments

  • stretch_wallpaper.jpg
    92.3 KB · Views: 358
Cookies are required to use this site. You must accept them to continue using the site. Learn more…