【问题标题】:Mime type for Google Drive when using Kitkat open document dialog (Storage Access Framework)使用 Kitkat 打开文档对话框时 Google Drive 的 Mime 类型(存储访问框架)
【发布时间】:2014-02-07 18:31:50
【问题描述】:

我正在使用 Android 的新文件选择器让用户打开我的文件。我正在尝试选择一个私钥文件(*.key,pem 格式):

    Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    [...]
    construct supportedMimeTypesArray as array with
    "application/x-pem-file"
    "application/pkcs8"
    [...]
    i.putExtra(Intent.EXTRA_MIME_TYPES, supportedMimeTypesArray);

这在从内部存储中选择文件时有效。但是当我尝试从 Google 打开文件时,Google 驱动器会将文件清空。

文件是使用浏览器上传的。

有什么方法可以显示 Google 驱动器认为文件是什么 mime 类型?

【问题讨论】:

    标签: android google-drive-api mime-types android-4.4-kitkat


    【解决方案1】:

    方法是请求具有“/”mime 类型的文件,然后显示返回的 URI 的元字段。事实证明,“.key”文件的 mime 类型为“application/x-iwork-keynote-sffkey”

    这里给出一个又快又脏的方法:

        @Override
        public void onActivityResult(int requestCode, int resultCode,
                                     Intent resultData) {
            if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
                Uri uri = null;
                if (resultData != null) {
                    uri = resultData.getData();
                    Log.i(TAG, "Uri: " + uri.toString());
    
                    Cursor c = getActivity().getContentResolver().query(uri, null, null, null, null);
                    try {
                        String r = "";
                        c.moveToFirst();
                        do {
                            for (int i = 0; i < c.getColumnCount(); i++) {
                                r += c.getColumnName(i) + "      " + c.getString(i) + "\n";
    
                            }
                            r += "\n";
                        } while (c.moveToNext());
                        mResultView.setText(r);
                    } finally {
                        c.close();
                    }
    
                }
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2014-09-30
      • 1970-01-01
      • 1970-01-01
      • 2015-07-18
      • 1970-01-01
      • 2013-02-03
      • 2015-12-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多