【问题标题】:how to open another app in a tabhost / how to open a word doc within a tabhost of android?如何在 tabhost 中打开另一个应用程序/如何在 android 的 tabhost 中打开 word doc?
【发布时间】:2012-01-12 02:05:56
【问题描述】:

我一直在尝试创建一个可以在 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) "

【问题讨论】:

    标签: android android-tabhost doc


    【解决方案1】:

    您可以将此意图作为指定选项卡的内容传递。

    但您应该小心 - 可能有一些设备不需要打开 doc 文件的应用程序,或者可能有多个应用程序用于此目的。无论如何,最好使用Intent.createChooser() 方法进行此类操作。

    【讨论】:

    • 你能举个例子吗?因为我不确定你在说什么
    • 尝试这样做:... .setContent(Intent.createChooser(intent, "some string"));
    • 我试过了。但它不会出现在 tabhost 中,而是打开另一个应用程序并退出我的。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多