I started working on my first live wallpaper on android mainly working with this: http://www.vogella.com/articles/AndroidLiveWallpaper/article.html. The problem is that the wallpaper does not show up in the screen where you can select the wallpaper.
I started the wallpaper out of eclipse, uninstalled reinstalled the exported wallpaper, but it neither works on my smartphone nor on the emulator.
The Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.zdev.wallpaper.cpubeat"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<uses-feature android:name="android.software.live_wallpaper" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<service
android:name="de.zdev.wallpaper.CPUBeatService"
android:label="@string/app_name"
android:permission="android.permission.BIND_WALLPAPER" >
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data
android:name="android.service.wallpaper"
android:resource="@xml/wallpaper" />
</service>
</application>
The "wallpaper.xml" (I don't think the problem is here):
<?xml version="1.0" encoding="utf-8"?>
<Wallpaper
xmlns:android="http://schemas.android.com/apk/res/android"
android:thumbnail="@drawable/ic_launcher"
android:description="@string/description" />
And finally my "CPUBeatService.java":
package de.zdev.wallpaper.cpubeat;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Handler;
import android.service.wallpaper.WallpaperService;
import android.service.wallpaper.WallpaperService.Engine;
import android.view.SurfaceHolder;
public class CPUBeatService extends WallpaperService {
@Override
public Engine onCreateEngine(){
return new CPUBeatEngine();
}
private class CPUBeatEngine extends Engine{
private final Handler handler = new Handler();
private boolean visible = true;
private int width, height;
private final Runnable drawRunnable = new Runnable(){
public void run(){
doDraw();
}
};
public CPUBeatEngine(){
handler.post(drawRunnable);
}
private void draw(Canvas c){
c.drawColor(Color.GREEN);
}
@Override
public void onVisibilityChanged(boolean v){
visible = v;
if(visible) handler.post(drawRunnable);
else handler.removeCallbacks(drawRunnable);
}
@Override
public void onSurfaceDestroyed(SurfaceHolder holder){
super.onSurfaceDestroyed(holder);
visible = false;
handler.removeCallbacks(drawRunnable);
}
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int w, int h){
super.onSurfaceChanged(holder, format, w, h);
width = w;
height = h;
}
private void doDraw(){
SurfaceHolder holder = getSurfaceHolder();
Canvas c = null;
try {
c = holder.lockCanvas();
if (c != null) {
//do the real drawing now
draw(c);
}
} finally {
if (c != null)
holder.unlockCanvasAndPost(c);
}
handler.removeCallbacks(drawRunnable);
if (visible) {
handler.postDelayed(drawRunnable, 5000);
}
}
}
}
Thanks to anyone who can help.
Alright, after a few months, I decided to work on this again. I found the mistake... at least I think so. The Wallpaper.xml was not correct, this is correct:
<?xml version="1.0" encoding="utf-8"?>
<wallpaper
xmlns:android="http://schemas.android.com/apk/res/android"
android:thumbnail="@drawable/ic_launcher"
android:description="@string/description" />
Notice: <wallpaper
is written lowercase! I think that was the problem. :)