Intent to read both .xls and xlsx files in Android?

被刻印的时光 ゝ 提交于 2021-02-11 15:15:49

问题


My intent picks .xls while

fileintent.setType("application/vnd.ms-excel");

Picks .xlsx while

fileintent.setType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

How to make both .xls and .xlsx selectable and readable? Appreciate help!


回答1:


For .xls and .xlsx extensions,

Mimetypes are clubbed.

Intent intent;
    
        String[] mimetypes =
                { "application/vnd.ms-excel", // .xls
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" // .xlsx
                       };

        intent = new Intent(Intent.ACTION_GET_CONTENT); // or use ACTION_OPEN_DOCUMENT
        intent.setType("*/*");
        intent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
        intent.addCategory(Intent.CATEGORY_OPENABLE);

For other extensions:

Check the following link, find the corresponding mimetype and include it in the above code.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types



来源:https://stackoverflow.com/questions/63482335/intent-to-read-both-xls-and-xlsx-files-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!