0

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?

adlagar
  • 877
  • 10
  • 31

2 Answers2

0

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.

w9jds
  • 877
  • 6
  • 17
0

In addition to w9jds's answer, you can also send a broadcast to let the system know that you created new media files.

For a particular file:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(imageAdded)));

Or to scan the whole external storage:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
          Uri.parse("file://"+ Environment.getExternalStorageDirectory())));

Also see:

Scan Android SD card for new files

How can I refresh MediaStore on Android?

Community
  • 1
  • 1
pt2121
  • 11,720
  • 8
  • 52
  • 69