Partage
  • Partager sur Facebook
  • Partager sur Twitter

[Android] Affichage d'un PDF 64

    31 octobre 2020 à 21:33:11

    Bonjour,

    J'essaie désespérément d'afficher un PDF qui est en base64 sur mon application.

    Je vois le lecteur de PDF qui s'ouvre et se referme immédiatement.

    Je pense à un soucis sur le path mais j'ai beau chercher je ne vois pas ...

    FileOutputStream fos = null;
                            try {
                                if (text.get(position).getDonnees() != null) {
                                    final File newFilePath = new File(ViePratiqueConseilActivity.this.getFilesDir(), text.get(position).getNom_fichier());
                                    fos = new FileOutputStream(newFilePath, false);
                                    //fos = new FileOutputStream(ViePratiqueConseilActivity.this.getApplicationContext().getPackageName());
    
                                    byte[] decodedPDF = android.util.Base64.decode(text.get(position).getDonnees(), android.util.Base64.DEFAULT);
                                    fos.write(decodedPDF);
                                    fos.flush();
                                    fos.close();
                                }
    
                            } catch (Exception e) {
                                e.printStackTrace();
                            } finally {
                                if (fos != null) {
                                    fos = null;
                                }
                            }
    
                            Uri path = FileProvider.getUriForFile(ViePratiqueConseilActivity.this, ViePratiqueConseilActivity.this.getPackageName(), new File(text.get(position).getNom_fichier()));
                            //Uri path = FileProvider.getUriForFile(ViePratiqueConseilActivity.this, ViePratiqueConseilActivity.this.getApplicationContext().getPackageName(), new File(text.get(position).getNom_fichier()));
    
                            Intent intent = new Intent(Intent.ACTION_VIEW);
                            intent.setDataAndType(path, "application/pdf");
                            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    
                            try {
                                startActivity(intent);
                            }
                            catch (ActivityNotFoundException e) {
                                Toast.makeText(ViePratiqueConseilActivity.this,
                                        "No Application Available to View PDF",
                                        Toast.LENGTH_SHORT).show();
                            }

    Merci pour votre aide

    • Partager sur Facebook
    • Partager sur Twitter

    [Android] Affichage d'un PDF 64

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown