A FileNameMap is an interface returned by methods of a class that understands filetypes. For example there is a URLConnection class that has a getFileNameMap() method, which is used like this.
private void requestIntent(Uri uri) {
Intent intent = new Intent(Intent.ACTION_VIEW);
FileNameMap mime = URLConnection.getFileNameMap();
String mimeType = mime.getContentTypeFor(uri.getPath());
intent.setDataAndType(uri, mimeType);
try {
mActivity.startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(mActivity, OResource.string(mActivity, R.string.toast_no_activity_found_to_handle_file), Toast.LENGTH_LONG).show();
}
}
That example from here
So, you usually do not use FileNameMap in isolation. Instead you either use an existing library class that creates objects that implement FileNameMap. If you did want to implement such a library you would need to write code like this (taken from the source of UrlConnection)
public static synchronized FileNameMap More getFileNameMap() {
316 if ((fileNameMap == null) && !fileNameMapLoaded) {
317 fileNameMap = sun.net.www.MimeTable.loadTable();
318 fileNameMapLoaded = true;
319 }
320
321 return new FileNameMap() {
322 private FileNameMap map = fileNameMap;
323 public String getContentTypeFor(String fileName) {
324 return map.getContentTypeFor(fileName);
325 }
326 };
327 }
You see here that the implementation creates an anonymous class implementing the interface; your responsibility as implementor of the interface would be to figure a way to implement that getContentTypeFor() method.
If all you want to do is get the mime type for a file then you can use URLConnection to give you an object that already has that implementation, and so just use the approach shown in the answer to the related question