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

當你看到上面的代碼是在我的android平板電腦上顯示MS PPT。Iam無法顯示PPT Infact我想要顯示的不僅是PPT,而且doc/ppt/pdf/xls文件在視圖中.....在Android中

現在我的代碼程序如下。

1.我將從URL下載一個ppt並將它存儲在SD卡中。

2.然後我想在視圖中顯示ppt,我認爲這恰恰適合於此。

所以蔭無法顯示PPT INFACT我想在一個視圖中顯示的不僅百分點,而且DOC/PPT/PDF/XLS文件.....

那麼該怎麼辦呢??? ??

+0

哪個版本UR使用? – sravan

+0

android 4.0 ICS我猜 –

回答

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); 
       } 
+0

感謝代碼兄弟做了上面的代碼爲你工作 –

+0

是的它爲我工作 – sravan

+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); 
+0

感謝您的答案兄弟,嘿,我有另一個問題,讓我們假設我打開一個文檔文件使用webview作爲你suggstd和我有金山辦公室將該軟件幫助我打開和保存相同的文檔頁???? –

+0

如果你想打開你的文件使用金山辦公室意味着你必須在該意圖傳遞包名稱..那麼你的文件將被打開使用該軟件。 – itsrajesh4uguys

+0

如果你是K答案接受,upvote它。 – itsrajesh4uguys

相關問題