我无法显示ppt其实我不仅要显示ppt而且还要在视图中显示doc / ppt / pdf / xls文件.....在android中

时间:2013-01-02 06:11:49

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

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并将其存储在SD卡中。

2.然后我想在一个视图中显示ppt,我认为这完全适用于此。

所以Iam无法显示ppt infact我不仅要在视图中显示ppt而且还要显示doc / ppt / pdf / xls文件......

那怎么办?????

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分: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);
                }