Nel mio onCreate() faccio questo controllo:Visualizza PDF in Android
//
// check if we have a PDF viewer, else bad things happen
//
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("application/pdf");
List<ResolveInfo> intents = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (intents == null || intents.size() == 0) {
// display message then...
finish();
}
Sul mio HTC Desire, questo non restituire una partita, anche se ho visualizzatore PDF di Adobe. Una risposta a questa domanda android: open a pdf from my app using the built in pdf viewer menziona che Adobe potrebbe non avere intenzioni pubbliche, quindi il controllo sopra riportato non restituirà ovviamente nulla.
Qualcuno può verificare se si dovrebbe essere in grado di avviare Acrobat da un intent, o c'è qualche altro metodo o visualizzatore PDF da usare.
Il caso di effettivo utilizzo sta scaricando copie delle fatture e la loro memorizzazione su storage locale utilizzando il codice come ad esempio:
URL url = new URL(data);
InputStream myInput = url.openConnection().getInputStream();
FileOutputStream fos = openFileOutput(fname, Context.MODE_WORLD_READABLE);
// transfer bytes from the input file to the output file
byte[] buffer = new byte[8192];
int length;
while ((length = myInput.read(buffer)) > 0) {
fos.write(buffer, 0, length);
progressDialog.setProgress(i++);
}
fos.close();
e quindi per mostrare
// read from disk, and call intent
openFileInput(fname); // will throw FileNotFoundException
File dir = getFilesDir(); // where files are stored
File file = new File(dir, fname); // new file with our name
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file));
intent.setType("application/pdf");
startActivity(intent);
Grazie - buona idea – BJB