2011-12-29 28 views
3

這已在一般前面討論過,但我現在有一個特定的情況。我的應用程序打開一個特定應用程序特定的文件類型(.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發現了匹配意圖。任何人都可以更完整地解釋這個嗎

+0

另一個區別是'%20'。嘗試在DropBox中以不具有空格的方式下載文件。我沒有檢查DropBox外部存儲文件結構,但我猜測「GedStar Pro」是一個文件夾。 – CommonsWare 2011-12-29 15:05:54

+0

我已經消除了這個問題,但它原來是pathPattern的限制。請參閱下面的答案。 – gordonwd 2011-12-29 20:44:55

回答

6

感謝Dropbox的技術支持,事實證明,我不是唯一有這個問題的人,原因是Intent字符串中的「com.dropbox.android」,其中包含這些額外的點。結果發現pathPattern匹配不是「貪婪」,因此被規範中的第一個點破壞。如果用戶在目錄或文件名中有一個點,它也會中斷!該解決方案(?我們仍然用「雜牌」)是提供了一堆的意圖過濾器與pathPatterns如:

 <intent-filter> 
      <action android:name="android.intent.action.VIEW" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.BROWSABLE" /> 
      <category android:name="android.intent.category.ALTERNATIVE"/> 
      <data android:scheme="file" 
        android:mimeType="application/octet-stream" 
        android:pathPattern=".*\\..*\\..*\\..*\\.gedstar" 
        android:host="*" /> 
     </intent-filter> 

此相匹配的「.gedstar」字符串前三個點的路徑。這個想法將包括多個意圖以涵蓋儘可能多的點。醜陋,但它現在工作!

+0

您是否有任何特殊原因不僅僅使用您自己的供應商MIME類型? – CommonsWare 2011-12-29 20:57:10

+0

它實際上是一個SQLite數據庫文件,所以我不確定如何讓啓動活動(如Dropbox)將其識別爲特定的MIME類型。 – gordonwd 2011-12-30 17:29:21