blankwall
blankwall

Reputation: 353

Android camera issues

Using the google developer tutorials and following them exactly and my app will just restart or completely shut down and not get the picture from the camera. I had the exact same code working about 30 minutes ago but now it wont work. All I did was try and implement a button. Any help is greatly appreciated.

HEre is my code. Its short and simple so hopefully someone can give some advice on where to go from here.

package com.example.camera;

import android.app.Activity;
 import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
 import android.os.Bundle;
 import android.provider.MediaStore;
 import android.widget.ImageView;

public class MainActivity extends Activity {
ImageView iv;
Bitmap bitmap;
private static final int actionCode = 100;
public static final int MEDIA_TYPE_IMAGE = 1;

@Override
 public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv=(ImageView)findViewById(R.id.imageView1);
dispatchTakePictureIntent(actionCode);
}



protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 handleSmallCameraPhoto(data);
 }

private void dispatchTakePictureIntent(int actionCode) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, actionCode);
    }

private void handleSmallCameraPhoto(Intent intent) {
    Bundle extras = intent.getExtras();
    bitmap = (Bitmap) extras.get("data");
   iv.setImageBitmap(bitmap);
}
     }

Upvotes: 0

Views: 531

Answers (1)

Girish Nair
Girish Nair

Reputation: 5216

Some times it does get messy to ask the android system to take images for you. I have a Camera Library Project you can use the library to take the picture sample is also provided. or you can go through the code to understand it

Upvotes: 1

Related Questions