如何在tabhost中打开另一个应用程序/如何在android的tabhost中打开word文档?

时间:2012-01-12 02:05:56

标签: android android-tabhost doc

我一直在尝试创建一个可以在tabhost的帮助下打开多个活动的应用程序。其中一个支持是我想在我的应用程序中打开一个word文档。

我知道如何用其他应用程序打开一个,但我希望它可以在我的应用程序中打开,而不是需要按回按钮返回我的应用程序。

我用来打开word doc的代码:

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) "

2 个答案:

答案 0 :(得分:0)

您可以将此意图作为指定标签的内容传递。

但是你应该小心 - 可能有设备,没有必要的应用程序打开doc文件,或者可以有几个应用程序。无论如何最好使用Intent.createChooser()方法进行此类操作。

答案 1 :(得分:0)

我尝试使用MIME应用程序/ msword类型它不起作用所以我使用了application / vnd.ms-word