Hi,
I have a simple task (simple in other platforms, not in Android :-( ):
take a photo and return its pathname to the caller.
I searched a lot the net and tried many variants to the code. I'm
aware of the "thumbnail image" bug and am trying to bypass it.
The following code works, but its somewhat dificult to get the photo:
the guy has to go to the media picker, click menu button, select
"camera capture", take the photo, click back, and finally select the
photo from the list. The good thing: the photo returned is BIG.
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent, TAKE_PHOTO);
protected void onActivityResult(int requestCode, int resultCode,
Intent data)
{
switch (requestCode)
{
case TAKE_PHOTO:
if (resultCode == RESULT_OK)
try
{
Uri uri = data.getData();
java.io.InputStream is =
getContentResolver().openInputStream(uri);
java.io.FileOutputStream os = new
java.io.FileOutputStream(targetPhotoName);
byte[] buf = new byte[4096];
int r;
while ((r = is.read(buf)) > 0)
os.write(buf,0,r);
is.close();
os.close();
Launcher4A.pictureTaken(0,null);
}
catch (Exception e)
{
String stack = Log.getStackTraceString(e);
AndroidUtils.debug(stack);
}
break;
}
I also saw a code that (in theory) would do exactly what i need:
sourcePhotoName = Environment.getExternalStorageDirectory() +
java.io.File.separator + "tmpPhoto.jpg";
targetPhotoName = s;
Intent i = new
Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Uri uri = Uri.fromFile(new java.io.File(sourcePhotoName));
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(i, TAKE_PHOTO);
protected void onActivityResult(int requestCode, int resultCode,
Intent data)
{
switch (requestCode)
{
case TAKE_PHOTO:
if (resultCode == RESULT_OK)
try
{
java.io.InputStream is = new
FileInputStream(sourcePhotoName);
java.io.FileOutputStream os = new
java.io.FileOutputStream(targetPhotoName);
byte[] buf = new byte[4096];
int r;
while ((r = is.read(buf)) > 0)
os.write(buf,0,r);
is.close();
os.close();
}
catch (Exception e)
{
String stack = Log.getStackTraceString(e);
AndroidUtils.debug(stack);
}
break;
}
}
It works (almost) as expected: the camera application is shown, and
after the photo is taken, the photo is returned to the application.
However, it has two problems:
1. If i pass a folder inside my application's directory, when i press
"done" button, the camera application does not return; it stays in the
same screen until i press cancel. Seems that the camera application
does not have permissions to write to my folder.
2. The image returned from this code is the SMALL IMAGE (THUMBNAIL).
So, i now have a code that works and return a big image, but is
somewhat burocratic to the guy to use (and also can lead to errors, if
he selects the wrong picture), and a code that does what i want but
returns a small picture.
I'm using a HTC G2 with Android 1.6, and i have to use it because 1.6
is the requirement for my system.
Ok, now the question: is there something i can do in code #2 to make
it return the big picture?
thanks and regards,
guich
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en