1. Check out our companion app, Forums for Android! Download from Google Play

Sony Xperia S Camera Intent

Discussion in 'Application Development' started by Todilo, Oct 3, 2012.

  1. Todilo

    Todilo New Member
    Thread Starter

    Oct 3, 2012
    I am having problem with storing the image from a camera intent. After hours of testing I finally realised that the problem I had was due to the fact that it was Sony Xperia S I was working on as my HTC desire worked correctly.

    I want to take image, and then I want to retrieve it and conert it to byte array and sent it to a wcf.

    This is how I try to achieve the storing image part:
    Code (Text):
    1.  private File getCameraImageFile() {
    2.         String storageState = Environment.getExternalStorageState();
    3.         if (storageState.equals(Environment.MEDIA_MOUNTED)) {
    4.             String path = Environment.getExternalStorageDirectory() +
    5.                 "" + File.separatorChar + "download"+ ""+ File.separatorChar+""+ "mypicture.jpg";
    6.             File photoFile = new File(path);
    7.             try {
    8.                 if (!photoFile.exists()) {
    9.                     photoFile.getParentFile().mkdirs();
    10.                     photoFile.createNewFile();
    11.                 }
    12.             } catch (IOException e) {
    13.                 Log.e(TAG, "Could not create file.", e);
    14.             }
    15.             Log.i(TAG, "Got a file! " + path);
    16.             return photoFile;
    17.         } else {
    18.             Log.i(TAG, "External storage (SD card) is required. Current state: "
    19.                 + storageState);
    20.             // show some error dialog here
    21.             return null;
    22.         }
    23.     }
    26.     public void takePhoto(View view) {
    27.         Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    28.         File file = getCameraImageFile();
    29.         imageUri = Uri.fromFile(file);
    30.         cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
    31.         startActivityForResult(cameraIntent, 32);
    32.     }
    How can this be fixed so it can be used on Sony Xperia S, I figure it is because it has an internal memory, not an external device. I have tried using cachedir but then the intent fails with error-code 0. With this code it does not fail, but no image is stored to the download directory but its saved to the gallary.

    Solved: The problem was not in the storing of files, my windows explorer did not update the folders so I thought the files had not been saved. However! it was how I in the next step tried to grab the file, with File f = new File(imageUri.toString()); , this works on HTC Desire but not on Sony Xperia S!


Share This Page