這已在一般前面討論過,但我現在有一個特定的情況。我的應用程序打開一個特定應用程序特定的文件類型(.gedstar),它實際上是一個SQLite數據庫,通常作爲具有pathPattern限定符的application/octet-stream進行處理。這是我的意圖定義:Android的意圖文件類型失敗
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file"
android:mimeType="application/octet-stream"
android:pathPattern=".*\\.gedstar"
android:host="*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file"
android:mimeType="*/*"
android:pathPattern=".*\\.gedstar"
android:host="*" />
</intent-filter>
(我已經有和沒有通配mimeType,順便說一句)。到目前爲止,我一直在推薦使用Dropbox將文件從用戶的PC上傳輸到Android,並啓動我的應用程序,直到最近這一直都很順利。然後,隨着Dropbox V2.0應用程序的發佈,該應用程序崩潰,導致關於沒有該文件類型的應用程序的敬酒信息。
與logcat的誘捕它,這是不工作的意圖,這在我看來就像它應該:
I/ActivityManager(97):啓動活動:意向{行動= android.intent.action。 VIEW dat = file:///mnt/sdcard/Android/data/com.dropbox.android/files/scratch/GedStar%20Pro/Gordon.gedstar typ = application/octet-stream flg = 0x10000003(has extras)}
奇怪的是,我可以使用Dropbox的瀏覽器界面下載相同的文件,然後轉到瀏覽器的下載列表併成功啓動它。這裏是成功的意圖:
I/ActivityManager(97):開始活動:意圖{動作= android.intent.action.VIEW dat =文件:///mnt/sdcard/download/Gordon.gedstar typ =應用程序/ octet-stream flg = 0x10000000 cmp = com.ghcssoftware.gedstar/.GedStar}
我看到的唯一區別是我假設的「flg」和「cmp =」值的值是因爲ActivityManager發現了匹配意圖。任何人都可以更完整地解釋這個嗎
另一個區別是'%20'。嘗試在DropBox中以不具有空格的方式下載文件。我沒有檢查DropBox外部存儲文件結構,但我猜測「GedStar Pro」是一個文件夾。 – CommonsWare 2011-12-29 15:05:54
我已經消除了這個問題,但它原來是pathPattern的限制。請參閱下面的答案。 – gordonwd 2011-12-29 20:44:55