作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想将拍摄的照片添加到 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/
我是一名优秀的程序员,十分优秀!