The New Yorker recently had a piece on early earthquake warning systems that have been developed in recent years. People can sign up for an app and get the warnings on their cell phones.
The way it works, according to California's Office of Emergency Services: in an earthquake, a rupturing fault sends out three different types of waves. The fast-moving P-wave is first to arrive, with damage being caused by the slower S-waves and surface waves.
Sensors detect the P-wave and immediately transmit data to an earthquake alert center where the location and size of the quake are determined and updated. A message from an alert center is immediately transmitted to users giving them a few seconds warning.