// Path: FileManager/src/main/java/org/openintents/filemanager/util/MimeTypes.java
// public class MimeTypes {
// 
//     private static MimeTypes mimeTypes;
// 
//     private Map<String, String> mExtensionsToTypes = new HashMap<>();
//     private Map<String, Integer> mTypesToIcons = new HashMap<>();
// 
//     public static MimeTypes getInstance() {
//         if (mimeTypes == null) {
//             throw new IllegalStateException("MimeTypes must be initialized with newInstance");
//         }
//         return mimeTypes;
//     }
// 
//     /**
//      * Use this instead of the default constructor to get a prefilled object.
//      */
//     public static void initInstance(Context c) {
//         MimeTypeParser mtp = null;
//         try {
//             mtp = new MimeTypeParser(c, c.getPackageName());
//         } catch (NameNotFoundException e) {
//             // Should never happen
//         }
// 
//         XmlResourceParser in = c.getResources().getXml(R.xml.mimetypes);
// 
//         try {
//             mimeTypes = mtp.fromXmlResource(in);
//         } catch (XmlPullParserException | IOException e) {
//             e.printStackTrace();
//         }
//     }
// 
//     public void put(String extension, String type, int icon) {
//         put(extension, type);
//         mTypesToIcons.put(type, icon);
//     }
// 
//     public void put(String extension, String type) {
//         // Convert extensions to lower case letters for easier comparison
//         extension = extension.toLowerCase(Locale.ROOT);
//         mExtensionsToTypes.put(extension, type);
//     }
// 
//     public String getMimeType(String filename) {
//         String extension = FileUtils.getExtension(filename);
// 
//         // Let's check the official map first. Webkit has a nice extension-to-MIME map.
//         // Be sure to remove the first character from the extension, which is the "." character.
//         if (extension.length() > 0) {
//             String webkitMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.substring(1));
// 
//             if (webkitMimeType != null) {
//                 // Found one. Let's take it!
//                 return webkitMimeType;
//             }
//         }
// 
//         // Convert extensions to lower case letters for easier comparison
//         extension = extension.toLowerCase();
// 
//         String mimetype = mExtensionsToTypes.get(extension);
// 
//         if (mimetype == null) {
//             mimetype = "*/*";
//         }
// 
//         return mimetype;
//     }
// 
//     public int getIcon(String mimetype) {
//         Integer iconResId = mTypesToIcons.get(mimetype);
//         if (iconResId == null)
//             return 0; // Invalid identifier
//         return iconResId;
//     }
// }


import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.provider.MediaStore;
import org.openintents.filemanager.util.MimeTypes;
import java.io.File;
import java.io.FileNotFoundException;

package org.openintents.filemanager;




public class FileManagerProvider extends ContentProvider {

    public static final String FILE_PROVIDER_PREFIX = "content://org.openintents.filemanager";
    public static final String AUTHORITY = "org.openintents.filemanager";
    private MimeTypes mMimeTypes;

    public static Uri getUriForFile(Uri uri) {
        String filePath = uri.getSchemeSpecificPart();
        return getUriForFile(filePath);
    }

    public static Uri getUriForFile(String filePath) {
        if (filePath.startsWith("//")) {
            filePath = filePath.substring(2);
        }
        return Uri.parse(FILE_PROVIDER_PREFIX).buildUpon()
                .appendPath(filePath)
                .build();
    }

    @Override
    public boolean onCreate() {
        MimeTypes.initInstance(getContext());

// Path: FileManager/src/main/java/org/openintents/filemanager/util/MimeTypes.java
// public class MimeTypes {
// 
//     private static MimeTypes mimeTypes;
// 
//     private Map<String, String> mExtensionsToTypes = new HashMap<>();
//     private Map<String, Integer> mTypesToIcons = new HashMap<>();
// 
//     public static MimeTypes getInstance() {
//         if (mimeTypes == null) {
//             throw new IllegalStateException("MimeTypes must be initialized with newInstance");
//         }
//         return mimeTypes;
//     }
// 
//     /**
//      * Use this instead of the default constructor to get a prefilled object.
//      */
//     public static void initInstance(Context c) {
//         MimeTypeParser mtp = null;
//         try {
//             mtp = new MimeTypeParser(c, c.getPackageName());
//         } catch (NameNotFoundException e) {
//             // Should never happen
//         }
// 
//         XmlResourceParser in = c.getResources().getXml(R.xml.mimetypes);
// 
//         try {
//             mimeTypes = mtp.fromXmlResource(in);
//         } catch (XmlPullParserException | IOException e) {
//             e.printStackTrace();
//         }
//     }
// 
//     public void put(String extension, String type, int icon) {
//         put(extension, type);
//         mTypesToIcons.put(type, icon);
//     }
// 
//     public void put(String extension, String type) {
//         // Convert extensions to lower case letters for easier comparison
//         extension = extension.toLowerCase(Locale.ROOT);
//         mExtensionsToTypes.put(extension, type);
//     }
// 
//     public String getMimeType(String filename) {
//         String extension = FileUtils.getExtension(filename);
// 
//         // Let's check the official map first. Webkit has a nice extension-to-MIME map.
//         // Be sure to remove the first character from the extension, which is the "." character.
//         if (extension.length() > 0) {
//             String webkitMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.substring(1));
// 
//             if (webkitMimeType != null) {
//                 // Found one. Let's take it!
//                 return webkitMimeType;
//             }
//         }
// 
//         // Convert extensions to lower case letters for easier comparison
//         extension = extension.toLowerCase();
// 
//         String mimetype = mExtensionsToTypes.get(extension);
// 
//         if (mimetype == null) {
//             mimetype = "*/*";
//         }
// 
//         return mimetype;
//     }
// 
//     public int getIcon(String mimetype) {
//         Integer iconResId = mTypesToIcons.get(mimetype);
//         if (iconResId == null)
//             return 0; // Invalid identifier
//         return iconResId;
//     }
// }


// Path: FileManager/src/main/java/org/openintents/filemanager/FileManagerProvider.java
import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.provider.MediaStore;
import org.openintents.filemanager.util.MimeTypes;
import java.io.File;
import java.io.FileNotFoundException;

package org.openintents.filemanager;




public class FileManagerProvider extends ContentProvider {

    public static final String FILE_PROVIDER_PREFIX = "content://org.openintents.filemanager";
    public static final String AUTHORITY = "org.openintents.filemanager";
    private MimeTypes mMimeTypes;

    public static Uri getUriForFile(Uri uri) {
        String filePath = uri.getSchemeSpecificPart();
        return getUriForFile(filePath);
    }

    public static Uri getUriForFile(String filePath) {
        if (filePath.startsWith("//")) {
            filePath = filePath.substring(2);
        }
        return Uri.parse(FILE_PROVIDER_PREFIX).buildUpon()
                .appendPath(filePath)
                .build();
    }

    @Override
    public boolean onCreate() {
        MimeTypes.initInstance(getContext());

        mMimeTypes = MimeTypes.getInstance();
