0% found this document useful (0 votes)
60 views38 pages

MAD Microproject

Uploaded by

films.doifode
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views38 pages

MAD Microproject

Uploaded by

films.doifode
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

A

Micro-Project report
On
“DEVELOP AN ANDROID APPLICATION FOR WOMEN SAFETY”
Submitted to the

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION,


MUMBAI

In for the award of diploma impartial fulfilment of the requirements

COMPUTER ENGINEERING

(MOBILE APPLICATION DEVELOPMENT)


(22617)

Submitted by
1.Bhavesh Nitin Doifode 2.Swanand Sandeep Deo

3.Vansh Ganesh Rajurkar 4.Nagesh Saroj Vishwakarma

Under The Guidance Of

(Ms. Chyrine Nicholas)

Academic Year 2022-2023

DEPARTMENT OF COMPUTER ENGINEERING

G. H. RAISONI POLYTECHNIC
B-37-39/1, Shraddha Park, Hingna Wadi Link Road, Nagpur-
28
G. H. RAISONI POLYTECHNIC
Academic Session 2022-2023
CERTIFICATE

This is to certify that this micro project report on “ DEVELOP AN

ANDROID APPLICATION FOR WOMEN SAFETY” is the

bonafide work of Bhavesh Nitin Doifode, Swanand Sandeep Deo,

Vansh Ganesh Rajurkar, Nagesh Saroj Vishwakarma. Who carried

out the project work under my supervision for the partial fulfillment of

the requirement for the award of the degree of the diploma in

Computer Engineering in Sixth semester.

(Mrs. Roshani Dharme) (Ms. Chyrine Nicholas)


Head Of The Department Project Guide

(Dr. G. N. Akhade)
Principal
MAHARASHTRA STATE BOARD OF TECHNICAL
EDUCATION, MUMBAI

SUBMISSION
We are the students of G. H. Raisoni Polytechnic, Nagpur, Third year sixth
semester of course COMPUTER ENGINEERING humbly submit that we
completed time to time as a part of project work as prescribed Maharashtra State
Board of Technical Education, Mumbai for the subject MOBILE
APPLICATION DEVELOPMENT (MAD) and the project is prescribed in the
report by our own skill and study for the academic session 2022-2023, as per the
guidance of Ms Chyrine Nicholas , Lecturer in MOBILE APPLICATION
DEVELOPMENT (MAD).

Name of Students: Signature

1. Bhavesh Nitin Doifode ----------------

2. Swanand Sandeep Deo ----------------

3. Vansh Ganesh Rajurkar ----------------

4. Nagesh Saroj Vishwakarma ----------------


ACKNOWLEDGEMENT

We wish to avail this opportunity to acknowledge Our profound


indebtedness and extend our deep sense of gratitude of our
profound Ms. Chyrine Nicholas For her valuable guidance , advice
and encouragement that has been feel to successful completion of
this micro-project.

We here by express our deep gratitude to our H.O.D. and Hon'ble


Principal for his/her cooperation and help and also the other staff
member of the department.

We also thank to library for making us available necessary books for


reference. I would like to place on record my sincere thanks to all
persons directly or indirectly helped us in completion of this work.

Name of Students:- Sign

1. Bhavesh Nitin Doifode

2. Swanand Sandeep Deo

3. Vansh Ganesh Rajurkar

4. Nagesh Saroj Vishwakarma


PART A
DEVELOP AN ANDROID APPLICATION FOR WOMEN SAFETY
• Brief Introduction
To provide safety for women a good way to reduce the chances of
becoming a victim of violent crime is to identify and call on resources to
help you out unsafe situations. Having a safety app on your phone can
reduce the reason for the risk situation and add assistance when we need
to use it.
• Aim Of Microproject
To Create an Android Application For Women’s Safety

• Action Plan

Planed Name of
Sr. Planned
Details of activity Finished Responsible
No. Start date
Date Team
Members
1 Project Survey 15/03/23 21/03/23 Bhavesh Doifode

2 Gathering 25/03/23 08/04/23 Nagesh Vishwakarma


Information

