Bonjour à toutes et à tous,

J'essaie d’enregistrer un fichier que je télécharge sur la toile en me basant sur cet exemple.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
        DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url))
                .setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN)// Visibility of the download Notification
//                .setDestinationUri(Uri.fromFile(fch))// Uri of the destination file
//                .setDestinationInExternalPublicDir("/storage/emulated/0", "/GPSNav/Marees/" + fileName)
                .setDestinationInExternalFilesDir(this, "/storage/emulated/0", "/GPSNav/Marees/" + fileName)
                .setTitle(fileName)// Title of the Download Notification
                .setDescription("Downloading")// Description of the Download Notification
                .setRequiresCharging(false)// Set if charging is required to begin the download
                .setAllowedOverMetered(true)// Set if download is allowed on Mobile network
                .setAllowedOverRoaming(true);// Set if download is allowed on roaming network
        DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
        downloadID = downloadManager.enqueue(request);// enqueue puts the download request in the queue.
Le problème est que, quelque soit la méthode employée, ligne 3 ou 4 ou 5 du code ci-dessus, j'ai une erreur sur le ligne choisie qui dit :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
    java.lang.IllegalStateException: Not one of standard directories: 
        at android.os.Parcel.createException(Parcel.java:2096)
        at android.os.Parcel.readException(Parcel.java:2056)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
        at android.content.ContentProviderProxy.call(ContentProviderNative.java:658)
        at android.content.ContentProviderClient.call(ContentProviderClient.java:558)
        at android.content.ContentProviderClient.call(ContentProviderClient.java:546)
        at android.app.DownloadManager$Request.setDestinationInExternalPublicDir(DownloadManager.java:761)
        at com.example.telechargement.MainActivity.beginDownload(MainActivity.java:79) // ici ligne 3 ou 4 ou 5
NOTA : le répertoire ou je souhaite enregistrer le fichier existe et est bien : /storage/emulated/0/GPSNav/Marees/

Je ne sais plus quoi faire ! Des idées ?

Cordialement.

Pierre.