【发布时间】:2012-06-14 08:21:37
【问题描述】:
我正在尝试将我的应用与扩展程序相关联。我已经阅读了documentation 和some questions 关于这个问题的内容。但是主要的文件浏览器(如es文件浏览器、astro、Rhythm软件的文件管理器)无法打开我的文件。
我的manifest 文件:
<activity android:name="com.comapping.android.map.MapActivity" android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.comap" android:mimeType="*/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="content" android:host="*" android:pathPattern=".*\\.comap" android:mimeType="*/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
如果我尝试使用下一个代码从我的应用程序中打开文件,一切正常(未显示选择器):
String extension = "";
int dotIndex = downloadedFile.lastIndexOf('.');
if (dotIndex != -1) {
extension = downloadedFile.substring(dotIndex + 1, downloadedFile.length());
}
// create an intent
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
Uri data = Uri.fromFile(new File(downloadedFile));
String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
if (type == null || type.length() == 0) {
// if there is no acceptable mime type
type = "application/octet-stream";
}
intent.setDataAndType(data, type);
// get the list of the activities which can open the file
List resolvers = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolvers.isEmpty()) {
(new AlertDialog.Builder(context)
.setMessage(R.string.AttachmentUnknownFileType)
.setNeutralButton(R.string.NeutralButtonText, null)
.create()).show();
} else {
context.startActivity(intent);
}
如果我尝试使用 OpenIntents 文件管理器打开它,一切正常 - 显示有很多应用程序的长选择器,我的应用程序在列表中。
但如果我尝试使用 es 文件资源管理器或 Rhythm 文件资源管理器打开它 - 显示他们的自定义选择器(以文本/图像/视频/音频打开)。这很糟糕。
如果我尝试用 Astro 打开它 - 它会打开 OpenIntent 的文件管理器。这也很糟糕。
这个问题有什么解决办法吗?这种行为谁错了?
感谢您的帮助。
【问题讨论】:
标签: android intentfilter