0

我有一个关于 MediaScanner 的基本问题,请帮助我更好地理解这一点。

文件夹的 MediaScanner 仅返回有关已扫描文件夹的信息,但不返回文件夹中存在的任何媒体文件的内容。如果扫描文件夹以查找 ex。/storage/extSdCard/DCIM/Camera其中有几个 .jpg 文件,我得到有关文件夹的扫描响应,而不是其中的文件。下面的日志,

D/MediaScannerConnection(29105): Connected to MediaScanner
D/MediaScannerConnection(29105): Scanning file 7klwibgf7fxlKdCbid7DCRV7Cbvfib

D/MyLog(29105): onScanCompleted(path,uri), path: /storage/extSdCard/DCIM/Camera, Uri: content://media/external/file/4334

我的问题,在这种情况下,当媒体文件添加到我感兴趣的文件夹中时,是否有可能恢复事件,/storage/extSdCard/DCIM/Camera

    public void MyScanner(String filename){
        File fileCheck = new File(filename);
        conn = new MediaScannerConnection(this,this);
        conn.connect();
}

@Override
    public void onMediaScannerConnected() {
        Log.d(TAG,"onMediaScannerConnected() to MediaScanner Service");
        conn.scanFile(filename, null);
    }

@Override
    public void onScanCompleted(String path, Uri uri) {
        if(path!=null && uri!=null)
        Log.d(TAG,"onScanCompleted(), path: "+path+", Uri: "+uri.toString());
        Log.d(TAG,"Converting file uri to FilePath: "+getRealPathFromURI(uri)); 
        }
4

1 回答 1

0
  First One Code....

 scanPhoto(imageFileName.toString());



public void scanPhoto(final String imageFileName)
{
  msConn = new MediaScannerConnection(PreviewDemo1.this,new MediaScannerConnectionClient()
  {
                public void onMediaScannerConnected()
                {
                    msConn.scanFile(imageFileName, null);
                    Log.i("msClient obj  in Photo Utility","connection established");
                }
                public void onScanCompleted(String path, Uri uri)
                {
                    msConn.disconnect();
                    Log.i("msClient obj in Photo Utility","scan completed");
                }
    });
    msConn.connect();
 } 

第二个代码..

 sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
于 2013-08-16T10:37:50.073 回答