Voila le code en question ( aucune erreur sous eclipse pourtant )
maListViewPerso2.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
HashMap<String, String> map = (HashMap<String, String>) maListViewPerso2.getItemAtPosition(position);
String nomFichierDansAsset = map.get("file");
String nomFichierTemp = "list1.pdf";
if (copyAssetToTempFile(nomFichierDansAsset, nomFichierTemp)) {
try {
String name = getFileStreamPath(nomFichierTemp).getAbsolutePath();
Uri uri = Uri.parse("file://" + name);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "application/pdf");
startActivity(intent);
} catch (ActivityNotFoundException e) {
// Cas d'erreur si pas de lecteur PDF installé
Log.d("xx", "Erreur affichage PDF", e);
}
}
}
});
maListViewPerso3.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
HashMap<String, String> map = (HashMap<String, String>) maListViewPerso3.getItemAtPosition(position);
String nomFichierDansAsset = map.get("file");
String nomFichierTemp = "list3";
if (copyAssetToTempFile(nomFichierDansAsset, nomFichierTemp)) {
try {
String name = getFileStreamPath(nomFichierTemp).getAbsolutePath();
Uri uri = Uri.parse("file://" + name);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "application/pdf");
startActivity(intent);
} catch (ActivityNotFoundException e) {
// Cas d'erreur si pas de lecteur PDF installé
Log.d("xx", "Erreur affichage PDF", e);
}
}
}
});
};
private boolean copyAssetToTempFile(String nomFichierAsset,
String nomFichierTemp) {
boolean result = true;
try {
byte[] buffer = new byte[512];
FileOutputStream fos = openFileOutput(nomFichierTemp, MODE_WORLD_READABLE);
InputStream is = getAssets().open(nomFichierAsset);
int bytesRead = is.read(buffer);
while (bytesRead > 0) {
fos.write(buffer, 0, bytesRead);
bytesRead = is.read(buffer);
}
fos.close();
is.close();
} catch (FileNotFoundException e) {
// Cas d'erreur de création de fichier
Log.d("xx", "Erreur creation fichier ", e);
result = false;
} catch (IOException e) {
// Cas d'erreur de lecture de fichier
Log.d("xx", "Erreur lecture fichier", e);
result = false;
}
return result;
}
}
Il vous faut le Logcat ?
Modifié par gogui63, 19 May 2012 - 21:54.








Retour en haut







