vendredi 22 mai 2015

Why image is saved in two path ?

The image is saved in two different path: 1) DCIM 2) PICTURE I want save the image only in the second path. The code in main class:

This function start when user press a specific button "capturing"

public void intentFoto(View view) {
    //Implicit intent
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    //There is an app thath handle the intent?
    if (intent.resolveActivity(getPackageManager()) != null) {

        File photoFile = null;
        try {
            //get file 
            photoFile = getOutputMediaFile();
        } catch (IOException e) {

            Toast.makeText(getApplicationContext(), "Nada de nada", Toast.LENGTH_LONG).show();
        }

        if (photoFile != null) {

            Toast.makeText(getApplicationContext(), Uri.fromFile(photoFile).getPath(), Toast.LENGTH_LONG).show();
            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
            //start capturing image
            startActivityForResult(intent, 100);
        }
    }

This function get new media file

private File getOutputMediaFile() throws IOException {
    File mediaFile = null;
    if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {

        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";
        File dir =new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),"MioAlbum");
        // dir exist?
        if (! dir.exists()){
            if (! dir.mkdirs()){
                Toast.makeText(getApplicationContext(), "Accesso sd non avvenuto", Toast.LENGTH_LONG).show();
                return null;
            }
        }

        //file for image
        mediaFile = new File(dir.getPath() + File.separator +
                "IMG_"+ timeStamp + ".jpg");

        //mediaFile = File.createTempFile(imageFileName, ".jpg", dir);
        pathfoto = mediaFile.getAbsolutePath();
    }

    else Toast.makeText(getApplicationContext(), "Accesso sd non avvenuto", Toast.LENGTH_LONG).show();


    return mediaFile;

}

I use this permission in the manifest:

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Aucun commentaire:

Enregistrer un commentaire