1

我的应用程序创建了一个与标准 .PNG 向后兼容的自定义 .PNG 文件,但我希望我的应用程序能够识别我的特殊 .PNG(而不是默认为 Gallery)。创建图像后,我尝试将其注册为自定义 MIME 类型,但它们仍被作为常规 PNG 扫描。

File file = new File("/mnt/sdcard/custom.png");
//now scan the file into the content database
MediaScannerConnection.scanFile(this,
            new String[] { file.toString() }, new String[] { "image/x-custom" },
                new MediaScannerConnection.OnScanCompletedListener() {
            public void onScanCompleted(String path, Uri uri) {
                Log.i("ExternalStorage", "Scanned " + path + ":");
                Log.i("ExternalStorage", "-> uri=" + uri);

                ContentResolver cr = getContentResolver();
                String mime = cr.getType(uri);
                //mime returns image/png, not image/x-custom :(        
            }

关于如何让 Android 识别我的自定义 MIME 类型和/或允许我的应用识别扩展的 .PNG 的任何想法?

4

3 回答 3

0

You need to add your mimetype and file extension to android/frameworks/base/media/java/android/media/MediaFile.java.

When mediascanner can't find your mimetype in MediaFile.java, it will get a new mimetype for it by basing on the file extension.

于 2011-12-15T09:32:38.943 回答
0

扫描似乎是基于文件扩展名的,我今天才读到,我试图记住在哪里..

于 2011-08-15T01:05:13.023 回答
0

您必须有一些活动将自己(在清单上)注册为能够处理 .png 文件(或您的 mime 类型)。自定义 mime 类型的文件的问题是系统应该能够将您的 .png 识别为与常规 .png 不同的类型(它可能不会这样做)。所以你可以做你想做的最好的方法是创建一个可以处理所有.png的IntentFilter。

你可以在这里这里阅读。

于 2011-08-15T01:11:40.000 回答