Note that there are some explanatory texts on larger screens.

plurals
  1. POcapturing the image using android camera
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/10679571/calling-camera-from-an-activity-capturing-an-image-and-uploading-to-a-server">Calling camera from an activity, capturing an image and uploading to a server</a> </p> </blockquote> <p>i am very new to android, i am trying to capture the image after that i placed that image into image view,its working on emulator but in device it crashes it shows the message force close even it cannot open the camera activity.the following is my code. please help me how to solve this problem.thank you.</p> <pre><code>package com.gss.android; package com.gss.android; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import android.app.Activity; import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; public class Pictures extends Activity{ Button btnsave,btnnewpic; protected ImageView image; protected String _path; File sdImageMainDirectory; private static final int IMAGE_CAPTURE = 0; protected boolean _taken = true; private Uri imageUri; protected static final String PHOTO_TAKEN = "photo_taken"; private static final int CAMERA_PIC_REQUEST = 1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pictures); btnsave=(Button)findViewById(R.id.btnsave); btnnewpic=(Button)findViewById(R.id.btnnewpic); btnnewpic.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub startCameraActivity2(); } }); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { if ( requestCode == CAMERA_PIC_REQUEST){ if (resultCode == RESULT_OK){ switch (resultCode) { case 0: finish(); break; case -1: try { StoreImage(this, Uri.parse(data.toURI()), sdImageMainDirectory); Log.e("file path", "stiring file") ; } catch (Exception e) { e.printStackTrace(); } finish(); } } } else if ( requestCode == IMAGE_CAPTURE) { if (resultCode == RESULT_OK){ Log.d("ANDRO_CAMERA","Picture taken!!!"); ImageView image = (ImageView) findViewById(R.id.image); image.setImageURI(imageUri); } } } protected void startCameraActivity2() { Log.d("ANDRO_CAMERA", "Starting camera on the phone..."); String fileName = "testphoto.jpg"; ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, fileName); values.put(MediaStore.Images.Media.DESCRIPTION, "Image capture by camera"); values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); imageUri = getContentResolver().insert( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); startActivityForResult(intent, IMAGE_CAPTURE); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { if (savedInstanceState.getBoolean(Pictures.PHOTO_TAKEN)) { _taken = true; } } @Override protected void onSaveInstanceState(Bundle outState) { outState.putBoolean(Pictures.PHOTO_TAKEN, _taken); } public static void StoreImage(Context mContext, Uri imageLoc, File imageDir) { Bitmap bm = null; try { bm = MediaStore.Images.Media.getBitmap(mContext.getContentResolver(), imageLoc); FileOutputStream out = new FileOutputStream(imageDir); bm.compress(Bitmap.CompressFormat.JPEG, 100, out); Log.e("file dir",imageDir.toString()); bm.recycle(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload