1
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);`

正如你在上面看到的代码是在我的安卓平板电脑上显示一个 MS ppt。

现在我的代码过程如下。

1.我会从一个 URL 下载一个 ppt 并将它存储在 sdcard 中。

2.然后我想在一个我不知道的视图中显示ppt,这完全适合这个。

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

那怎么办????

4

2 回答 2

0

为此使用 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);
于 2013-01-02T06:16:24.333 回答
0
    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-02T06:24:46.920 回答