如何在tabhost中打开另一个应用程序/如何在android的tabhost中打开word文档?
我一直在尝试创建一个可以在 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) "
i've been trying to create an app that could open multiple activities with the help of the tabhost. one of the support is i would like to open a word document within my app.
i know how to open one with other app, but i hope it could be open within my app rather then having the need to press back button to return to my app.
the code that i use to open 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);
i tried to add it to my tab using
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);
but i get runtime error, with the main
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) "
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将此意图作为指定选项卡的内容传递。
但您应该小心 - 可能有一些设备不需要用于打开文档文件的应用程序,或者可能有多个用于打开文档文件的应用程序。无论如何,最好使用
Intent.createChooser()
方法进行此类操作。You can pass this intent as content of your specified tab.
But you should be careful - there can be devices, that does not necessary apps for opening doc files, or there can be several apps for this. Any way it is better to use
Intent.createChooser()
method for such operations.我尝试使用 MIME application/msword 类型,但它不起作用,所以我使用了 application/vnd.ms-word
I tried using the MIME application/msword type it didn't work so I used application/vnd.ms-word