2012-01-12 67 views
1

我一直在試圖創建一個應用程序,可以在tabhost的幫助下打開多個活動。其中一個支持是我想在我的應用程序中打開一個word文檔。如何在tabhost中打開另一個應用程序/如何在android的tabhost中打開word文檔?

我知道如何打開一個與其他應用程序,但我希望它可以在我的應用程序內打開,而不需要按返回按鈕返回到我的應用程序。

,我用它來打開Word文檔代碼:

File file = new File 
      (Environment.getExternalStorageDirectory(),"/MLT/student.doc"); 
Intent intent = new Intent(); 
intent.setAction(android.content.Intent.ACTION_VIEW); 
intent.setDataAndType(Uri.fromFile(file), "application/msword"); 
startActivity(intent); 

我試着將它添加到使用

File file = new File (Environment.getExternalStorageDirectory(),"/MLT/student.doc"); 
    intent = new Intent(); 
    intent.setAction(android.content.Intent.ACTION_VIEW); 
    intent.setDataAndType(Uri.fromFile(file), "application/msword"); 
    spec = tabHost.newTabSpec("Info").setIndicator("Info", 
         res.getDrawable(R.drawable.ic_tab_info)).setContent(intent); 
    tabHost.addTab(spec); 

我的標籤,但我得到運行時錯誤,與主

01-12 13:16:32.945: E/AndroidRuntime(10066): java.lang.SecurityException: Requesting code from com.infraware.polarisoffice (with uid 10053) to be run in process com.app.mlt (with uid 10128) " 
+0

所以,發生了什麼? – kosa 2012-01-12 02:36:57

回答

0

您可以將此意圖作爲指定標籤的內容傳遞。

但是你應該小心 - 可以有設備,不需要打開doc文件的應用程序,或者可以有幾個應用程序。任何方式最好使用Intent.createChooser()方法進行此類操作。

+0

你能舉個例子嗎?因爲我不知道你在說什麼 – Jovi 2012-01-12 05:27:36

+0

嘗試這樣做:... .setContent(Intent.createChooser(intent,「some string」)); – Jin35 2012-01-12 06:25:10

+0

我試過了。但不是在tabhost中出現,而是打開另一個應用程序並退出我的。 – Jovi 2012-01-13 03:39:43

0

我試過使用MIME應用程序/ msword類型它沒有工作,所以我用的應用程序/ vnd.ms字

+0

它不工作... – Jovi 2012-01-17 05:34:29

相關問題