BupeChombaDerrick
Получите количество изображений в mediaStore перед запуском камеры
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();
}
В onActivityResult вызовите метод exitingCamera
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
switch(requestCode){
case CAPTURE_IMAGES_FROM_CAMERA:
exitingCamera();
return;
}
return;
}
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);
}
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;
}
Затем вновь добавленные изображения можно найти с помощью
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();
}