我将尽力为您翻译。这是与扩展名相关的应用程序关联问题。我已经阅读了文档和一些问题,但主要的文件浏览器(如 ES 文件浏览器、Astro、File Manager by Rhythm Software)无法打开我的文件。
我的
如果我尝试使用OpenIntents文件管理器打开它,一切正常-显示了长的选择器,有很多应用程序和我的应用程序在列表中。但是,如果我尝试使用ES文件浏览器或Rhythm文件浏览器打开它,则显示它们的自定义选择器(作为文本/图像/视频/音频打开)。这很糟糕。如果我尝试使用Astro打开它,则会打开OpenIntent的文件管理器。这也很糟糕。是否有解决问题的方法?在这种行为中,谁是错误的?感谢任何帮助。
我的
清单
文件:<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的文件管理器。这也很糟糕。是否有解决问题的方法?在这种行为中,谁是错误的?感谢任何帮助。