[Android, 안드로이드] 인텐트 타입(setType) 설정시 사용되는 MIME 타입 정리 문서종류, 확장자별 MIME type
기본적으로 사용되는 MIME 타입
MIME 타입 | 설명 |
text/plain | 텍스트 파일을 위한 기본값 |
application/octet-stream | 다른 모든 경우를 위한 기본값 알려지지 않은 파일 타입은 이 타입을 사용 |
[샘플코드]
private void restoreDB(){
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/plain");
//intent.setType("application/pdf");
//intent.setType("application/*");
//intent.setType("application/octet-stream");
//intent.setType("image/*");
//intent.setType("audio/*");
//intent.setType("application/x-excel");
startActivityForResult(intent, 1212);
}
private void restoreDB(){
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
//여러개의 MIME를 설정하고자 할 경우
String[] mimeTypes = { "text/csv", "text/plain" ,"application/pdf","image/*"};
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
startActivityForResult(intent, 1212);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.i("TAG", "########### resultCode : " + resultCode + " requestCode : " + requestCode);
boolean isCopySuccess = false;
if (resultCode == Activity.RESULT_OK && requestCode == 1212) {
if (data != null) {
Uri uri = data.getData();
if (uri != null)
Log.e("TAG", "########### uri : " + uri.toString());
String returnFilename = getFileNameFromUri(uri, SettingActivity.this);
if (returnFilename.equals(BAK_FILE_NAME)) {
//파일에 쓰기
//File file = new File(String.valueOf(uri));
//File backupDB = new File(uri.getPath());
//덮어쓰기할 대상 혹은 파일 쓰기할 위치
ContextWrapper cw = new ContextWrapper(SettingActivity.this);
File targetDir = cw.getDir(BACKUP_PATH, Context.MODE_PRIVATE); //앱의 내부 저장소
File targetFile = new File(targetDir, BAK_FILE_NAME);
InputStream inputStream = null;
OutputStream outputStream = null;
int DEFAULT_BUFFER_SIZE = 1024 * 4; //파일 용량이 크다면 늘려줘요
try {
inputStream = getContentResolver().openInputStream(uri);
outputStream = new FileOutputStream(targetFile);//dst
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
//byte[] buffer = IOUtils.toByteArray(inputStream);
//byte[] buf = inputStream.readAllBytes(); //java 9
//byte[] byteArray = inputStream.toByteArray();
int len;
while ((len = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, len);
}
outputStream.close();
inputStream.close();
isCopySuccess = true;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (isCopySuccess) {
execRealrestoreDB();
}
}else{
callGuideDialogNoneTimer(getResources().getString(R.string.tet_1));
}
}
}
}
파일 확장자 | 문서 종류 | MIME 타입 |
.aac | AAC 오디오 파일 | audio/aac |
.abw | AbiWord 문서 | application/x-abiword |
.arc | 아카이브 문서 (인코딩된 다중 파일) | application/octet-stream |
.avi | AVI: Audio Video Interleave | video/x-msvideo |
.azw | 아마존 킨들 전자책 포맷 | application/vnd.amazon.ebook |
.bin | 모든 종류의 이진 데이터 | application/octet-stream |
.bz | BZip 아카이브 | application/x-bzip |
.bz2 | BZip2 아카이브 | application/x-bzip2 |
.csh | C-Shell 스크립트 | application/x-csh |
.css | Cascading Style Sheets (CSS) | text/css |
.csv | Comma-separated values (CSV) | text/csv |
.doc | Microsoft Word | application/msword |
.epub | Electronic publication (EPUB) | application/epub+zip |
.gif | Graphics Interchange Format (GIF) | image/gif |
.htm .html |
HyperText Markup Language (HTML) | text/html |
.ico | Icon 포맷 | image/x-icon |
.ics | iCalendar 포맷 | text/calendar |
.jar | Java 아카이브 (JAR) | application/java-archive |
.jpeg .jpg |
JPEG 이미지 | image/jpeg |
.js | JavaScript (ECMAScript) | application/js |
.json | JSON 포맷 | application/json |
.mid .midi |
Musical Instrument Digital Interface (MIDI) | audio/midi |
.mpeg | MPEG 비디오 | video/mpeg |
.mpkg | Apple Installer Package | application/vnd.apple.installer+xml |
.odp | OpenDocuemnt 프리젠테이션 문서 | application/vnd.oasis.opendocument.presentation |
.ods | OpenDocuemnt 스프레드시트 문서 | application/vnd.oasis.opendocument.spreadsheet |
.odt | OpenDocument 텍스트 문서 | application/vnd.oasis.opendocument.text |
.oga | OGG 오디오 | audio/ogg |
.ogv | OGG 비디오 | video/ogg |
.ogx | OGG | application/ogg |
Adobe Portable Document Format (PDF) | application/pdf | |
.ppt | Microsoft PowerPoint | application/vnd.ms-powerpoint |
.rar | RAR 아카이브 | application/x-rar-compressed |
.rtf | Rich Text Format (RTF) | application/rtf |
.sh | Bourne 쉘 스크립트 | application/x-sh |
.svg | Scalable Vector Graphics (SVG) | image/svg+xml |
.swf | Small web format (SWF) 혹은 Adobe Flash document | application/x-shockwave-flash |
.tar | Tape Archive (TAR) | application/x-tar |
.tif .tiff |
Tagged Image File Format (TIFF) | image/tiff |
.ttf | TrueType Font | application/x-font-ttf |
.vsd | Microsft Visio | application/vnd.visio |
.wav | Waveform Audio Format | audio/x-wav |
.weba | WEBM 오디오 | audio/webm |
.webm | WEBM 비디오 | video/webm |
.webp | WEBP 이미지 | image/webp |
.woff | Web Open Font Format (WOFF) | application/x-font-woff |
.xhtml | XHTML | application/xhtml+xml |
.xls | Microsoft Excel | application/vnd.ms-excel |
.xml | XML | application/xml |
.xul | XUL | application/vnd.mozilla.xul+xml |
.zip | ZIP archive | application/zip |
.3gp | 3GPP 오디오/비디오 컨테이너 | video/3gpp audio/3gpp if it doesn’t contain video |
.3g2 | 3GPP2 오디오/비디오 컨테이너 | video/3gpp2 audio/3gpp2 if it doesn’t contain video |
.7z | 7-zip 아카이브 | application/x-7z-compressed |
IANA 공식 MIME 미디어 타입(Media Types)
https://www.iana.org/assignments/media-types/media-types.xhtml
MimeUtils.class |
“application/andrew-inset”, “ez”); “application/dsptype”, “tsp”); “application/futuresplash”, “spl”); “application/hta”, “hta”); “application/mac-binhex40”, “hqx”); “application/mac-compactpro”, “cpt”); “application/mathematica”, “nb”); “application/msaccess”, “mdb”); “application/oda”, “oda”); “application/ogg”, “ogg”); “application/pdf”, “pdf”); “application/pgp-keys”, “key”); “application/pgp-signature”, “pgp”); “application/pics-rules”, “prf”); “application/pkix-cert”, “cer”); “application/rar”, “rar”); “application/rdf+xml”, “rdf”); “application/rss+xml”, “rss”); “application/zip”, “zip”); “application/vnd.android.package-archive”, “apk”); “application/vnd.cinderella”, “cdy”); “application/vnd.ms-pki.stl”, “stl”); “application/vnd.oasis.opendocument.database”, “odb”); “application/vnd.oasis.opendocument.formula”, “odf”); “application/vnd.oasis.opendocument.graphics”, “odg”); “application/vnd.oasis.opendocument.graphics-template”, “otg”); “application/vnd.oasis.opendocument.image”, “odi”); “application/vnd.oasis.opendocument.spreadsheet”, “ods”); “application/vnd.oasis.opendocument.spreadsheet-template”, “ots”); “application/vnd.oasis.opendocument.text”, “odt”); “application/vnd.oasis.opendocument.text-master”, “odm”); “application/vnd.oasis.opendocument.text-template”, “ott”); “application/vnd.oasis.opendocument.text-web”, “oth”); “application/vnd.google-earth.kml+xml”, “kml”); “application/vnd.google-earth.kmz”, “kmz”); “application/msword”, “doc”); “application/msword”, “dot”); “application/vnd.openxmlformats-officedocument.wordprocessingml.document”, “docx”); “application/vnd.openxmlformats-officedocument.wordprocessingml.template”, “dotx”); “application/vnd.ms-excel”, “xls”); “application/vnd.ms-excel”, “xlt”); “application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”, “xlsx”); “application/vnd.openxmlformats-officedocument.spreadsheetml.template”, “xltx”); “application/vnd.ms-powerpoint”, “ppt”); “application/vnd.ms-powerpoint”, “pot”); “application/vnd.ms-powerpoint”, “pps”); “application/vnd.openxmlformats-officedocument.presentationml.presentation”, “pptx”); “application/vnd.openxmlformats-officedocument.presentationml.template”, “potx”); “application/vnd.openxmlformats-officedocument.presentationml.slideshow”, “ppsx”); “application/vnd.rim.cod”, “cod”); “application/vnd.smaf”, “mmf”); “application/vnd.stardivision.calc”, “sdc”); “application/vnd.stardivision.draw”, “sda”); “application/vnd.stardivision.impress”, “sdd”); “application/vnd.stardivision.impress”, “sdp”); “application/vnd.stardivision.math”, “smf”); “application/vnd.stardivision.writer”, “sdw”); “application/vnd.stardivision.writer”, “vor”); “application/vnd.stardivision.writer-global”, “sgl”); “application/vnd.sun.xml.calc”, “sxc”); “application/vnd.sun.xml.calc.template”, “stc”); “application/vnd.sun.xml.draw”, “sxd”); “application/vnd.sun.xml.draw.template”, “std”); “application/vnd.sun.xml.impress”, “sxi”); “application/vnd.sun.xml.impress.template”, “sti”); “application/vnd.sun.xml.math”, “sxm”); “application/vnd.sun.xml.writer”, “sxw”); “application/vnd.sun.xml.writer.global”, “sxg”); “application/vnd.sun.xml.writer.template”, “stw”); “application/vnd.visio”, “vsd”); “application/x-abiword”, “abw”); “application/x-apple-diskimage”, “dmg”); “application/x-bcpio”, “bcpio”); “application/x-bittorrent”, “torrent”); “application/x-cdf”, “cdf”); “application/x-cdlink”, “vcd”); “application/x-chess-pgn”, “pgn”); “application/x-cpio”, “cpio”); “application/x-debian-package”, “deb”); “application/x-debian-package”, “udeb”); “application/x-director”, “dcr”); “application/x-director”, “dir”); “application/x-director”, “dxr”); “application/x-dms”, “dms”); “application/x-doom”, “wad”); “application/x-dvi”, “dvi”); “application/x-flac”, “flac”); “application/x-font”, “pfa”); “application/x-font”, “pfb”); “application/x-font”, “gsf”); “application/x-font”, “pcf”); “application/x-font”, “pcf.Z”); “application/x-freemind”, “mm”); “application/x-futuresplash”, “spl”); “application/x-gnumeric”, “gnumeric”); “application/x-go-sgf”, “sgf”); “application/x-graphing-calculator”, “gcf”); “application/x-gtar”, “tgz”); “application/x-gtar”, “gtar”); “application/x-gtar”, “taz”); “application/x-hdf”, “hdf”); “application/x-ica”, “ica”); “application/x-internet-signup”, “ins”); “application/x-internet-signup”, “isp”); “application/x-iphone”, “iii”); “application/x-iso9660-image”, “iso”); “application/x-jmol”, “jmz”); “application/x-kchart”, “chrt”); “application/x-killustrator”, “kil”); “application/x-koan”, “skp”); “application/x-koan”, “skd”); “application/x-koan”, “skt”); “application/x-koan”, “skm”); “application/x-kpresenter”, “kpr”); “application/x-kpresenter”, “kpt”); “application/x-kspread”, “ksp”); “application/x-kword”, “kwd”); “application/x-kword”, “kwt”); “application/x-latex”, “latex”); “application/x-lha”, “lha”); “application/x-lzh”, “lzh”); “application/x-lzx”, “lzx”); “application/x-maker”, “frm”); “application/x-maker”, “maker”); “application/x-maker”, “frame”); “application/x-maker”, “fb”); “application/x-maker”, “book”); “application/x-maker”, “fbdoc”); “application/x-mif”, “mif”); “application/x-ms-wmd”, “wmd”); “application/x-ms-wmz”, “wmz”); “application/x-msi”, “msi”); “application/x-ns-proxy-autoconfig”, “pac”); “application/x-nwc”, “nwc”); “application/x-object”, “o”); “application/x-oz-application”, “oza”); “application/x-pem-file”, “pem”); “application/x-pkcs12”, “p12”); “application/x-pkcs12”, “pfx”); “application/x-pkcs7-certreqresp”, “p7r”); “application/x-pkcs7-crl”, “crl”); “application/x-quicktimeplayer”, “qtl”); “application/x-shar”, “shar”); “application/x-shockwave-flash”, “swf”); “application/x-stuffit”, “sit”); “application/x-sv4cpio”, “sv4cpio”); “application/x-sv4crc”, “sv4crc”); “application/x-tar”, “tar”); “application/x-texinfo”, “texinfo”); “application/x-texinfo”, “texi”); “application/x-troff”, “t”); “application/x-troff”, “roff”); “application/x-troff-man”, “man”); “application/x-ustar”, “ustar”); “application/x-wais-source”, “src”); “application/x-wingz”, “wz”); “application/x-webarchive”, “webarchive”); “application/x-webarchive-xml”, “webarchivexml”); “application/x-x509-ca-cert”, “crt”); “application/x-x509-user-cert”, “crt”); “application/x-x509-server-cert”, “crt”); “application/x-xcf”, “xcf”); “application/x-xfig”, “fig”); “application/xhtml+xml”, “xhtml”); “audio/3gpp”, “3gpp”); “audio/amr”, “amr”); “audio/basic”, “snd”); “audio/midi”, “mid”); “audio/midi”, “midi”); “audio/midi”, “kar”); “audio/midi”, “xmf”); “audio/mobile-xmf”, “mxmf”); “audio/mpeg”, “mp3”); “audio/mpeg”, “mpga”); “audio/mpeg”, “mpega”); “audio/mpeg”, “mp2”); “audio/mpeg”, “m4a”); “audio/mpegurl”, “m3u”); “audio/prs.sid”, “sid”); “audio/x-aiff”, “aif”); “audio/x-aiff”, “aiff”); “audio/x-aiff”, “aifc”); “audio/x-gsm”, “gsm”); “audio/x-mpegurl”, “m3u”); “audio/x-ms-wma”, “wma”); “audio/x-ms-wax”, “wax”); “audio/x-pn-realaudio”, “ra”); “audio/x-pn-realaudio”, “rm”); “audio/x-pn-realaudio”, “ram”); “audio/x-realaudio”, “ra”); “audio/x-scpls”, “pls”); “audio/x-sd2”, “sd2”); “audio/x-wav”, “wav”); “image/bmp”, “bmp”); “image/gif”, “gif”); “image/ico”, “cur”); “image/ico”, “ico”); “image/ief”, “ief”); “image/jpeg”, “jpeg”); “image/jpeg”, “jpg”); “image/jpeg”, “jpe”); “image/pcx”, “pcx”); “image/png”, “png”); “image/svg+xml”, “svg”); “image/svg+xml”, “svgz”); “image/tiff”, “tiff”); “image/tiff”, “tif”); “image/vnd.djvu”, “djvu”); “image/vnd.djvu”, “djv”); “image/vnd.wap.wbmp”, “wbmp”); “image/x-cmu-raster”, “ras”); “image/x-coreldraw”, “cdr”); “image/x-coreldrawpattern”, “pat”); “image/x-coreldrawtemplate”, “cdt”); “image/x-corelphotopaint”, “cpt”); “image/x-icon”, “ico”); “image/x-jg”, “art”); “image/x-jng”, “jng”); “image/x-ms-bmp”, “bmp”); “image/x-photoshop”, “psd”); “image/x-portable-anymap”, “pnm”); “image/x-portable-bitmap”, “pbm”); “image/x-portable-graymap”, “pgm”); “image/x-portable-pixmap”, “ppm”); “image/x-rgb”, “rgb”); “image/x-xbitmap”, “xbm”); “image/x-xpixmap”, “xpm”); “image/x-xwindowdump”, “xwd”); “model/iges”, “igs”); “model/iges”, “iges”); “model/mesh”, “msh”); “model/mesh”, “mesh”); “model/mesh”, “silo”); “text/calendar”, “ics”); “text/calendar”, “icz”); “text/comma-separated-values”, “csv”); “text/css”, “css”); “text/html”, “htm”); “text/html”, “html”); “text/h323”, “323”); “text/iuls”, “uls”); “text/mathml”, “mml”); “text/plain”, “txt”); “text/plain”, “asc”); “text/plain”, “text”); “text/plain”, “diff”); “text/plain”, “po”); // reserve “pot” for vnd.ms-powerpoint “text/richtext”, “rtx”); “text/rtf”, “rtf”); “text/texmacs”, “ts”); “text/text”, “phps”); “text/tab-separated-values”, “tsv”); “text/xml”, “xml”); “text/x-bibtex”, “bib”); “text/x-boo”, “boo”); “text/x-c++hdr”, “hpp”); “text/x-c++hdr”, “h++”); “text/x-c++hdr”, “hxx”); “text/x-c++hdr”, “hh”); “text/x-c++src”, “cpp”); “text/x-c++src”, “c++”); “text/x-c++src”, “cc”); “text/x-c++src”, “cxx”); “text/x-chdr”, “h”); “text/x-component”, “htc”); “text/x-csh”, “csh”); “text/x-csrc”, “c”); “text/x-dsrc”, “d”); “text/x-haskell”, “hs”); “text/x-java”, “java”); “text/x-literate-haskell”, “lhs”); “text/x-moc”, “moc”); “text/x-pascal”, “p”); “text/x-pascal”, “pas”); “text/x-pcs-gcd”, “gcd”); “text/x-setext”, “etx”); “text/x-tcl”, “tcl”); “text/x-tex”, “tex”); “text/x-tex”, “ltx”); “text/x-tex”, “sty”); “text/x-tex”, “cls”); “text/x-vcalendar”, “vcs”); “text/x-vcard”, “vcf”); “video/3gpp”, “3gpp”); “video/3gpp”, “3gp”); “video/3gpp”, “3g2”); “video/dl”, “dl”); “video/dv”, “dif”); “video/dv”, “dv”); “video/fli”, “fli”); “video/m4v”, “m4v”); “video/mpeg”, “mpeg”); “video/mpeg”, “mpg”); “video/mpeg”, “mpe”); “video/mp4”, “mp4”); “video/mpeg”, “VOB”); “video/quicktime”, “qt”); “video/quicktime”, “mov”); “video/vnd.mpegurl”, “mxu”); “video/x-la-asf”, “lsf”); “video/x-la-asf”, “lsx”); “video/x-mng”, “mng”); “video/x-ms-asf”, “asf”); “video/x-ms-asf”, “asx”); “video/x-ms-wm”, “wm”); “video/x-ms-wmv”, “wmv”); “video/x-ms-wmx”, “wmx”); “video/x-ms-wvx”, “wvx”); “video/x-msvideo”, “avi”); “video/x-sgi-movie”, “movie”); “video/x-webex”, “wrf”); “x-conference/x-cooltalk”, “ice”); “x-epoc/x-sisx-app”, “sisx”); |
MdeilFile.class |
addFileType(“MP3”, FILE_TYPE_MP3, “audio/mpeg”, MtpConstants.FORMAT_MP3); addFileType(“MPGA”, FILE_TYPE_MP3, “audio/mpeg”, MtpConstants.FORMAT_MP3); addFileType(“M4A”, FILE_TYPE_M4A, “audio/mp4”, MtpConstants.FORMAT_MPEG); addFileType(“WAV”, FILE_TYPE_WAV, “audio/x-wav”, MtpConstants.FORMAT_WAV); addFileType(“AMR”, FILE_TYPE_AMR, “audio/amr”); addFileType(“AWB”, FILE_TYPE_AWB, “audio/amr-wb”); if (isWMAEnabled()) { addFileType(“WMA”, FILE_TYPE_WMA, “audio/x-ms-wma”, MtpConstants.FORMAT_WMA); } addFileType(“OGG”, FILE_TYPE_OGG, “audio/ogg”, MtpConstants.FORMAT_OGG); addFileType(“OGG”, FILE_TYPE_OGG, “application/ogg”, MtpConstants.FORMAT_OGG); addFileType(“OGA”, FILE_TYPE_OGG, “application/ogg”, MtpConstants.FORMAT_OGG); addFileType(“AAC”, FILE_TYPE_AAC, “audio/aac”, MtpConstants.FORMAT_AAC); addFileType(“AAC”, FILE_TYPE_AAC, “audio/aac-adts”, MtpConstants.FORMAT_AAC); addFileType(“MKA”, FILE_TYPE_MKA, “audio/x-matroska”); addFileType(“MID”, FILE_TYPE_MID, “audio/midi”); addFileType(“MPEG”, FILE_TYPE_MP4, “video/mpeg”, MtpConstants.FORMAT_MPEG); if (isWMVEnabled()) { addFileType(“JPG”, FILE_TYPE_JPEG, “image/jpeg”, MtpConstants.FORMAT_EXIF_JPEG); addFileType(“M3U”, FILE_TYPE_M3U, “audio/x-mpegurl”, MtpConstants.FORMAT_M3U_PLAYLIST); addFileType(“FL”, FILE_TYPE_FL, “application/x-android-drm-fl”); addFileType(“TXT”, FILE_TYPE_TEXT, “text/plain”, MtpConstants.FORMAT_TEXT); |
[REFERENCE]
https://developer.mozilla.org/ko/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
https://stackoverflow.com/questions/23385520/android-available-mime-types
#android MIME-Type list,#MIME Type 종류,#MIME Type이란,#application/octet-stream,#MIME type 확인,#MIME type list,#Android mimeType list,#MIME Type 설정,#MIME type pdf