The shooting was reported at about 10:34 a.m. in the 27200 block of Sleepy Hollow Avenue near West Tennyson Road, police said.
Foster was taken to a local hospital, where he was pronounced dead.
Police said the shooting is still under investigation and they don't have any suspect information.
Two nearby schools went into lockdown after the shooting, a school district employee said.
Southgate Elementary School, located at 26601 Calaroga Ave., went on lockdown around 11:30 a.m., according to Lisa Cote, an executive assistant with the Hayward Unified School District superintendent's office.
She said the lockdown was recommended by Hayward police.
Martin Luther King Jr. Middle School, located about half a mile away at 26890 Holly Hill Ave., decided to go on voluntary lockdown, Cote said.
The lockdowns were lifted at about 12:30 p.m.