-4

I have a project,where i have a button when the user click the button,then camera preview is set as wallpaper,can any one give me an idea how can i do that?

I am using Following code to camera preview

public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback{

private SurfaceHolder mHolder;
private Camera mCamera;


public CameraPreview(Context context, Camera camera) {
    super(context);
    mCamera=camera;
    // TODO Auto-generated constructor stub
    mHolder = getHolder();
    mHolder.addCallback(this);
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    try {
        mCamera.setPreviewDisplay(holder);
        mCamera.setDisplayOrientation(90);
        mCamera.startPreview();
    } catch (IOException e) {
        Log.d("DEBUG", "Error setting camera preview: " + e.getMessage());
    }
}



@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub

}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {
    // TODO Auto-generated method stub

    if (mHolder.getSurface() == null){
      // preview surface does not exist
      return;
    }

    // stop preview before making changes
    try {
        mCamera.stopPreview();
    } catch (Exception e){
      // ignore: tried to stop a non-existent preview
    }

    // set preview size and make any resize, rotate or
    // reformatting changes here

    // start preview with new settings
    try {
        mCamera.setPreviewDisplay(mHolder);
        mCamera.startPreview();

    } catch (Exception e){
        Log.d("DEBUG", "Error starting camera preview: " + e.getMessage());
    }
}
}

But my problem was how to add the camera preview to WallpaperService?

Somanadh
  • 97
  • 2
  • 11

2 Answers2

0

First, when the user clicks the button, take a picture of the camera preview and find out the path where the picture is saved.

Then refer to this link to set a particular image as wallpaper by specifying its path.

How to set image as wallpaper programmatically?

Community
  • 1
  • 1
SoulRayder
  • 5,072
  • 6
  • 47
  • 93
  • Thanks for reply, but my app requirement is when the user clicks "set wallpaper" button,then live camera will be added to the wallpaper screen. – Somanadh Jan 03 '14 at 09:12
  • yes, so u can programmatically make the camera take a pic, save it and then use the image stored in the path to set as wallpaper, when the user clicks "set wallpaper" button. Anyhow you will have to display an image as the wallpaper. So whatever the preview was showing at the instant u click the button, will be displayed as wallpaper. – SoulRayder Jan 03 '14 at 09:16
  • sorry, my app requirement is not to set the camera picture as wallpaper. my requirement is when we open the camera it will be entered in to capturing mode, that capturing mode is set as wallpaper, that means the user set camera as wallpaper, it is continuously in captured mode only. – Somanadh Jan 03 '14 at 10:10
  • similar to: https://play.google.com/store/apps/details?id=gfm.camera.packge&hl=en – Somanadh Jan 03 '14 at 10:16
0

You need to create a live wallpaper, with a WallpaperService. Then you'll need to have your service create its own rendering surface that it draws the camera preview into.

Eddy Talvala
  • 17,243
  • 2
  • 42
  • 47