Choosing background for Live Wallpaper

后端 未结 2 1370
暖寄归人
暖寄归人 2020-12-04 18:41

I\'m writing a live wallpaper that creates an effect over a background. I want the user to be able to choose the background from any of the system wallpapers and camera pho

2条回答
  •  广开言路
    2020-12-04 19:23

    Nope, that's pretty much the best way to go about it. Anything that responds to android.intent.action.SET_WALLPAPER would be a wallpaper provider of one form or another. The problem is that giving them that list will take your control out of the equation. Essentially having them pick something from another provider will unset your Live Wallpaper. You could probably get around this with with some creative Manifest settings and or some "startActivityForResult" type calls.

    After they choose something though it's a simple matter of something like this in your WallpaperService.Engine:

    @Override
    public void onSurfaceChanged( SurfaceHolder holder, int format, int width, int height )
    {
        super.onSurfaceChanged( holder, format, width, height );
        if( isVisible() )
        {
        mSurfaceHolder = holder;
        final Drawable drawable = WallpaperManager.getInstance( getBaseContext() ).getFastDrawable();
        mSurfaceHolder.setFormat( RenderThread.pixFormat );
        Canvas c = mSurfaceHolder.lockCanvas();
        if( c != null )
            {
                drawable.draw( c );
                mSurfaceHolder.unlockCanvasAndPost( c );
            }
        }
    }
    

提交回复
热议问题