Question

What I'm trying to do is Live Wallpaper with some action(that is already done)but the problem is there..that I've made it in Activity which "action" is an class who extends view and the Activity's setContentView() method isn't some layout ..it is this View.And what I'm trying to do now is to create option to set that activity as wallpaper,but I don't know how. This is my onCreate() method from the main Activity which is loading the View. I want that to be an Wallpaper..so how can I set it up to be one?

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SnowFall snowFallView = new SnowFall(this);
        setContentView(snowFallView);
        snowFallView.setBackgroundDrawable(getResources().getDrawable(
                R.drawable.christmas));

    }

Here's example app for what I want to create: https://play.google.com/store/apps/details?id=com.chiralcode.wallpaper.autumn&hl=bg

Was it helpful?

Solution

Did you implement wallpaper as a service? Get the basics - check Lars Vogel's tutorial on live wallpapers here

In short, you can set the wallpaper with an intent:

Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, new ComponentName(this, MyWallpaperService.class));
startActivity(intent);

You will need to adapt the above to your class names, and remember to have the permission android.permission.BIND_WALLPAPER in your AndroidManifest, but again, read his tutorial.

OTHER TIPS

Start Wallpaper service through activity , following is perfect working for that, you can put following in onclick(...) also, if you start livewallpaper ( your own live wallpaper directly through just one click) you just write following code,

        btnInstallWallpaper.setOnClickListener(new OnClickListener() {

        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @SuppressLint("InlinedApi")
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
             Intent intent = new Intent();
            if (android.os.Build.VERSION.SDK_INT >= 16)
            {
                intent.setAction("android.service.wallpaper.CHANGE_LIVE_WALLPAPER");
                intent.putExtra("android.service.wallpaper.extra.LIVE_WALLPAPER_COMPONENT", new ComponentName("com.example.wall", "com.example.wall.WallpaperService"));
            } else

                intent.setAction("android.service.wallpaper.LIVE_WALLPAPER_CHOOSER");
                intent.putExtra("android.service.wallpaper.extra.LIVE_WALLPAPER_COMPONENT", new ComponentName("com.example.wall", "com.example.wall.WallpaperService"));  // package + classname
            //}  
            startActivity(intent);
        }
    });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top