Skip to content Skip to sidebar Skip to footer

Capture Image From Camera In Htc Desire Android Device Is Not Working?

i am doing a camera app which picks photo from camera i am working with the below code its working in samsung galaxy ace but in Htc Desire with Android OS 2.2 its not working,pleas

Solution 1:

if you are passing Uri of Image when starting Camera then get image as in onActivityResult :

@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data) { 
  super.onActivityResult(requestCode, resultCode, data); 

  if (CAMERA_PIC_REQUEST == resultCode) { 
     ImageViewiv= (ImageView) findViewById(R.id.ReturnedImageView); 

      // Decode it for real 
     BitmapFactory.OptionsbmpFactoryOptions=newBitmapFactory.Options();
                    bmpFactoryOptions.inJustDecodeBounds = false; 

     //imageFilePath image path which you pass with intent Bitmapbmp= BitmapFactory.decodeFile(cameraImageFile, bmpFactoryOptions); 

      // Display it 
     iv.setImageBitmap(bmp); 
     }    
   } 
} 

Solution 2:

Calendar currentDate = Calendar.getInstance();SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");String dateNow = formatter.format(currentDate.getTime());imageName = dateNow + ".jpg";//Create path to store image in SDCard path = Environment.getExternalStorageDirectory() + File.separator + imageName; startCameraActivity();

protected void startCameraActivity() { File file = new File(path); Uri outputFileUri = Uri.fromFile(file);Intent intent = new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTURE);intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);startActivityForResult(intent, Globals.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); }

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 100) {switch (resultCode) {case RESULT_CANCELED:Log.i("MakeMachine", "User cancelled");Toast.makeText(getBaseContext(), "User cancelled", Toast.LENGTH_LONG).show();break;case RESULT_OK:BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 4;Bitmap bitmap = BitmapFactory.decodeFile(path, options); image.setImageBitmap(bitmap); }

Solution 3:

Thanks to all.i solved the issue,i made a small change in my code i am creating file in the sd card using File myDirectory = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera/");

there is no folder named as DCIM/Camera in Htc just changed the line as below its working fine

File myDirectory = new File(Environment.getExternalStorageDirectory() + "/DCIM/");

Post a Comment for "Capture Image From Camera In Htc Desire Android Device Is Not Working?"