What i am trying to do is create a new folder and save the image captured by camera in that folder.I am trying to achieve it using following snipet:
public class DocsAdd extends Activity
{
private static int TAKE_PICTURE = 1;
private Uri outputFileUri;
Bitmap thumbnail;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
File filename;
try
{
long currentTime = System.currentTimeMillis();
String fileName = "img" + currentTime+".jpg";
String path = Environment.getExternalStorageDirectory().toString();
filename = new File(path + "/AutoistDiary/"+ fileName);
FileOutputStream out = new FileOutputStream(filename);
out.flush();
out.close();
MediaStore.Images.Media.insertImage(getContentResolver(),filename.getAbsolutePath(), filename.getName(), filename.getName());
outputFileUri = Uri.fromFile(filename);
}
catch (Exception e)
{
e.printStackTrace();
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == TAKE_PICTURE)
{
Uri imageUri = null;
if (data!=null)
{
if (data.hasExtra("data"))
{
thumbnail = data.getParcelableExtra("data");
Intent docsShow_intent=new Intent(this,DocsShow.class);
startActivity(docsShow_intent);
}
}
else
{
}
}
}
}
but when i run it on Optimus1 it is not returning any result to my activity, came across a link Camera on Android Example which states the same problem that i am facing currently so can help me with this. ?
Unfortunately there is a bug on some devices causing the
Intend data
parameter inonActivityResult
to be null when you use theMediaStore.EXTRA_OUTPUT
flag in your intent for the camera. A workaround is to keep theoutputFileUri
variable global so that you can access it again in youronActivityResult
method. Something like this:This workaroud has worked for me. Hope that helps.