Solution 1
fun getCameraBucketId(): Int { val bucketPath = Environment.getExternalStoragePublicDirectory("/DCIM/Camera").toString() return bucketPath.toLowerCase().hashCode().toLong()}
NOTE: Environment.getExternalStoragePublicDirectory is deprecated in API level 29
Solution 2
Search for all albums with the name "Camera".
fun getCameraBucketId(): Long? { for (item in findAlbums()) { if (item.name == "Camera") { cameraBucketId = item.id return item.id } } return null}
NOTE: Refer to findAlbums
Solution 3
Combine solution 1 and 2
private var cameraBucketId: Long? = null@Suppress("DEPRECATION")fun getCameraBucketId(): Long? { if (cameraBucketId == null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { val bucketPath = Environment.getExternalStoragePublicDirectory("/DCIM/Camera").toString() cameraBucketId = bucketPath.toLowerCase().hashCode().toLong() return cameraBucketId } else { for (item in findAlbums()) { Timber.d("${item.name}=${item.count}, ${item.id}") if (item.name == "Camera") { cameraBucketId = item.id return cameraBucketId } } } } return cameraBucketId}