【问题标题】:Intent filter for common file explorers通用文件浏览器的意图过滤器
【发布时间】:2012-06-14 08:21:37
【问题描述】:

我正在尝试将我的应用与扩展程序相关联。我已经阅读了documentationsome 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


    【解决方案1】:

    这里的部分问题在于人们包装共享意图的所有不同方式,例如,在 Android mime 标识符中解析为 text/plain 的文件。

    我的方法是找出我想要的文件是什么 mime 类型。然后我将清单过滤器设置为这些类型。我使用两个过滤器。第一个只是过滤我想要的哑剧。第二个是第一个加计划的副本。

    然后我通过像您所做的那样从应用程序发送共享来进行测试。当一个人不工作时,我会用烤面包来看看我为 STREAM 得到了什么,然后改变它以适应它。例如,如果我得到一个 OpenIntent STREAM,我必须删除

    content://org.openintents.filemanager
    

    这给我留下了路径。大多数情况下,我只需要删除:

    file://
    

    但它总是有些东西,因为整个内容/Uri/Intent 方案是一个免费的集群whatsit。

    稍后。我只是偶然发现了这个:

    Intent intent = getIntent();                
    String name = intent.getData().getPath();
    

    也许这对你有用。我很快就会自己尝试一下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多