"Default Activity Not Found" in WallpaperService

589 views Asked by At

I want to use a gif image as wallpaper in Android and I'm facing some problem. I have the following error: "Default Activity Not Found". There is no error in the project, but when I run it, I got this error on 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);
        }
    }
}

This is my manifest:

<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>
2

There are 2 answers

1
Sagar Aghara On

Replace this on your in Manifest file.

<intent-filter>

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

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

</intent-filter>

i think this will solve your Problem.please check it and let me know.

Hope this will helps..(:

1
user7807108 On

Run->Edit Configurations->Launch set to "Nothing"