gpt4 book ai didi

android - 如何将拍摄的照片添加到 MediaStore

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:04:33 26 4
gpt4 key购买 nike

我想将拍摄的照片添加到 MediaStore,以便 Gallery 应用程序可以找到它们(无需重启设备)。应用程序的最小 SDK 为 9。感谢任何帮助、博客或文档。

最佳答案

在大多数设备上,您只需稍等片刻,系统就会自动检测到新照片。

如果你想立即刷新图库,你需要使用 MediaScanner 类,它会刷新图库 - 删除删除的照片,添加新的等等......

public void refreshGallery() {
Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
String newPhotoPath = "file:" + image.getAbsolutePath(); // image is the created file image
File file = new File(newPhotoPath);
Uri contentUri = Uri.fromFile(file);
scanIntent.setData(contentUri);
sendBroadcast(scanIntent);
}

希望这对您有所帮助!

关于android - 如何将拍摄的照片添加到 MediaStore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21822759/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com