Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'am trying to capture multiple images using a native camera app. How do I get the paths to images captured using intent action "INTENT_ACTION_STILL_IMAGE_CAMERA"?

Any help will be appreciated.

BCD
Posted
Updated 5-Jun-18 0:00am

Get the number of images in the mediaStore before starting the camera

Java
public void startCameraActivity(){
    	
	   Cursor cursor = loadCursor();
	   
           //current images in mediaStore
	   image_count_before = cursor.getCount();
	   
	   cursor.close();
	   
    	Intent cameraIntent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
    	
	    List<ResolveInfo> activities = getPackageManager().queryIntentActivities(cameraIntent, 0);
	       
	    if(activities.size() > 0)
           startActivityForResult(cameraIntent,CAPTURE_IMAGES_FROM_CAMERA);
	    else
	    	Toast.makeText(this, getResources().getString(R.string.no_camera_app), Toast.LENGTH_SHORT).show();
    }


In onActivityResult call method exitingCamera

Java
@Override
 public void onActivityResult(int requestCode, int resultCode, Intent data){
       	
    	  switch(requestCode){
    	       	
    	  case CAPTURE_IMAGES_FROM_CAMERA:
    	       		
    	      exitingCamera();
    	       		
    	      return;
    	       	
    	  }
    
       	 return;
       }



Java
public Cursor loadCursor(){
	
    final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID };
	
	final String orderBy = MediaStore.Images.Media.DATE_ADDED;
	
	return getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns,null,null,orderBy);
}


Java
public String[] getImagePaths(Cursor cursor, int startPosition){
	
	int size = cursor.getCount() - startPosition;
	
	if(size <= 0) return null;
	
	String []paths = new String[size];
	
	int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
	  
     for (int i = startPosition; i < cursor.getCount(); i++) {
 	  
 	     cursor.moveToPosition(i);
 	
 	     paths[i - startPosition]= cursor.getString(dataColumnIndex);
     }
       
     return paths;
}


Then the newly added images can be found with

Java
private void exitingCamera(){
   		
   		Cursor cursor = loadCursor();
   		
                //get the paths to newly added images
   		String []paths = getImagePaths(cursor,image_count_before);
   		
                // process images		
   		process(paths);
   		
   		cursor.close();
   		
   	}
 
Share this answer
 
v2
Could you tell me please what process(paths) method does?
 
Share this answer
 
Comments
CHill60 5-Jun-18 9:28am    
Don't post questions as solutions to old posts. Use the "Have a Question or Comment?" link next to a post.
In this case I suspect process(paths) shows the OP where they would put any code that would use the path information as we don't know what the OP wants to do with them.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900