试图从我的应用程序在Xoom(Android 3.0)中打开Word文档,但得到“未知源”

问题描述:

我有一个word文档(后来我也会构建PDF文件,但现在要选择word文档)在我的文件夹“/mnt/sdcard/Download/baby_details.doc”中,我设置打开这个文档的应用程序类型是“application/msword”。试图从我的应用程序在Xoom(Android 3.0)中打开Word文档,但得到“未知源”

在我的Eclipse的logcat我是看如何在Word文档通过原生的Android活动开,我能看到的结果

Starting: Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/Download/per-general-business-letter.doc typ=application/msword flg=0x10000000 cmp=com.qo.android.moto/com.qo.android.quickoffice.QuickofficeDispatcher } from pid 24132 
Starting: Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/Download/per-general-business-letter.doc typ=application/msword flg=0x1 cmp=com.qo.android.moto/com.qo.android.quickword.Quickword } from pid 1591 
Start proc com.qo.android.moto:Quickword for activity com.qo.android.moto/com.qo.android.quickword.Quickword: pid=2452 uid=10010 gids={3003} 

所以我试图用

   Bundle bundle = new Bundle(); 
       bundle.putString("dat", "/mnt/sdcard/Download/baby_details.doc"); 
       bundle.putString("typ", "application/msword"); 
       Intent docClient = new Intent(Intent.ACTION_VIEW); 
       docClient.putExtras(bundle); 
       docClient.setClassName("com.qo.android.moto", "com.qo.android.quickword.Quickword"); 
       startActivityForResult(docClient, WORD_APP); 
打开该文档

但我得到一个未知的来源,我也试图改变setClassName到

docClient.setClassName("com.qo.android.moto", "com.qo.android.quickoffice.QuickofficeDispatcher"); 

,仍然获得同样的错误。

我想知道是否有人使用本机QuickOffice活动打开word/pdf/xls?

谢谢, 萨那。

不要将“dat”和“type”放在一个包中;使用Intent.setTypeintent.setData(或只使用intent.setDataAndType。并确保您使用的数据的URI匹配的是什么系统要求(file://)。

+0

它的工作!谢谢。 – Sana 2011-03-24 20:14:43

+2

不要硬编码“到/ mnt/SD卡',请使用android.os.Environment类来获取外部存储的正确路径。 – 2011-03-27 22:14:10