首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我不能显示ppt事实上我想不仅显示ppt而且在视图中显示doc/ppt/pdf/xls文件.....在android中

我不能显示ppt事实上我想不仅显示ppt而且在视图中显示doc/ppt/pdf/xls文件.....在android中
EN

Stack Overflow用户
提问于 2013-01-02 14:11:49
回答 2查看 390关注 0票数 1
代码语言:javascript
复制
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文件.....

那么该怎么做呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-02 14:24:47

代码语言:javascript
复制
    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);
                }
票数 0
EN

Stack Overflow用户

发布于 2013-01-02 14:16:24

为此,请使用Webview。这对我很管用。

代码语言:javascript
复制
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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14117621

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档