Need Java Code snippet to take picture on ET1

// Expert user has replied.
T Thibaut David 3 years 6 months ago
29 2 0

What is wrong here ? (other Android Consumer smartphones can make it run properly) :
 
 
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE );
startActivityForResult(intent, CAMERA_PIC_REQUEST);
 
We receive the path of created image using following method:
 
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == CAMERA_PIC_REQUEST) {
    if (resultCode == RESULT_OK)
      try {
        Uri capturedImageUri = data.getData();
...
 
Returned Intent "data" on ET1 is "null".
 
Same results if picture’s destination path is hardcoded:
 
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE );

intent.putExtra(MediaStore.EXTRA_OUTPUT, customUri); 

startActivityForResult(intent, CAMERA_PIC_REQUEST);
 
Pointer to file under variable Uri "customUri" is created but remains empty.
Method onActivityResult always returns parameter data as "null".
 
thanks for guidance or source sample.
Thibaut

Please Register or Login to post a reply

2 Replies

T Thibaut David

Thanks Rob, this was hepful. Here are differences listed when we compare programming ET1 versus Smartphone

Sample that could work on smartphones (Xperia Ray) which does not work on  ET1 :
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE );
startActivityForResult(intent, CAMERA_PIC_REQUEST);

Works with ET1 :
File currentPhotoFile = GetCurrentPhotoFile();
mCurrentPhotoUri = Uri.fromFile(currentPhotoFile);

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE );
intent.putExtra(MediaStore.EXTRA_OUTPUT, mCurrentPhotoUri);
startActivityForResult(intent, CAMERA_PIC_REQUEST);

-----------------

Once result is captured, do not try retrieving the image path  using the intent. Use the path you have defined during the call ("intent.putExtra")

Sample which does not work on ET1 :
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
if (resultCode == RESULT_OK) {
try {
Uri capturedImageUri = data.getData();
new AsyncPreview(this).execute(capturedImageUri);
EnablePreview();
} catch (Exception e) {
e.printStackTrace();
}
}
else if(resultCode == RESULT_CANCELED)
            ...

Sample that works with ET1 :
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
if (resultCode == RESULT_OK)
try {
new AsyncPreview(this).execute(mCurrentPhotoUri);
EnablePreview();
} catch (Exception e) {
e.printStackTrace();
}
}
else if(resultCode == RESULT_CANCELED)
...

Two reminders for ET1  :
- Picture file is not automatically created (smartphones might use a DCIM folder as default), methods requires a destination path.
- File retrieved is not pointing to the path, the initial path should be kept in memory.

Thibaut

R Robert Galvin

Thibaut

See attached working sampe of a project.

Note:
Generally speaking, for native application development there are a ton of resources out on the internet. I do not see a reason why general Android examples would not work on the ET1. I would usually start with developer.android.com for most of these type of requests. Also if you install the Android SDK it does come with lots and lots of sample code that you can try.

http://developer.android.com/guide/topics/media/index.html
http://developer.android.com/guide/topics/media/camera.html
http://labs.makemachine.net/2010/03/simple-android-photo-capture/
http://developer.android.com/resources/samples/get.html
http://marakana.com/forums/android/examples/39.html

For the attached I found the app by just doing a simple google search and after a few minutes came across the following link:
http://labs.makemachine.net/2010/03/simple-android-photo-capture/

It has a walk through, but also has a sample project all zipped up. I unzipped the file and then in my Android Eclipse environment, did:
-File/ New Project
-Android Project
-From Existing Source and selected the folder where I unzipped it from.

With my ET1 attached I was able to run the project and see the application launch. There was one "bug" in the project in that it expected the folder "images' to exist onthe SD card. if it did not exists then the cam intent would never return. I modified the default save path to be the root of the SD card so that it will just run. There is no mention of the camera preview coming up, so I would have your developers walk through their code and comopare what is wrong.

It looks like they are using the INTENT method for using the camera, so it will use whatever application has hooked into the take picture intent. As a test they can also install another cam app to see if the "intent picker' comes up as well to select the app to use to satisfy the intent. I just used the Cam app that comes with the build as app to use.

Rob

CONTACT
Can’t find what you’re looking for?