FileProvider - Ouvrir le Fichier dans le Répertoire de Téléchargement

Je ne peux pas ouvrir n'importe quel fichier à partir du Dossier de Téléchargement.

Je peux télécharger un fichier et l'enregistrer dans le Dossier de Téléchargement:

   DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
    request.setDescription(descricao);
    request.setTitle(titulo);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        request.allowScanningByMediaScanner();
        request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
    }
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, nome);

    enq = downloadManager.enqueue(request);

Après, mon fichier est correct enregistré au Répertoire du Dossier: Android >> Stockage Interne Partagé >> Télécharger.
***Ce chemin, je vois manuellement l'ouverture de l'appareil hd dans ubuntu. Comme l'image montre le chemin.
Android HD par ubuntu dossier - voir le chemin d'accès

Et j'essaie d'ouvrir ce fichier avec ceci:

downloadManager = (DownloadManager)getContext().getSystemService(DOWNLOAD_SERVICE);
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) {
long downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, 0);
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(enq);
Cursor c = downloadManager.query(query);
if(c.moveToFirst()) {
int columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS);
if(DownloadManager.STATUS_SUCCESSFUL == c.getInt(columnIndex)) {
String uriString = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
if (uriString.substring(0, 7).matches("file://")) {
uriString =  uriString.substring(7);
}
File file = new File(uriString);
Uri uriFile = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID + ".fileprovider", file);
String mimetype = "application/pdf";
Intent myIntent = new Intent(Intent.ACTION_VIEW);
myIntent.setDataAndType(uriFile, mimetype);
Intent intentChooser = Intent.createChooser(myIntent, "Choose Pdf Application");
startActivity(intentChooser);
}
}
}
}
};
getContext().registerReceiver(receiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

Je déclare mon fournisseur de fichier dans le manifeste:

    <provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>

et avec ceci:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="Download" path="Download/"/>
</paths>

Mais quand je clique sur le bouton pour télécharger je reçois ce message: "Ce fichier petit plus ponctuellement être pas accessible. Vérifiez l'emplacement ou le réseau et essayez de nouveau."

De reprise:

1 - Le fichier est téléchargé et enregistré dans le répertoire du dossier.

2 - L'intention est commencé, mais le fichier n'est pas ouvert.

3 - le mode de Débogage me donner à ce "nouveau Fichier(urlString)": "urlString=/storage/emulated/0/Download/nom.pdf"

4 - "FileProvider.getUriFromFile..." en mode debug avoir ceci:

"uriFile = content://com.exemple.android.parlamentaresapp.fileprovider/Download/nom.pdf"

Merci.

Android >> Internal Shared Storage >> Download.. Ce n'est pas un chemin du système de fichiers que vous pouvez utiliser dans votre code. Veuillez entrez le chemin d'accès complet.
voici l'exemple complet, étape par étape, dans android androidwave.com/capture-image-from-camera-gallery

OriginalL'auteur Sarara | 2017-03-29