こちらの記事を参考に実装したところ以下のエラーが出ました。
java.lang.NullPointerException: uriString
こちらを解決した際の内容をかるく紹介しておき、
今後のために記事に残しておきます。
解決方法
for (int i = 0; i < count; i++) {
val bytes = ByteArrayOutputStream()
bitmapImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes)
- val path = MediaStore.Images.Media.insertImage(context.getContentResolver(),
+ val path = MediaStore.Images.Media.insertImage(context.getContentResolver(),
bitmapImage, "Title + i", null)
val uri = Uri.parse(path)
}
MediaStoreへinsertImageする際にtitleが同じだとエラーになるようで、そこを毎回違う値が入るようにしたらエラーが出なくなりました。
今回はfor文で回していたので、回した回数をtitleに含めて渡すことにしました。