我是android开发中的菜鸟。我正在试用livewallpaper开发。我没有任何错误地完成了代码..但是livewallpaper没有在我的avd中的活壁纸列表中显示
这是我的清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ani.trial.lwp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7" />
<uses-feature android:name="android.software.live_wallpaper"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<service
android:name="ani.trial.lwp.mainservice"
android:label="Trial"
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/layout"/>
</service>
</application>
</manifest>
和我的主要java代码 -
package ani.trial.lwp;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Handler;
import android.service.wallpaper.WallpaperService;
import android.view.SurfaceHolder;
public class mainservice extends WallpaperService {
private final Handler mHandler = new Handler();
@Override
public Engine onCreateEngine() {
// TODO Auto-generated method stub
return new RenderEngine();
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onDestroy() {
super.onDestroy();
}
class RenderEngine extends Engine
{
boolean mVisible=true;
RenderEngine(){
}
@Override
public void onVisibilityChanged(boolean visible){
mVisible = visible;
if(visible)
drawFrame();
}
private final Runnable mDrawScene = new Runnable(){
public void run(){
drawFrame();
}
};
void drawFrame()
{
//Don't render when not visible
if(!mVisible) return;
final SurfaceHolder holder = getSurfaceHolder();
Canvas c= null;
try
{
c=holder.lockCanvas();
if(c!=null){
//TODO iterate through sprites/renderables
//and render them here
c.drawColor(Color.MAGENTA);
}
}
finally
{
if(c!=null) holder.unlockCanvasAndPost(c);
}
mHandler.removeCallbacks(mDrawScene);
if(mVisible){
mHandler.postDelayed(mDrawScene, 1000/30);
}
}
}}
任何想法都是错误的人吗?我正在尝试一些教程,这就是我完成它的方法。还有任何关于动态壁纸开发的好教程吗?我得到了一些renderscripts,但我不知道如何在eclipse中添加它们..提前感谢!
答案 0 :(得分:0)
这是两个非常好的动态壁纸教程,你可以遵循: -
http://www.vogella.com/articles/AndroidLiveWallpaper/article.html
http://www.codeproject.com/Articles/108390/How-To-Create-Android-Live-Wallpaper
对于要在动态壁纸列表中显示的图标,您要引用的xml文件“layout”必须具有如下定义的代码:
<?xml version="1.0" encoding="utf-8"?>
<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="packagename.LiveWallpaperSettings"
android:thumbnail="@drawable/icon"/>
必须在其中定义缩略图。