3 Setup And 13/04/23 20/04/23 Vansh Rajurkar


Configuration

4 Create Report 22/04/23 27/04/23 Swanand Deo


INDEX

Sr.
No. Content Page No.

1 Introduction 07

2 XML Program 08-14

3 Java Program 15-36

4 Output 36-37

5 Reference 38
INTRODUCTION
In today’s fast moving world, Women Security is an issue of growing concern.
We have read about many unfortunate incidents happening with women and the
rate is increasing. Women these days are working women and the globalization
has made us aware of gender equality. Earlier the women were restricted only to
the household chores. With the changing scenario, women are competing with
men in all fields.

We can see women going to great success levels in all fields, may it be corporate,
scientific, education, business or any other field. Safety of women matters a lot
whether at home, outside the home or working place. Last few crimes against
women especially the case in Delhi was very dread and fearful. Because of such
crimes, women safety has become a major topic. According to the statistics, it is
found that every two out of three women have suffered trauma in the last year.
According to the survey of women, it is found that women are losing their
confidence because of such incidents. By the survey of Delhi government’s
Women and Child Development Department, around 80% of the women in
national capital have fear regarding their safety. Women are harassed not only in
the night or evening but also in the day time at their home, working places, or
other places like street, club, etc. It is found through the survey that the reason of
safety concern is the lack of gender-friendly environment and improper
functional infrastructure such as consumption of alcohol and drugs in open area,
lack of adequate lighting, safe public toilets, sidewalks, lack of effective police
service, lack of properly working helpline numbers, etc. A huge percentage of
women have no faith that police can curb such harassment cases. There is an
urgent need to understand and solve this problem of women safety so that they
can also grow equally like men in their own country.
• XML PROGRAM
Layout Folder:

activity_display.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Display" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"

android:text="Shake your phone to TEST." />

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:onClick="back"
android:text="Main Menu" />

</RelativeLayout>

activity_instructions.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Instructions" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:text="INSTRUCTIONS"
android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/help"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:onClick="back"
android:text="Main Menu" />

<TextView
android:id="@+id/help"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/textView1"
android:layout_marginTop="15dp"
android:text="@string/help" />

</RelativeLayout>

activity_register.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Register" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="64dp"
android:text="Name:" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="71dp"
android:text="Number:" />

<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="68dp"
android:onClick="storeInDB"
android:text="Save" />

<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_alignRight="@+id/button1"
android:ems="10"
android:hint="Mobile Number"
android:inputType="phone" />

<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/textView1"
android:layout_alignBottom="@+id/textView1"
android:layout_alignLeft="@+id/editText2"
android:ems="10"
android:hint="Person Name"
android:inputType="textPersonName" >

<requestFocus />
</EditText>

<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_alignParentBottom="true"
android:layout_marginBottom="21dp"
android:onClick="instructions"
android:text="Instructions" />
<Button
android:id="@+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button1"
android:layout_alignTop="@+id/button2"
android:onClick="display"
android:text="View Registered" />

</RelativeLayout>

activity_verify.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Verify" >

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="176dp"
android:onClick="verify_no"
android:text="Submit" />

<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="76dp"
android:ems="10"
android:hint="Your Phone Number"
android:inputType="phone" >

<requestFocus />
</EditText>

<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="94dp"
android:onClick="back"
android:text="Back" />

</RelativeLayout>

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Verify" >

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="176dp"
android:onClick="verify_no"
android:text="Submit" />

<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="76dp"
android:ems="10"
android:hint="Your Phone Number"
android:inputType="phone" >

<requestFocus />
</EditText>

<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="94dp"
android:onClick="back"
android:text="Back" />

</RelativeLayout>

Menu Folder :

instuctions.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>

</menu>
display.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>

</menu>
register.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>

</menu>
main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>

</menu>
verify.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/action_settings"/>

</menu>

Values Folder :

style.xml
<resources>

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>

<!-- Application theme. -->


<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

</resources>
dimens.xml
<resources>

<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>

</resources>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">Women Safety App</string>


