2014-05-19 6 views
1

J'ai téléchargé un fichier PDF dans mon application dans le chemin getFilesDir().getPath()Comment ouvrir un fichier PDF stocké dans le chemin

Lorsque je tente d'ouvrir le même fichier getFilesDir() getPath() en utilisant ci-dessous le code suivant:.

 String path = getBaseContext().getFilesDir().getPath()+"/myfile.pdf"; 
     File file = new File(path); 
     Intent intent = new Intent(Intent.ACTION_VIEW); 
     intent.setDataAndType(Uri.fromFile(file), "application/pdf"); 
     intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 
     startActivity(intent); 

Je reçois l'erreur The target file doesnot exist du lecteur pdf.

Lorsque je parcours mon périphérique pour le chemin myfile.pdf, il se trouve au "/sdcard/Android/data/com.***.***/files/data/com.***.***/files/myfile.pdf". Si je code en dur le chemin ci-dessus, j'obtiens aussi la même erreur.

Veuillez me faire savoir comment lire le fichier à partir de ce chemin.

Répondre

0

utilisation: Environment.getExternalStorageDirectory().getAbsolutePath()

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/myfile.pdf"); 
Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.fromFile(file), "application/pdf"); 
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 
startActivity(intent); 
+0

Merci pour votre aide mais Environment.getExternalStorageDirectory() getAbsolutePath() ne fonctionne pas dans mon cas.. – brig

Questions connexes