【问题标题】:Mime type for text files文本文件的 MIME 类型
【发布时间】:2015-01-07 18:37:53
【问题描述】:

当我在 kitkat 上使用意图 ACTION_GET_CONTENT 并使用 mime */* 时,UI 选择器甚至会显示本地存储和其他来源。当我使用 text/plain 时,它不显示本地存储,而只显示 Dropbox(这是我安装的应用程序)。用于显示本地存储的 mime 类型是什么?我可以使用*/*,但我不想显示照片或音频等来源,因为我只需要文本文件。

【问题讨论】:

    标签: android


    【解决方案1】:

    从 API 级别 19 开始,您可以使用 EXTRA_MIME_TYPES

     https://developer.android.com/reference/android/content/Intent.html#EXTRA_MIME_TYPES
    

    来自论坛的示例:

      private static final String[] ACCEPT_MIME_TYPES = {
            "application/x-pkcs12",
            "application/x-x509-ca-cert",
            "application/x-x509-user-cert",
            "application/x-x509-server-cert",
            "application/x-pem-file",
            "application/pkix-cert"
      };
    
    
      final Intent openIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
                openIntent.setType("*/*");
                openIntent.putExtra(Intent.EXTRA_MIME_TYPES, ACCEPT_MIME_TYPES);
    

    因此,如果您有幸为 API 19 构建,您只需弄清楚哪个 您需要列出的 mime 类型。

    【讨论】:

      【解决方案2】:

      解决方案:它仅适用于 API 19+ 的 三星 手机。

              Intent intent = new Intent();
              intent.setAction(Intent.ACTION_GET_CONTENT);
              intent.addCategory(Intent.CATEGORY_OPENABLE);
              intent.setType("application/vnd.foo.bar");
              intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{"application/x-zip", "application/vnd.foo.bar",
                      "application/octet-stream"});
              intent.setClassName("com.android.documentsui", "com.android.documentsui.DocumentsActivity");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-12-25
        • 1970-01-01
        • 2018-06-27
        • 2019-01-28
        • 2021-02-11
        • 1970-01-01
        • 2010-11-07
        • 2018-12-01
        相关资源
        最近更新 更多