开发者

MediaScannerConnection, this syntax won't compile

I'm trying to add a file in my data directory on my sdcard to the mediastore content provider. However, I fear that I may have a java education 开发者_高级运维issue on my hands. MediaScannerConnectionClient is purportedly a nested class of MediaScannerConnection, but this syntax won't compile.

Here is the link to the MediaScannerConnection API: http://developer.android.com/reference/android/media/MediaScannerConnection.html

What would be the appropriate way to reference scanner?

Thanks!

final String filename = (new File(img.uri.toString())).getAbsolutePath().substring(6);

        final MediaScannerConnection scanner = new MediaScannerConnection(this,
                new MediaScannerConnectionClient() {
                    public void onMediaScannerConnected() {
                        MediaScannerConnection.this.scanFile(filename, null /*mimeType*/);
                    }

                    public void onScanCompleted(String path, Uri uri) {
                         MediaScannerConnection.this.disconnect();
                    }
            });
        scanner.connect();


I finally found my answer in an example.

.../android-8/ApiDemos/src/com/example/android/apis/content/ExternalStorage.java

// Tell the media scanner about the new file so that it is
// immediately available to the user.
MediaScannerConnection.scanFile(this,
    new String[] { filename }, null,
    new MediaScannerConnection.OnScanCompletedListener() {
    public void onScanCompleted(String path, Uri uri) {
    Log.i("ExternalStorage", "Scanned " + path + ":");
        Log.i("ExternalStorage", "-> uri=" + uri);
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