Main Function - liuyiming091/falldetector GitHub Wiki

Main Function

The major project is designing and developing an Android application, which could receive information from embedded sensors in smartphone, then detect and identify falls of older people. In this application, many functions have been developed, some details are shown as below.

  • Fall Detection

The fall detection is used to monitor the elderly for potential possibility of falls, so that they can get help on time. The application will run on background and detect the fall. Users shall input the personal information and the emergency phone number and name of the contract, and then click the button to monitor. When a fall is detected, the application would wake up and unlock the screen to show an alert view on the screen. If the users don’t respond to the alert, the phone would send the emergency message to the contact, and tell the contact the location of the user.

  • Location Tracking

We use the Google play service API to get the user’s location, it will call the Google play service to get the last known location of the user, and the location information would be updated automatically on the service.

//Check if the google play services are available on this phone
private boolean checkPlayServices() {
    GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
    int result = googleAPI.isGooglePlayServicesAvailable(this);
    if(result != ConnectionResult.SUCCESS) {
        if(googleAPI.isUserResolvableError(result)) {
            googleAPI.getErrorDialog(this, result,
                    PLAY_SERVICES_RESOLUTION_REQUEST).show();
        }

        return false;
    }

    return true;
}
//Build the google api client to get the location
protected synchronized void buildGoogleApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();
}

private void getCurrentLocation() {

    int permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
    if (permission != PackageManager.PERMISSION_GRANTED) {
        //Get the permission of the location
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_ACCESS_FINE_LOCATION );
    }

    mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);

    if (mLastLocation != null) {
        currentLatitude = mLastLocation.getLatitude();
        currentLongitude = mLastLocation.getLongitude();
    }
}
@Override
protected void onStart() {
    super.onStart();
    if (mGoogleApiClient != null) {
        mGoogleApiClient.connect();
    }
}


@Override
public void onConnectionFailed(ConnectionResult result) {
    Log.i(TAG, "Connection failed: ConnectionResult.getErrorCode() = "
            + result.getErrorCode());
}

@Override
public void onConnected(Bundle arg0) {

    // Once connected with google api, get the location
    getCurrentLocation();
}

@Override
public void onConnectionSuspended(int arg0) {
    mGoogleApiClient.connect();
}
  • Alarming

We use the SMS service on the phone to send an alert message to help the user to get help, the message would include the name of the user and his/her location.

String text_Message ="https://maps.google.com/?t=m&q="+currentLatitude+','+currentLongitude+"+(Shared+location)&ll="+currentLatitude+','+currentLongitude+"&z=17";
String text_Message2="An emergency might occur to your friend, "+name+", here is the location for him/her right now, please help him/her as soon as possible!";
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phone, null, text_Message2, null, null);
smsManager.sendTextMessage(phone, null, text_Message, null, null);
Toast.makeText(AlertActivity.this,"Alert Sended!",Toast.LENGTH_SHORT).show();
  • Helpful information

It is very important for elder people to get correct weather information in time, some fall-related injury due to bad weather could be avoided. This application could acquire weather information automatically in the main activity and also tips about how to prevent a fall and knowledge about first aid.