【问题标题】:Iam not able to display the ppt infact i want to display not only ppt but also doc/ppt/pdf/xls files in a view..... in android我无法显示 ppt 事实上我想在视图中显示 ppt 和 doc/ppt/pdf/xls 文件.....在 android
【发布时间】:2013-01-02 06:11:49
【问题描述】:
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.我会从一个网址下载一个ppt并保存在sdcard中。

2.然后我想在我不知道的视图中显示 ppt 到底适合这个。

所以我无法显示 ppt 事实上我想在视图中显示 ppt 和 doc/ppt/pdf/xls 文件.....

那怎么办呢??????

【问题讨论】:

  • 你用的是哪个版本?

标签: android android-layout android-intent android-emulator android-widget


【解决方案1】:
    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);
                }

【讨论】:

    【解决方案2】:

    为此使用 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);
    

    【讨论】:

    • 谢谢你的回答兄弟,嘿,我还有一个问题,假设我使用 webview 打开一个 doc 文件,我有金山办公软件会帮助我打开和保存同一个 doc页面????
    • 如果你想用金山办公软件打开你的文件意味着你必须在那个意图中传递包名..然后你的文件就会用那个软件打开。
    猜你喜欢
    • 2011-01-31
    • 1970-01-01
    • 2020-04-23
    • 2021-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-18
    相关资源
    最近更新 更多