这在前面已经讨论过了,但我现在有一个具体的案例。我的应用程序打开一个特定于应用程序的文件类型(.gedstar),它实际上是一个SQLite数据库,通常作为带有pathPattern限定符的应用程序/八位位组数据流进行处理。这是我的意图定义:
<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,BTW)。到目前为止,我一直推荐使用Dropbox将文件从用户的PC传输到Android并启动我的应用程序,直到最近,这种方法一直运行得很好。然后,随着Dropbox V2.0应用程序的发布,它崩溃了,导致了关于没有针对此文件类型的应用程序的吐司消息。
使用Logcat捕获它,这是不起作用的意图,在我看来应该是这样:
I/ActivityManager( 97):正在启动活动: Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/Android/data/com.dropbox.android/files/scratch/GedStar%20Pro/Gordon.gedstar类型=应用程序/八位位流flg=0x10000003 (具有额外内容)}
奇怪的是,我可以使用Dropbox的浏览器界面下载相同的文件,然后转到浏览器的下载列表并成功启动它。以下是成功的意图:
I/ActivityManager( 97):正在启动活动: Intent { act=android.intent.action.VIEW dat=file:///mnt/sdcard/download/Gordon.gedstar typ=act=android.intent.action.VIEW/octet-stream flg=0x10000000 cmp=com.ghcssoftware.gedstar/.GedStar }
我看到的唯一区别是"flg“的值和"cmp=”的值,我认为这是因为ActivityManager找到了匹配的意图。有人能更完整地解释这一点吗?
发布于 2011-12-30 04:50:50
多亏了Dropbox的技术支持,事实证明我不是唯一一个有这个问题的人,原因是意图字符串中的"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“字符串前面有三个点的路径。我们的想法是包含多个意图,以覆盖尽可能多的点。丑陋,但现在它确实起作用了!
https://stackoverflow.com/questions/8668743
复制相似问题