1 minute read
10.4. Building and Running the App
if (location != null) { latitude = location.getLatitude(); longitude = location.getLongitude(); Toast.makeText(getApplicationContext(), "READY TO SEND!!!", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(), "NOT READY YET...", Toast.LENGTH_LONG).show(); }
@Override public void onStatusChanged(String s, int i, Bundle bundle) {
@Override public void onProviderEnabled(String s) { Toast.makeText(getApplicationContext(), "GPS Enabled!", Toast.LENGTH_LONG).show();
@Override public void onProviderDisabled(String s) {
Toast.makeText(getApplicationContext(), "Please enable GPS!", Toast.LENGTH_LONG).show();
}
Code 10.11 (cont‟d from the previous pages)
10.4. Building and Running the App
Since this app uses SMS functionality, it needs a GSM connection therefore it cannot be simulated in an emulator. Please connect a real Android device to your computer and select it for running this app after hitting the Run button in Android Studio as follows:
Figure 10.11. Selecting a real Android device with GSM functionality
When the app starts, please wait a moment to see the READY TO SEND! message on the screen and then if you click on the giant S.O.S. button, the phone will send your current location to the hardcoded phone number. In the receiving phone, you‟ll see a text such as Please take me from longitude: -1.985401 and latitude 52.397618. The coordinates will obviously be different depending on your location.
It is again worth noting that you can download the complete project files, images, etc. from the book‟s companion website: www.androidjava.website.