Bonjour à tous!
J'essaye sans succès de placer dans un répertoire de mon application, les photos prises par l'aplication native PHOTO de mon LG G4.
Pour cela j'utilise un intent à partir d'un drawer:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Intent prendrePhoto = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
 
            if (prendrePhoto.resolveActivity(getPackageManager()) != null)
                //prendrePhoto = null;
            try {
                photoFile = createImageFile();
                } catch (IOException ex) {// Error occurred while creating the File
            }
            if (photoFile != null) {
                photoURI = FileProvider.getUriForFile(this,
                        "com.x.x.fileprovider",
                        photoFile);
 
                prendrePhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                startActivityForResult(prendrePhoto, REQUEST_CAMERA);
            }
Voici mon FileProvider:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
 
    <external-path  name ="mes_images"  path = "Android/data/com.x.x/files/DCIM" />
</paths>
et dans mon Manifest
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.x.x.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
           <meta-data
               android:name="android.support.FILE_PROVIDER_PATHS"
               android:resource="@xml/provider_paths" />
 
        </provider>
La photo se prend bien, mais elle va dans la galerie et non dans mon application.
Voici ma classe createImageFile
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
private File createImageFile() throws IOException {
        Calendar c = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm", Locale.FRANCE);
        String dh = sdf.format(c.getTime());
        String fileName = "/Carnassier_Du_" + dh ;
        File storageDir = getExternalFilesDir(Environment.DIRECTORY_DCIM);
        File image = File.createTempFile(fileName,".jpg",storageDir);
        mCurrentPhotoPath = image.getAbsolutePath();
        return image;
    }
Et mon activityResult
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 protected void onActivityResult(int requestCode, int resultCode, Intent prendrePhoto) {
        super.onActivityResult(requestCode, resultCode, prendrePhoto);
 
        if (resultCode == Activity.RESULT_OK) {
            if (photoFile != null) {
                photoURI = FileProvider.getUriForFile(this,
                        "com.x.x.fileprovider",
                        photoFile);
 
                prendrePhoto.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
 
            }
        }
    }
photoFile est null . . .
Si un dev pouvait me dire ce qui ne convient pas . . .