Reputation: 625
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
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