Gre*_*bin 5 android intentfilter
我正在尝试将我的应用与扩展相关联.我已阅读文档和一些 问题有关的问题.但主要的文件浏览器(如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>Run Code Online (Sandbox Code Playgroud)
如果我尝试使用下一个代码从我的应用程序打开文件一切正常(选择器未显示):
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);
}Run Code Online (Sandbox Code Playgroud)
如果我尝试使用OpenIntents文件管理器打开它一切正常 - 显示列表中有很多应用程序和我的应用程序的长选择器.
但是,如果我尝试用es文件浏览器或Rhythm文件浏览器打开它 - 显示他们的自定义选择器(打开为文本/图像/视频/音频).这不好.
如果我尝试用Astro打开它 - 它会打开OpenIntent的文件管理器.这也很糟糕.
这个问题有什么解决方案吗?这种行为谁错了?
感谢您的任何帮助.
这里的部分问题是人们包装共享意图的所有不同方式,例如,在 Android mime 标识符中解析为 text/plain 的文件。
我的方法是找出我想要的文件是什么 MIME 类型。然后我将清单过滤器设置为这些类型。我使用两个过滤器。第一个只是过滤我想要的哑剧。第二个是第一个加方案的副本。
然后我通过像您一样从应用程序发送共享来进行测试。当其中一个不起作用时,我会使用 toast 来查看我从 STREAM 中得到了什么,然后对其进行更改以适应。例如,如果我得到一个 OpenIntent STREAM,我必须删除
content://org.openintents.filemanager
Run Code Online (Sandbox Code Playgroud)
这给我留下了道路。大多数情况下,我只需要删除:
file://
Run Code Online (Sandbox Code Playgroud)
但它总是很重要,因为整个内容/Uri/意图方案是一个免费的集群什么的。
之后。我只是偶然发现了这一点:
Intent intent = getIntent();
String name = intent.getData().getPath();
Run Code Online (Sandbox Code Playgroud)
也许这对你有用。我自己很快就会尝试一下。
| 归档时间: |
|
| 查看次数: |
1453 次 |
| 最近记录: |