0

我想在 Android 中使用 gif 图像作为壁纸,但遇到了一些问题。我有以下错误:“未找到默认活动”。项目中没有错误,但是当我运行它时,我在 Android Studio 上得到了这个错误。

public class GIFWallpaperService extends WallpaperService {

    @Override
    public WallpaperService.Engine onCreateEngine() {
        try {
            Movie movie = Movie.decodeStream(
                    getResources().getAssets().open("girl.gif"));

            return new GIFWallpaperEngine(movie);
        }catch(IOException e){
            Log.d("GIF", "Could not load asset");
            return null;
        }
    }

    private class GIFWallpaperEngine extends WallpaperService.Engine {

        private final int frameDuration = 20;

        private SurfaceHolder holder;
        private Movie movie;
        private boolean visible;
        private Handler handler;

        public GIFWallpaperEngine(Movie movie) {
            this.movie = movie;
            handler = new Handler();
        }

        @Override
        public void onCreate(SurfaceHolder surfaceHolder) {
            super.onCreate(surfaceHolder);
            this.holder = surfaceHolder;
        }

        private Runnable drawGIF = new Runnable() {
            public void run() {
                draw();
            }
        };


        private void draw() {
            if (visible) {
                Canvas canvas = holder.lockCanvas();
                canvas.save();
                    // Adjust size and position so that
                    // the image looks good on your screen
                    canvas.scale(3f, 3f);
                    movie.draw(canvas, -100, 0);
                canvas.restore();
                holder.unlockCanvasAndPost(canvas);
                movie.setTime((int) (System.currentTimeMillis() % movie.duration()));

                handler.removeCallbacks(drawGIF);
                handler.postDelayed(drawGIF, frameDuration);
            }
        }

        @Override
        public void onVisibilityChanged(boolean visible) {
            this.visible = visible;
            if (visible) {
                handler.post(drawGIF);
            } else {
                handler.removeCallbacks(drawGIF);
            }
        }

        @Override
        public void onDestroy() {
            super.onDestroy();
            handler.removeCallbacks(drawGIF);
        }
    }
}

这是我的清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.hathy.gifwallpaper">

    <application android:allowBackup="true" android:label="@string/app_name"
        android:icon="@drawable/ic_launcher" android:theme="@style/AppTheme">

        <service
            android:name=".GIFWallpaperService"
            android:enabled="true"
            android:label="GIF Wallpaper"
            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" >
            </meta-data>
        </service>

    </application>

    <uses-feature
        android:name="android.software.live_wallpaper"
        android:required="true" >
    </uses-feature>
</manifest>
4

2 回答 2

0

运行->编辑配置->启动设置为“无”

于 2017-04-03T08:54:16.997 回答
0

在您的清单文件中替换它。

<intent-filter>

    <action android:name="android.service.wallpaper.WallpaperService"/>

    <category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

我认为这将解决您的问题。请检查并告诉我。

希望这会有所帮助..(:

于 2016-12-31T04:01:45.260 回答