<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="title_activity_register">Register</string>
<string name="title_activity_display">Display</string>
<string name="title_activity_instructions">Instructions</string>
<string name="title_activity_verify">Verify</string>
<string name="help">Please follow the below steps to setup your account:\n\n\n\t1:Register
Your Phone Number.\n\t2:Register Your Guardian Numbers.\n\t3:Always maintain working
internet connection.\n\t4:SHAKE your phone in case of emergency to alert your
guardians.\n\t\n\n\n\n\tLETS START NOW!</strin
</resources>
• JAVA PROGRAM
Display.Java:

package com.prabhu.womensafetyapp;

import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;

public class Display extends Activity{

Cursor c;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display);

SQLiteDatabase db;
db=openOrCreateDatabase("NumDB", Context.MODE_PRIVATE, null);

c=db.rawQuery("SELECT * FROM details", null);


if(c.getCount()==0)
{
showMessage("Error", "No records found.");
return;
}
StringBuffer buffer=new StringBuffer();
while(c.moveToNext())
{
buffer.append("Name: "+c.getString(0)+"\n");
buffer.append("Number: "+c.getString(1)+"\n");
}
showMessage("Details", buffer.toString());
Intent i_startservice=new Intent(Display.this,BgService.class);
startService(i_startservice);

public void showMessage(String title,String message)


{
Builder builder=new Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(message);
builder.show();
}

