final Uri uri = Uri.fromFile(file);
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
PackageManager pm = getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
if(list.size() > 0)
startActivity(context, intent);`正如你在上面看到的,代码是在我的android平板电脑上显示一个MS ppt。
现在我的代码过程如下所示。
1.我将从URL下载ppt并将其存储在sdcard中。
2.然后我想在一个我认为完全适合的视图中显示ppt。
所以我不能显示ppt事实上我想不仅显示ppt而且在视图中显示doc/ppt/pdf/xls文件.....
那么该怎么做呢?
发布于 2013-01-02 14:24:47
Hi friend I fased Same problem
that time instead of specifing we can pick suitable application from list of Application ,
but below code is for example purpose only , not for 100% gurantee
depends on Requirement you have to change .
In ICS You have default polaris application you can use
else if (TEXT == type) {
File targetFile = new File(path);
Uri targetUri = Uri.fromFile(targetFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(targetUri, "text/plain");
startActivityForResult(intent, TEXT);
} else if (type == DOC) {
File targetFile = new File(path);
Uri targetUri = Uri.fromFile(targetFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(targetUri, "application/*");
startActivityForResult(intent, DOC);
} else if (type == EXCEL) {
File targetFile = new File(path);
Uri targetUri = Uri.fromFile(targetFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(targetUri, "application/*");
startActivityForResult(intent, EXCEL);
} else {
File targetFile = new File(path);
Uri targetUri = Uri.fromFile(targetFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(targetUri, "application/*");
startActivityForResult(intent, 0);
}发布于 2013-01-02 14:16:24
为此,请使用Webview。这对我很管用。
WebView mWebView = (WebView) findViewById( R.id.WebView01);
String pdfurl = ""; // Url of pdf or doc file.
String weblink="http://docs.google.com/gview?embedded=true&url="+pdfurl;
mWebView.loadUrl(weblink);https://stackoverflow.com/questions/14117621
复制相似问题