Search code examples
google-glassgoogle-gdkandroid-file

Images and folder not appear on USB folder access


I'm trying to make a photo and store it on the device.

For the path, i'm using this:

File mediaStorageDir = new File(Environment.getExternalStorageDirectory() + File.separator + "DCIM", "nameFolder");

And the path for each image that I store, the path is this:

/storage/emulated/0/DCIM/nameFolder/IMG_20150513_125555.jpg

Ok, it seems that works fine.

But, when I try to see the photo via USB, there is no exist the new folder

However, if I accede via DDMS, I can find the folder and the image in this path:

mnt/shell/emulated0/DCIM/nameFolder

What is the problem?


Solution

  • You don't tell the device that you created a new file so what you need to do is use a Media Scanner so that it can update the list of files on your device. Try creating a new class that looks like this:

    public class SingleMediaScanner implements MediaScannerConnection.MediaScannerConnectionClient
    {
        private MediaScannerConnection mMediaScanner;
        private File mFile;
    
        public SingleMediaScanner(Context context, File file)
        {
            mFile= file;
            mMediaScanner = new MediaScannerConnection(context, this);
            mMediaScanner.connect();
        }
    
        @Override
        public void onMediaScannerConnected()
        {
            mMediaScanner.scanFile(mFile.getAbsolutePath(), null);
        }
    
        @Override
        public void onScanCompleted(String path, Uri uri)
        {
            mMediaScanner.disconnect();
        }
    
    }
    

    And then after you create the file just do this:

    new SingleMediaScanner(mContext, image);
    

    That should let the device know there is a new image and it should show up in usb connection now.