Android:下载后打开PDF格式文件
2014-06-11 15:43
555 查看
File file = new File("/sdcard/example.pdf");
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
Toast.makeText(OpenPdf.this,
"No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
}
上面的可以正常打开的
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this,
"No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
http://blog.csdn.net/xiaojunhu/article/details/8814710 http://blog.csdn.net/ouyangtianhan/article/details/6975899
首先是下载,不再赘述。
然后定义打开pdf的Intent
[java] view
plaincopy
/**
* Get PDF file Intent
*/
public Intent getPdfFileIntent(String path){
Intent i = new Intent(Intent.ACTION_VIEW);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
Uri uri = Uri.fromFile(new File(path));
i.setDataAndType(uri, "application/pdf");
return i;
}
打开
[java] view
plaincopy
btnDownload.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//You need to open another thread to download file ,
//so that it cannot disturb the main UI thread.
final HttpDownloader loader = new HttpDownloader(getApplicationContext());
int result = loader.download("http://xxx.pdf", "Tian/", "t0.pdf");
Log.d("PDFActivity.java","Download result: "+result);
if(result == 0 || result == 1){ // Success,open it
Intent intent = getPdfFileIntent("/mnt/sdcard/Tian/t0.pdf");
startActivity(intent);
}
}
});
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
Toast.makeText(OpenPdf.this,
"No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
}
上面的可以正常打开的
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this,
"No Application Available to View PDF",
Toast.LENGTH_SHORT).show();
}
http://blog.csdn.net/xiaojunhu/article/details/8814710 http://blog.csdn.net/ouyangtianhan/article/details/6975899
首先是下载,不再赘述。
然后定义打开pdf的Intent
[java] view
plaincopy
/**
* Get PDF file Intent
*/
public Intent getPdfFileIntent(String path){
Intent i = new Intent(Intent.ACTION_VIEW);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
Uri uri = Uri.fromFile(new File(path));
i.setDataAndType(uri, "application/pdf");
return i;
}
打开
[java] view
plaincopy
btnDownload.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//You need to open another thread to download file ,
//so that it cannot disturb the main UI thread.
final HttpDownloader loader = new HttpDownloader(getApplicationContext());
int result = loader.download("http://xxx.pdf", "Tian/", "t0.pdf");
Log.d("PDFActivity.java","Download result: "+result);
if(result == 0 || result == 1){ // Success,open it
Intent intent = getPdfFileIntent("/mnt/sdcard/Tian/t0.pdf");
startActivity(intent);
}
}
});
相关文章推荐
- Android:下载后打开PDF格式文件
- Android:下载并打开PDF格式文件2----用指定的software
- Android下载并打开PDF文件
- springMVC以附件形式下载PDF文件(解决了下载后文件格式出错无法打开的问题)
- Android遍历获取Office格式(Word,Excel,PPT,PDF)的文件并打开
- 笔记-Android中打开各种格式的文件(apk、word、excel、ppt、pdf、音视频、图片等)
- Android中打开各种格式的文件(apk、word、excel、ppt、pdf、音视频、图片等)
- Android下载并打开PDF文件
- Android遍历获取Office格式(Word,Excel,PPT,PDF)的文件并打开
- 笔记-Android中打开各种格式的文件(apk、word、excel、ppt、pdf、音视频、图片等)
- Android遍历获取Office格式(Word,Excel,PPT,PDF)的文件并打开
- Android下载文件与实际文件大小不一致,打开失败
- android用于打开各种文件的intent,包括以下文件PDF,PPT,WORD,EXCEL,CHM,HTML,TEXT,AUDIO,VIDEO
- Android执行打开文件(PDF,PPT,WORD,EXCEL,CHM,HTML,TEXT,AUDIO,VIDEO)的总结
- Android 下载一个文件以及打开这个apk文件
- android下支持pdf、ppt等格式的下载
- 在线打开.PDF、.TXT等文件,.doc、.xls自动下载
- 下载(打开)PDF文件 代码
- android Intent打开各种类型文件(PDF,PPT,WORD,EXCEL,CHM,H...
- Tomcat 在IE中下载rar文件直接以乱码体式格式打开解决规划