2

I create an app that sends intent to the camera app to take picture.

if (storageState.equals(Environment.MEDIA_MOUNTED)) {

        try {
            String name=  "pic"+new Date().getTime();
            File photoFile = File.createTempFile(name, ".jpg");
            Log.i(TAG, "created file:"+name+".jpg");
            mImageUri = Uri.fromFile(photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri);
            startActivityForResult(takePictureIntent, ActionCode.TAKE_PHOTO);

        } catch (IOException e) {
            Log.e(TAG, "Could not create file. ", e);
     }

}

When I take picture and press the "tick" OK button. It doesn't send any result to my app.

I found this error in the logcat.

07-22 17:56:30.289: E/iu.UploadsManager(5699): upload failed for ID=11 content_uri=content://media/external/images/media/5117 state=1 bytes_total=0,0%
07-22 17:56:30.289: E/iu.UploadsManager(5699): java.lang.IllegalArgumentException: Zero length file can't be uploaded
07-22 17:56:30.289: E/iu.UploadsManager(5699):  at com.google.android.apps.plus.iu.GDataUploader.upload(GDataUploader.java:95)
07-22 17:56:30.289: E/iu.UploadsManager(5699):  at com.google.android.apps.plus.iu.UploadsManager.doUpload(UploadsManager.java:819)
07-22 17:56:30.289: E/iu.UploadsManager(5699):  at com.google.android.apps.plus.iu.UploadsManager.access$1200(UploadsManager.java:54)
07-22 17:56:30.289: E/iu.UploadsManager(5699):  at com.google.android.apps.plus.iu.UploadsManager$UploadTask.performSyncInternal(UploadsManager.java:1390)
07-22 17:56:30.289: E/iu.UploadsManager(5699):  at com.google.android.apps.plus.iu.UploadsManager$AutoUploadTask.performSyncInternal(UploadsManager.java:1874)
07-22 17:56:30.289: E/iu.UploadsManager(5699):  at com.google.android.apps.plus.iu.UploadsManager$UploadTask.performSync(UploadsManager.java:1309)
07-22 17:56:30.289: E/iu.UploadsManager(5699):  at com.google.android.apps.plus.iu.InstantUploadSyncManager.performSyncInternal(InstantUploadSyncManager.java:545)
07-22 17:56:30.289: E/iu.UploadsManager(5699):  at com.google.android.apps.plus.iu.InstantUploadSyncManager.performSync(InstantUploadSyncManager.java:591)
07-22 17:56:30.289: E/iu.UploadsManager(5699):  at com.google.android.apps.plus.iu.InstantUploadSyncService$InstantUploadSyncAdapter.onPerformSync(InstantUploadSyncService.java:180)
07-22 17:56:30.289: E/iu.UploadsManager(5699):  at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:254)
kanitw
  • 874
  • 10
  • 19

4 Answers4

1

Just for reference (I happen to be having them open right now), here are some related ones here on SO:

They mostly find the cause to be problems saving the image file, or mistakes in onActivityResult.

Community
  • 1
  • 1
Sz.
  • 3,342
  • 1
  • 30
  • 43
0

The issue with your code is you are creating an invalid file name.

String name=  "pic"+new Date().getTime();

creates a file with name having : in it's name which makes it invalid, and camera cannot store image to return back to you.

Shardul
  • 27,760
  • 6
  • 37
  • 35
0

This may help people, as I have struggled for days trying to fix this problem.

I'm working on an inherited project, using Cordova with the latest Phonegap barcode scanner (now maintained by wildabeast on GitHub), and after fixing some Cordova version issues bringing the project from Cordova version 2 to 3.1.0, I still kept having the problem that the application wouldn't return after using the barcode scanner.

Using the window.onunload event, I found out that the application actually unloaded before the barcode scanner plugin launched. This turns out to be by design, and is caused by a developer option, which is called "Don't keep activities". DISABLE this option to "keep the activity" of running your app, and it will not close.

I'm not sure for which phones this option is turned on (Samsung Note II here, with Android 4.1.2) and if or how it can be bypassed, and I'm not sure how to develop my application where it does not rely on this option. Implementing the Scandit scanner plugin didn't fix the problem, it only improved the issue slightly but it was still a hit and miss. For now I'm sticking with the Phonegap plugin.

Hopefully this can help someone else!

Jacob Bruinsma
  • 1,087
  • 1
  • 10
  • 23
-1

Refer below code

    path = Environment.getExternalStorageDirectory() + "/"
            + filename;

    btnTakePhoto.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            File file = new File(path);
            Uri outputFileUri = Uri.fromFile(file);

            Intent intent = new Intent(
                    android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

            startActivityForResult(intent, TAKE_PICTURE);

        }
    });

And then

public void onActivityResult(int requestCode, int resultCode, Intent data) {

    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK && requestCode == TAKE_PICTURE) {

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 3;

        bitmap = BitmapFactory.decodeFile(path, options);
        // Fetch the image from give path.

        imageView.setImageBitmap(bitmap);

    }
 }
Nirali
  • 13,571
  • 6
  • 40
  • 53