Photo does not show up to gallery

前端 未结 3 1796
走了就别回头了
走了就别回头了 2020-12-22 11:39

I\'m trying to take a photo using the android camera and telling it to save to the phone\'s gallery. I think i messed up on the path, but i can\'t seem to find my error. Cou

相关标签:
3条回答
  • 2020-12-22 11:42

    This will work in all android versions used in on activity result of camera capture

    MediaScannerConnection.scanFile(this, new String[]{file.getPath()}, new String[]{"image/jpeg"}, null);

    0 讨论(0)
  • 2020-12-22 11:42

    You need to set a value to this uriToFileInExternalStorage

    Sample code:

    fileName = "image_" + String.valueOf(numImages) + ".jpg";
    
    File output = new File(direct + File.separator + fileName); // create
                                                                        // output
    while (output.exists()) { // while the file exists
        numImages++; // increment number of images
        fileName = "image_" + String.valueOf(numImages) + ".jpg";
        output = new File(outputFolder, fileName);
    }
    
    uriToFileInExternalStorage = Uri.fromFile(output); 
    
    0 讨论(0)
  • 2020-12-22 11:58

    Try code given here: Add the Photo to a Gallery

    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File(mCurrentPhotoPath);
    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    this.sendBroadcast(mediaScanIntent);
    

    I would suggest you to download example PhotoIntentActivity to read and understand how to fetch mCurrentPhotoPath value.

    0 讨论(0)
提交回复
热议问题