public void back(View v) {


Intent i_back=new Intent(Display.this,MainActivity.class);
startActivity(i_back);

Register.Java:

package com.prabhu.womensafetyapp;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class Register extends Activity {

EditText name,number;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
//Toast.makeText(getApplicationContext(), "Activity
created",Toast.LENGTH_LONG).show();

public void display(View v) {


Intent i_view=new Intent(Register.this,Display.class);
startActivity(i_view);

public void instructions(View v) {


Intent i_help=new Intent(Register.this,Instructions.class);
startActivity(i_help);

public void storeInDB(View v) {


Toast.makeText(getApplicationContext(), "save
started",Toast.LENGTH_LONG).show();
name = (EditText) this.findViewById(R.id.editText1);
number = (EditText) this.findViewById(R.id.editText2);
String str_name=name.getText().toString();
String str_number=number.getText().toString();
SQLiteDatabase db;
db=openOrCreateDatabase("NumDB", Context.MODE_PRIVATE, null);
//Toast.makeText(getApplicationContext(), "db
created",Toast.LENGTH_LONG).show();

db.execSQL("CREATE TABLE IF NOT EXISTS details(name VARCHAR,number


VARCHAR);");
//Toast.makeText(getApplicationContext(), "table
created",Toast.LENGTH_LONG).show();

Cursor c=db.rawQuery("SELECT * FROM details", null);


if(c.getCount()<2)
{
db.execSQL("INSERT INTO details
VALUES('"+str_name+"','"+str_number+"');");
Toast.makeText(getApplicationContext(), "Successfully
Saved",Toast.LENGTH_SHORT).show();
}
else {

db.execSQL("INSERT INTO details


VALUES('"+str_name+"','"+str_number+"');");
Toast.makeText(getApplicationContext(), "Maximun Numbers limited reached.
Previous numbers are replaced.",Toast.LENGTH_SHORT).show();
}

db.close();

RGeocoder.Java:

package com.prabhu.womensafetyapp;

import java.io.IOException;
import java.util.List;
import java.util.Locale;

import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

public class RGeocoder {

private static final String TAG = "LocationAddress";

public void getAddressFromLocation(final double latitude, final double longitude,


final Context context, final Handler handler) {

Thread thread = new Thread() {


@Override
public void run() {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
String result = null;
try {

List<Address> addressList = geocoder.getFromLocation(latitude, longitude, 1);


if (addressList != null && addressList.size() > 0) {
Address address = addressList.get(0);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
sb.append(address.getAddressLine(i)).append("\n");
}
sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName());
result = sb.toString();

}
}

catch (IOException e) {
Log.e(TAG, "Unable connect to Geocoder", e);
}

finally {
Message message = Message.obtain();
message.setTarget(handler);
if (result != null) {
message.what = 1;
Bundle bundle = new Bundle();
result = "Latitude: " + latitude + " Longitude: " + longitude +
"\n\nAddress:\n" + result;
bundle.putString("address", result);
message.setData(bundle);
} else {
message.what = 1;
Bundle bundle = new Bundle();
result = "Latitude: " + latitude + " Longitude: " + longitude +
"\n Unable to get address for this lat-long.";
bundle.putString("address", result);
message.setData(bundle);
}
message.sendToTarget();
}
}
};
thread.start();

}
}

Verify.Java:

package com.prabhu.womensafetyapp;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import android.support.v4.app.NavUtils;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Build;

public class Verify extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_verify);
// Show the Up button in the action bar.
setupActionBar();

public void verify_no(View v) {


EditText source_no = (EditText) this.findViewById(R.id.editText1);
String str_source_no=source_no.getText().toString();
SQLiteDatabase db;
db=openOrCreateDatabase("NumDB", Context.MODE_PRIVATE, null);
// if(source_no.getText()!=null){

db.execSQL("CREATE TABLE IF NOT EXISTS source(number VARCHAR);");


db.execSQL("INSERT INTO source VALUES('"+str_source_no+"');");
Toast.makeText(getApplicationContext(), str_source_no+" Successfully
Saved",Toast.LENGTH_SHORT).show();
db.close();
back(v);
// }
// else{
// Toast.makeText(getApplicationContext(), "Enter Your
Number.",Toast.LENGTH_SHORT).show();
// }
}

/**
* Set up the {@link android.app.ActionBar}, if the API is available.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.verify, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-
vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}

public void back(View v) {


Intent i_back=new Intent(Verify.this,MainActivity.class);
startActivity(i_back);

GPSTracker.Java:

package com.prabhu.womensafetyapp;

import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import android.util.Log;

public class GPSTracker extends Service implements LocationListener {

private final Context mContext;

// flag for GPS status


boolean isGPSEnabled = false;

// flag for network status


boolean isNetworkEnabled = false;

// flag for GPS status


boolean canGetLocation = false;

Location location; // location


double latitude; // latitude
double longitude; // longitude

// The minimum distance to change Updates in meters


private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; // 10 meters

// The minimum time between updates in milliseconds


private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; // 1 minute

// Declaring a Location Manager


protected LocationManager locationManager;

public GPSTracker(Context context) {


this.mContext = context;
getLocation();
}

public Location getLocation() {


try {
locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);

// getting GPS status


isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);

// getting network status


isNetworkEnabled = locationManager

.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

if (!isGPSEnabled && !isNetworkEnabled) {


// no network provider is enabled
} else {
this.canGetLocation = true;
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES,
this);
Log.d("Network", "Network");
if (locationManager != null) {
location = locationManager

.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,

MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager

.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude =
location.getLongitude();
}
}
}
}
}

} catch (Exception e) {
e.printStackTrace();
}

return location;
}

/**
* Stop using GPS listener
* Calling this function will stop using GPS in your app
* */
public void stopUsingGPS(){
if(locationManager != null){
locationManager.removeUpdates(GPSTracker.this);
}
}

/**
* Function to get latitude
* */
public double getLatitude(){
if(location != null){
latitude = location.getLatitude();
}

// return latitude
return latitude;
}

/**
* Function to get longitude
* */
public double getLongitude(){
if(location != null){
longitude = location.getLongitude();
}

// return longitude
return longitude;
}
/**
* Function to check GPS/wifi enabled
* @return boolean
* */
public boolean canGetLocation() {
return this.canGetLocation;
}

/**
* Function to show settings alert dialog
* On pressing Settings button will lauch Settings Options
* */
public void showSettingsAlert(){
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

// Setting Dialog Title


alertDialog.setTitle("GPS is settings");

// Setting Dialog Message


alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");

// On pressing Settings button


alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
mContext.startActivity(intent);
}
});

// on pressing cancel button


alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});

// Showing Alert Message


alertDialog.show();
}

@Override
public void onLocationChanged(Location location) {
}

@Override
public void onProviderDisabled(String provider) {
}

@Override
public void onProviderEnabled(String provider) {
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}

@Override
public IBinder onBind(Intent arg0) {
return null;
}

Instruction.Java

package com.prabhu.womensafetyapp;

import android.os.Bundle;
import android.view.View;
import android.app.Activity;
import android.content.Intent;

public class Instructions extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_instructions);
}

public void back(View v) {


Intent i_back=new Intent(Instructions.this,MainActivity.class);
startActivity(i_back);

MainActivity.java

package com.prabhu.womensafetyapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void register(View v) {


Intent i_register=new Intent(MainActivity.this,Register.class);
startActivity(i_register);

public void display_no(View v) {


Intent i_view=new Intent(MainActivity.this,Display.class);
startActivity(i_view);

public void instruct(View v) {


Intent i_help=new Intent(MainActivity.this,Instructions.class);
startActivity(i_help);
}

public void verify(View v) {


Intent i_verify=new Intent(MainActivity.this,Verify.class);
startActivity(i_verify);
}
}

BgService.java

package com.prabhu.womensafetyapp;

import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.telephony.SmsManager;
import android.util.Log;
import android.widget.Toast;

@SuppressLint("HandlerLeak")
public class BgService extends Service implements AccelerometerListener{

String str_address;

private Looper mServiceLooper;


private ServiceHandler mServiceHandler;

// Handler that receives messages from the thread.


private final class ServiceHandler extends Handler {

public ServiceHandler(Looper looper) {

super(looper);
}
@Override
public void handleMessage(Message msg) {

// REPLACE THIS CODE WITH YOUR APP CODE


// Wait before Toasting Service Message
// to give the Service Started message time to display.

// Toast Service Message.


/* Context context = getApplicationContext();
CharSequence text = "Service Message";
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
*/

// Service can stop itself using the stopSelf() method.


// Not using in this app. Example statement shown below.
//stopSelf(msg.arg1);
}
}

@Override
public IBinder onBind(Intent arg0) {

return null;
}

@Override
public void onCreate() {
super.onCreate();

if (AccelerometerManager.isSupported(this)) {

AccelerometerManager.startListening(this);
}
HandlerThread thread = new
HandlerThread("ServiceStartArguments",android.os.Process.THREAD_PRIORITY_BACKGRO
UND);
thread.start();

mServiceLooper = thread.getLooper();

mServiceHandler = new ServiceHandler(mServiceLooper);


}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

// Get message from message pool using handler.


Message msg = mServiceHandler.obtainMessage();

// Set start ID (unique to the specific start) in message.


msg.arg1 = startId;

// Send message to start job.


mServiceHandler.sendMessage(msg);

// Toast Service Started message.


// Context context = getApplicationContext();

/* CharSequence text = "Service Started";


int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
*/

// Start a sticky.
return START_STICKY;
}

public class GeocoderHandler extends Handler {


@Override
public void handleMessage(Message message) {

Toast.makeText(getApplicationContext(), "geocoderhandler started",


Toast.LENGTH_SHORT).show();

switch (message.what) {
case 1:
Bundle bundle = message.getData();
str_address = bundle.getString("address");
// TelephonyManager
tmgr=(TelephonyManager)BgService.this.getSystemService(Context.TELEPHONY_SERVICE)
;
// String ph_number=tmgr.getLine1Number();
SQLiteDatabase db;
db=openOrCreateDatabase("NumDB", Context.MODE_PRIVATE, null);
Cursor c=db.rawQuery("SELECT * FROM details", null);
Cursor c1=db.rawQuery("SELECT * FROM SOURCE", null);

String source_ph_number=c1.getString(0);
while(c.moveToNext())
{
String target_ph_number=c.getString(1);

// SmsManager smsManager=SmsManager.getDefault();
// smsManager.sendTextMessage("+918121668944", "+918121668944", "Please
help me. I need help immediately. This is where i am now:"+str_address, null, null);

Toast.makeText(getApplicationContext(),
"Source:"+source_ph_number+"Target:"+target_ph_number, Toast.LENGTH_SHORT).show();

}
db.close();

break;
default:
str_address = null;
}
Toast.makeText(getApplicationContext(), str_address,
Toast.LENGTH_SHORT).show();

}
}

@Override
public void onAccelerationChanged(float x, float y, float z) {
// TODO Auto-generated method stub

}
@Override
public void onShake(float force) {

GPSTracker gps;
gps = new GPSTracker(BgService.this);
if(gps.canGetLocation()){

double latitude = gps.getLatitude();


double longitude = gps.getLongitude();

RGeocoder RGeocoder = new RGeocoder();


RGeocoder.getAddressFromLocation(latitude,
longitude,getApplicationContext(), new GeocoderHandler());
Toast.makeText(getApplicationContext(), "onShake",
Toast.LENGTH_SHORT).show();

}
else{
gps.showSettingsAlert();
}

// onDestroy method. Display toast that service has stopped.


@Override
public void onDestroy() {
super.onDestroy();

// Toast Service Stopped.


Context context = getApplicationContext();

Log.i("Sensor", "Service distroy");

if (AccelerometerManager.isListening()) {

AccelerometerManager.stopListening();

CharSequence text = "Women Safety App Service Stopped";


int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.prab


hu.womensafetyapp" android:versionCode="1" android:versionName="1.0">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"> </uses-
permission>
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:la
bel="@string/app_name" android:theme="@style/AppTheme">
<activity android:name="com.prabhu.womensafetyapp.MainActivity" android:label="@strin
g/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.prabhu.womensafetyapp.Register" android:label="@string/title
_activity_register" android:parentActivityName="com.prabhu.womensafetyapp.MainActivity
">
<meta-
data android:name="android.support.PARENT_ACTIVITY" android:value="com.prabhu.wo
mensafetyapp.MainActivity"/>
</activity>
<activity android:name="com.prabhu.womensafetyapp.Display" android:label="@string/title
_activity_display" android:parentActivityName="com.prabhu.womensafetyapp.MainActivity
">
<meta-
data android:name="android.support.PARENT_ACTIVITY" android:value="com.prabhu.wo
mensafetyapp.MainActivity"/>
</activity>
<service android:name="com.prabhu.womensafetyapp.BgService"/>
<activity android:name="com.prabhu.womensafetyapp.Instructions" android:label="@string/
title_activity_instructions" android:parentActivityName="com.prabhu.womensafetyapp.Main
Activity">
<meta-
data android:name="android.support.PARENT_ACTIVITY" android:value="com.prabhu.wo
mensafetyapp.MainActivity"/>
</activity>
<activity android:name="com.prabhu.womensafetyapp.Verify" android:label="@string/title_
activity_verify" android:parentActivityName="com.prabhu.womensafetyapp.MainActivity">
<meta-
data android:name="android.support.PARENT_ACTIVITY" android:value="com.prabhu.wo
mensafetyapp.MainActivity"/>
</activity>
</application>
</manifest>

AccelerometerManager.java

package com.prabhu.womensafetyapp;

import java.util.List;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.widget.Toast;
public class AccelerometerManager {

private static Context aContext=null;

/** Accuracy configuration */


private static float threshold = 15.0f;
private static int interval = 200;

private static Sensor sensor;


private static SensorManager sensorManager;
// you could use an OrientationListener array instead
// if you plans to use more than one listener
private static AccelerometerListener listener;

/** indicates whether or not Accelerometer Sensor is supported */


private static Boolean supported;
/** indicates whether or not Accelerometer Sensor is running */
private static boolean running = false;

/**
* Returns true if the manager is listening to orientation changes
*/
public static boolean isListening() {
return running;
}

/**
* Unregisters listeners
*/
public static void stopListening() {
running = false;
try {
if (sensorManager != null && sensorEventListener != null) {
sensorManager.unregisterListener(sensorEventListener);
}
} catch (Exception e) {}
}

/**
* Returns true if at least one Accelerometer sensor is available
*/
public static boolean isSupported(Context context) {
aContext = context;
if (supported == null) {
if (aContext != null) {

sensorManager = (SensorManager) aContext.


getSystemService(Context.SENSOR_SERVICE);

// Get all sensors in device


List<Sensor> sensors = sensorManager.getSensorList(
Sensor.TYPE_ACCELEROMETER);

supported = new Boolean(sensors.size() > 0);

} else {
supported = Boolean.FALSE;
}
}
return supported;
}

/**
* Configure the listener for shaking
* @param threshold
* minimum acceleration variation for considering shaking
* @param interval
* minimum interval between to shake events
*/
public static void configure(int threshold, int interval) {
AccelerometerManager.threshold = threshold;
AccelerometerManager.interval = interval;
}

/**
* Registers a listener and start listening
* @param accelerometerListener
* callback for accelerometer events
*/
public static void startListening( AccelerometerListener accelerometerListener )
{

sensorManager = (SensorManager) aContext.


getSystemService(Context.SENSOR_SERVICE);

// Take all sensors in device


List<Sensor> sensors = sensorManager.getSensorList(
Sensor.TYPE_ACCELEROMETER);

if (sensors.size() > 0) {

sensor = sensors.get(0);

// Register Accelerometer Listener


running = sensorManager.registerListener(
sensorEventListener, sensor,
SensorManager.SENSOR_DELAY_GAME);

listener = accelerometerListener;
}

}
/**
* Configures threshold and interval
* And registers a listener and start listening
* @param accelerometerListener
* callback for accelerometer events
* @param threshold
* minimum acceleration variation for considering shaking
* @param interval
* minimum interval between to shake events
*/
public static void startListening(
AccelerometerListener accelerometerListener,
int threshold, int interval) {
configure(threshold, interval);
startListening(accelerometerListener);
}

/**
* The listener that listen to events from the accelerometer listener
*/
private static SensorEventListener sensorEventListener =
new SensorEventListener() {

private long now = 0;


private long timeDiff = 0;
private long lastUpdate = 0;
private long lastShake = 0;

private float x = 0;
private float y = 0;
private float z = 0;
private float lastX = 0;
private float lastY = 0;
private float lastZ = 0;
private float force = 0;

public void onAccuracyChanged(Sensor sensor, int accuracy) {}

public void onSensorChanged(SensorEvent event) {


// use the event timestamp as reference
// so the manager precision won't depends
// on the AccelerometerListener implementation
// processing time
now = event.timestamp;

x = event.values[0];
y = event.values[1];
z = event.values[2];

// if not interesting in shake events


// just remove the whole if then else block
if (lastUpdate == 0) {
lastUpdate = now;
lastShake = now;
lastX = x;
lastY = y;
lastZ = z;
Toast.makeText(aContext,"No Motion detected",
Toast.LENGTH_SHORT).show();

} else {
timeDiff = now - lastUpdate;

if (timeDiff > 0) {

/*force = Math.abs(x + y + z - lastX - lastY - lastZ)


/ timeDiff;*/
force = Math.abs(x + y + z - lastX - lastY - lastZ);

if (Float.compare(force, threshold) >0 ) {


//Toast.makeText(Accelerometer.getContext(),
//(now-lastShake)+" >= "+interval, 1000).show();

if (now - lastShake >= interval) {

// trigger shake event


listener.onShake(force);
}
else
{
Toast.makeText(aContext,"No Motion detected.",
Toast.LENGTH_SHORT).show();

}
lastShake = now;
}
lastX = x;
lastY = y;
lastZ = z;
lastUpdate = now;
}
else
{
Toast.makeText(aContext,"No Motion detected", Toast.LENGTH_SHORT).show();

}
}

// trigger change event


listener.onAccelerationChanged(x, y, z);
}

};

AccelerometerListener.java
package com.prabhu.womensafetyapp;

public interface AccelerometerListener {

public void onAccelerationChanged(float x, float y, float z);

public void onShake(float force);

Output: -
REFERENCE
1. https://projectworlds.in/android-projects-with-source-code/women-safety-app-
android-project-source-code/

2. https://www.ijraset.com/research-paper/an-android-based-women-safety-app

You might also like