Weloo
Weloo

Reputation: 625

Take photo with android camera and set it as wallpaper

I'm new in android and working on an app that captures photo by camera and set it as wallpaper.Here's the code :

public class camera extends Activity implements  View.OnClickListener  {


private ImageButton imgb;
private ImageView imgv;
private Button b;
Intent i;
static int cameraData =0;
Bitmap bmp;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image);

    cleaning();
    InputStream is=getResources().openRawResource(R.drawable.ic_launcher);
    bmp=BitmapFactory.decodeStream(is);


}

private void cleaning() {
    imgb=(ImageButton) findViewById(R.id.imgbutt);
    imgv=(ImageView) findViewById(R.id.iv);
    b=(Button) findViewById(R.id.butt);
    imgb.setOnClickListener(this);
    b.setOnClickListener(this);


}

@Override
public void onClick(View arg0) {

    switch(arg0.getId()){
    case R.id.imgbutt:
    i=new Intent (android.provider.MediaStore.ACTION_IMAGE_CAPTURE);    
    startActivityForResult(i, cameraData);

        break;

    case R.id.butt :
        try {
            getApplicationContext().setWallpaper(bmp);
        } catch (IOException e) {
            e.printStackTrace();
        }


        break;




    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(resultCode==RESULT_OK){

    Bundle extras=data.getExtras();

    bmp=(Bitmap) extras.get("data");
    imgv.setImageBitmap(bmp);
}
}

}

The problem is every time I hit "take pic" button I get an error say: the application has stopped unexpectedly

Upvotes: 0

Views: 1226

Answers (2)

c_idle
c_idle

Reputation: 1554

Some tips from when I have to troubleshoot is just simply using logcat.

This guy explains it well. http://www.youtube.com/watch?v=lESZqCflB0o&feature=bf_next&list=SPE953C0B85B50AB62&lf=list_related

Skip to 1:25:30

He will start right there about logs.

Upvotes: 1

mmeyer
mmeyer

Reputation: 3608

We'd all like to help but you really need to capture some details about what the error is in order for anyone to be able to try.

Please read up on how to use logcat and then use it to capture the actual error thats happening.

Upvotes: 0

Related Questions