MANET- Disaster Management

43
Page 1 of 43 INTRODUCTION Mobile telephony has become available to all and has become a common matter in the recent years. This is a huge success in the fields of technology and commercial enterprise. Devices have gradually become smaller, and at the same time more powerful, offering a multitude of features to the user, and a whole set of networking options. Today, the least we expect from our phone is the capability to ring someone, regardless of time and location. Besides the services like sms, mms people can remain connected with each other through Facebook, Twitter, WhatsApp, and Skype if they own a mobile phone. Even a PC is not required. A person can surf the internet at anytime from anywhere. However, this is not always possible. In case of a natural disaster all the pre-existing infrastructures may get affected. If communication system fails relief work is adversely affected. Disaster monitoring is one of the most challenging applications in wireless ad-hoc networks as establishing infrastructure-based networks are neither feasible nor suitable in those environments. As disaster strikes suddenly therefore advance planning to manage such situations is necessary to minimize its effect. Basic information about an area (may be disaster-prone area) should be always available with the disaster management authorities. For example information about hospitals, blood banks, police stations, fire stations should be stored in a database. Detailed map of a city or area should also be there. With a well designed ad hoc network system, the real scenarios of post disaster could be monitored promptly, and as per that action can be taken to save the lives of victims or minimize the losses. Reliable delivery of monitoring message is one of the key requirements in disaster management systems along with energy saving. Message reliability improves the performance of the system. Mobile ad hoc network (MANET) is one of the most popular wireless network used in the area; where establishing other type of network is either dicult or infeasible. An application using detailed information of a disaster-hit area and MANET is highly required during relief works.

description

Disaster management using MANET

Transcript of MANET- Disaster Management

Page 1: MANET- Disaster Management

Page 1 of 43

INTRODUCTION

Mobile telephony has become available to all and has become a common matter in the recent years. This is a huge success in the fields of technology and commercial enterprise. Devices have gradually become smaller, and at the same time more powerful, offering a multitude of features to the user, and a whole set of networking options. Today, the least we expect from our phone is the capability to ring someone, regardless of time and location. Besides the services like sms, mms people can remain connected with each other through Facebook, Twitter, WhatsApp, and Skype if they own a mobile phone. Even a PC is not required. A person can surf the internet at anytime from anywhere. However, this is not always possible. In case of a natural disaster all the pre-existing infrastructures may get affected. If communication system fails relief work is adversely affected. Disaster monitoring is one of the most challenging applications in wireless ad-hoc networks as establishing infrastructure-based networks are neither feasible nor suitable in those environments. As disaster strikes suddenly therefore advance planning to manage such situations is necessary to minimize its effect. Basic information about an area (may be disaster-prone area) should be always available with the disaster management authorities. For example information about hospitals, blood banks, police stations, fire stations should be stored in a database. Detailed map of a city or area should also be there. With a well designed ad hoc network system, the real scenarios of post disaster could be monitored promptly, and as per that action can be taken to save the lives of victims or minimize the losses. Reliable delivery of monitoring message is one of the key requirements in disaster management systems along with energy saving. Message reliability improves the performance of the system. Mobile ad hoc network (MANET) is one of the most popular wireless network used in the area; where establishing other type of network is either difficult or infeasible. An application using detailed information of a disaster-hit area and MANET is highly required during relief works.

Page 2: MANET- Disaster Management

Page 2 of 43

CHAPTER 1

1.1 Problem Statement: A Mobile Ad-hoc Network Based Disaster Management System using Android platform

1.2 Problem Definition: This project is mainly about developing a MANET-based application that will help rescuers during disasters. This application will be applicable to natural disasters because MANETS are highly insecure and applications to be used in man-made disasters like war etc need high security. Our project deals only with natural disasters like flood, cyclone, landslides, earthquakes etc.

1.3 Objective: Our aim is to develop a MANET-based application that will allow any rescuer to get or provide help at a disaster-hit location. The application is based on a wireless platform that will allow rescuers to search for nearest hospitals, blood banks, fire stations and police stations. The rescuers would also be able to contact each other and provide primary first aid based on the information available in the application. They can search for the shortest path between their current location and their destination. The application will be using MANET architecture because it needs no pre-defined or already existing infrastructure in the disaster-hit zone.

1.4 Tools and Platforms: Android Developer Toolkit bundle was used for designing and coding in Java. The application is developed for Android Jellybean 4.2.2 platform (API 17).

1.5 Brief Discussion on Problem: Mobile computing is human-computer interaction by which a device is expected to be transported during normal usage. It involves mobile communication, mobile hardware and mobile software. Communication issues include ad-hoc and infrastructure networks. A mobile ad-hoc network (MANET) is a self-configuring infrastructure-less network of mobile devices connected by wireless medium. Each device in a MANET is free to move independently in any direction, and will therefore change its links to other devices frequently.

Wireless mobile technology is used for disaster management because of its wide usages. In a post-disaster environment, some important pre-existing infrastructure may get disrupted. For example, the mobile towers deployed in various places can get damaged. So communication using mobile phones is not possible. Internet connection also may not be available. So in such conditions emergency rescue operation is very critical to numerous lives. Many people trapped in the disastrous areas under collapsed buildings or landslides may have a large chance to survive if they are rescued in 72 hours, referred as "Golden 72Hours". People evacuated from their home jammed in shelters need life support material to support their lives. They also need to communicate to each other for various reasons such as allocation of rescue and relief resource as well as reunion of family members. So an emergency temporary communication system is required and also basic information about those areas and first aid are also required.

Page 3: MANET- Disaster Management

Page 3 of 43

CHAPTER 2 Literature Survey:

• In “A Proposed Architecture of MANET for Disaster Area Architecture”, published in International Journal of Computer Theory and Engineering, Vol. 2 on 1st February 2011 R.P.Mahapatra, Tanvir Ahmad Abbasi and Mohd Suhaib Abbasi have proposed that in case of a disaster, when the conventional backbones of communications such as the base stations fail, an ad-hoc network will be very helpful. The ad-hoc network will help the victims communicate with each other without the need of a conventional infrastructure.

• In his paper “A Mobile Ad Hoc Network Implementation for Android Smartphone”, published on July 26, 2012 David Flanagan talks about the feasibility of implementing an Ad hoc network using Smartphones with an android platform.

• In the paper “Rescue Information System for Earthquake Disasters Based on MANET Emergency Communication Platform “Hung-Chin Jang Yao-Nan Lien Tzu-Chieh Tsai Department of Computer Science, National Chengchi University a detailed information about post disaster situations, the importance of a temporary communication system during relief work and the kinds of basic information required during rescuing victims.

• The book “Professional Android Application Development by Roto Meier”, 5th edition published by. John Wiley & Sons helped us to begin with android.

• “Total Beginner Companion Document”, by Mark Dexter helped us during the initial days of implementation of the application.

Page 4: MANET- Disaster Management

Page 4 of 43

CHAPTER 3

Concepts and Problem Analysis: The Manet-based Disaster Management System helps the rescuers to find the nearest hospitals, blood banks, police stations and fire stations, when there is no existing cellular network present. They can search for the first aids to be used on general injuries suffered by the victims. The rescuers can also find the shortest paths to their destinations from the locations they are present at. They will be able to communicate with each other using Mobile ad hoc networking or MANET. The impact of communication system failure to a disaster could be catastrophic, making the coordination among a large number of disorganized disaster response workers extremely difficult. Unfortunately, rapid deployment of an emergency communication system based on existing technologies may not be feasible since most technologies rely on a good transportation system, which is usually not available in a catastrophic natural disaster, to deliver essential equipments.

Causes that disrupts Communication Systems: • Base stations may crash.

• Trunks connecting base stations to MSCs can be broken almost everywhere, especially broken roads and bridges (Trunks were laid along roads and bridges).

• Backup power generators may be out because of fuel will get exhausted.

• Critical hardware equipments will be down because cooling towers may fall down or cooling pipes may be broken. Impact of communication system failure:

1. In a catastrophic disaster, regular rescue teams including trained professional rescue squads, police, army, and fire fighters were far from sufficient for the emergency rescue mission. A large number of volunteers must be mobilized to participate in the rescue operation. However, without a good communication system, it is very difficult to organize and coordinate rescue volunteers.

2. A large volume of rescue and relief resources were misplaced because the assessment of disasters distribution is virtually blind and inaccurate in the early hours of relief work. As a consequence, the higher accessibility a stricken spot, the easier to receive external resources. Unfortunately, reallocation of resources may not be possible because of paralyzed transportation systems. For example, in SiChuan Earthquake, some soldiers were even dropped to the disaster areas by parachutes. It is impossible to reallocate them if they were misplaced. Misplacement of rescue and relief resources may lead to catastrophic consequence. Each stricken spot may have many vulnerable survivals, such as injured people, babies and hospital patients, whose lives are highly dependent on relief resources. Misplacement of demanded medical equipments and supplies as well as life-support resources could cost numerous lives.

3. Trained and skill-specific professional rescue squads get misplaced to wrong spots. For instances, a professional rescue squad specially trained and equipped for detecting survivals trapped under collapsed buildings may be sent to a spot where there is no trapped survivals.

4. Some injured people may die after being rescued because of ambulance not available or being sent to over-saturated hospitals or lack of first aid.

The complete list may be much longer than what we mentioned above. Thus it is clear that without the existence of a temporary ah-hoc wireless communication system and lack of knowledge about the disaster-hit areas hamper rescue work. In our attempt to create a MANET based Disaster Management System we have tried to create a database that may provide useful information about a disaster-hit area like information about hospitals, blood banks, police stations, fire stations, medical camps set up for rescue work. We have also tried to give shortest path to a destination from a given location so that rescue workers can follow that path. We have taken the help of ANDROID platform to implement these goals.

Why Android Platform? 1. In disaster-hit areas the only possible means of communication is an ad hoc network consisting of mobile node example a

mobile phone. Android is a light-weight mobile Operating System providing a large number of features. It allows user to create applications at his/her will.

2. We have used SQLiteDatabase to store the information. 3. Android phones are cheaper than other phones like Windows phones and are easily available.

Page 5: MANET- Disaster Management

Page 5 of 43

4. Since in disaster hit areas the power supply is also disrupted so the nodes used in rescue work should use minimum power. Since Android is a light-weight mobile OS so it consumes lesser power.

Formation of ad hoc network:

For the formation of ad hoc network we have three choices- 1 .Using Wi-Fi enabled phones (by using Wi-Fi direct) 2. Using Bluetooth 3. Using ManetManager application which is based on Android platform.

Using any one of the options mentioned above a MANET can be formed. a MANE-based group communication system to support emergency communication and information network, called P2Pnet. P2Pnet is a serverless peer-to-peer communication network based on MANET to support temporary group communication and information access. As depicted in Figure 1 some nodes may have satellite communication capability performing gateway functions so that all other nodes can access Internet through gateways if they are available.

Figure 1

We have developed the application keeping in mind the following assumptions:

1. In a post-disaster environment, after getting relevant information from the database, the rescuers can communicate with each other within a given range, assisting each other by using an ad-hoc network on their mobile devices.

2. The other problems with MANET are its limited transmission range and limited battery life of devices. It is assumed that

there will be portable generators and chargers available to charge the mobile devices.

Page 6: MANET- Disaster Management

Page 6 of 43

CHAPTER 4

Design and Methodology:

The design and methodology part may be divided into four sections:

1) Algorithm to find the shortest path

2) User Interface

3) SQLiteDatabase

4) Intents

Algorithm to find the shortest path:

In this application we need to find the shortest path from any point to any another destination. This will be used by the rescuers during relief work to find the shortest path to their destinations.

Algorithms those are available to find shortest path-

I. Bellman Ford algorithm

II. Dijkstra’s algorithm

III. Flyod-Warshall

IV. Johnson’s algorithm

V. Viterbi’s algorithm

We have used Floyd-Warshall’s algorithm to compute the shortest path for the following reasons-

A. Bellman-Ford’s algorithm is a single-source shortest path algorithm. But we need to find shortest path between any two pair of points.

B. Dijkstra’s algorithm is a single-source shortest path algorithm. But we need to find shortest path between any two pair of points and also it is difficult to implement.

C. Johnson’s algorithm is an all-pairs shortest path algorithm. But it uses three algorithms: i) Bellman-Ford ii) Dijkstra iii) Floyd-Warshall

D. Viterbi algorithm is a dynamic algorithm, but was not used because of its implementation difficulties.

Thus, Flyod-Warshall is used because its’ concept and implementation are simple though its time complexity is O (n^3) (where n= no of nodes).

A screenshot of our application for find the shortest path and the pseudo code of Flyod-Warshall are given in next page.

Page 7: MANET- Disaster Management

Figure 2

The User Interface:

The user interface of our application has been designed using:

1. Drop-down menus 2. Buttons 3. Text boxes 4. Tabs

Drop-down menu:

A drop-down menu can be formed using the spinner class available in the android.widget package. Spinner is a view that displays one child at a time and lets the user pick among them.

We have used the data present in the cursorwe have used an instance of ArrayAdapter class,the same class.

To read the item selected by user from spinner we have used public Object getSelectedItem() method.

Figure 3

Button:

A button can be created by using the Button class available in the android.widget package.push-button widget. Push-buttons can be pressed, or clicked, by the user to perform an action.

cation has been designed using:

spinner class available in the android.widget package. Spinner is a view that displays one child at a time and lets the user pick among them. A spinner looks like the following:

We have used the data present in the cursor (i.e. data from database) to popwe have used an instance of ArrayAdapter class, the method setArrayAdapter(int resource)method of the same class.

To read the item selected by user from spinner we have used public Object getSelectedItem() method.

A button can be created by using the Button class available in the android.widget package. An object of the Button class represents a buttons can be pressed, or clicked, by the user to perform an action.

1 let dist be a |V| × |V| array of minimum

distances initialized to ∞ (infinity)

2 for each vertex v

3 dist[ v][ v] ← 0

4 for each edge ( u, v)

5 dist[ u][ v] ← w( u, v) // the weight of the

edge (u,v)

6 for k from 1 to |V|

7 for i from 1 to |V|

8 for j from 1 to |V|

9 if dist[ i][ j] > dist[ i][ k] +

dist[ k][ j]

10 dist[ i][ j] ← dist[ i][ k] +

dist[ k][ j]

11 end if

Page 7 of 43

spinner class available in the android.widget package. Spinner is a view that displays one A spinner looks like the following:

data from database) to populate the spinner. To do this the method setArrayAdapter(int resource)method of

To read the item selected by user from spinner we have used public Object getSelectedItem() method.

ect of the Button class represents a

Page 8: MANET- Disaster Management

Page 8 of 43

Using an OnClickListener: To declare the event handler programmatically, create an View.OnClickListener object and assign it to the button by calling setOnClickListener(View.OnClickListener).

For example: Button button =(Button)findViewById(R.id.button_send); button.setOnClickListener(newView.OnClickListener(){ publicvoid onClick(View v){ // Do something in response to button click } }); Text boxes: Text boxes can be created using the TextField class and EditText class available in android.widget package. Displays text to the user and optionally allows them to edit it. A TextView is a complete text editor; however the basic class is configured to not allow editing. EditText is a thin veneer over TextView that configures itself to be editable.

Tabs:

Tabs can be created by extending the FragmentActivity class. A Fragment represents a behavior or a portion of user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities. You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running (sort of like a "sub activity" that you can reuse in different activities).

final FragmentActivity getActivity() Return the Activity this fragment is currently associated with.

final FragmentManager getFragmentManager() Return the FragmentManager for interacting with fragments associated with this fragment's activity.

Public Methods

Void Void

addTab(TabHost.TabSpec tabSpec) Add a tab. onActivityCreated (Bundle savedInstanceState) Called when the fragment's activity has been created and this fragment's view hierarchy instantiated. It can be used to do final initialization once these pieces are in place, such as retrieving views or restoring state. It is also useful for fragments that use setRetainInstance(boolean) to retain their instance, as this callback tells the fragment when it is fully associated with the new activity instance. This is called after onCreateView(LayoutInflater,ViewGroup,Bundle) .

Toast A toast provides a simple feedback about an operation in a small pop-up. It only fills the space needed to display the message and the current activity remains visible and interactive. For example navigating away from email account before an email is sent triggers a “saved to drafts” toast. A toast disappears automatically after timeout.

Page 9: MANET- Disaster Management

Page 9 of 43

For Example: Context context = getApplicationContext(); CharSequence text = "Hello toast!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show();

Public void onClick(View V) { Intent explicitIntent=new Intent(mainActivity.this,second.class); startActivity(explicitIntent);}

SQLiteDatabase:

In our application we are accessing a SQLiteDatabase which has the following tables-

contacts_details_hospitals- This table contains basic information about the hospitals/nursing homes of an area. The complete schema of the table is: contact_details_hospitals (c_id, center_name, center_facilities, center_location, center_phone_no)

Data type of the fields-

• c_id: Integer

• center_name: String • center_facilities: String

• center_location: String

• center_phone_no: String

BLOODBANKS- This table contains the basic details about the blood banks in an area. The complete schema of this table is:

BLOODBANKS (bcode, blood_group, available, bloodbankaddress, phone_no)

Data types of the fields-

• bcode: Integer

• blood_group : String

• available: String

• bloodbankaddress: String

• phone_no: String

FIRESTATIONS- This table contains the basic details about the fire stations in an area. The complete schema of this table is:

FIRESTATIONS (fcode, acode, aname,fadd, fphone_no)

Data types of the fields-

• fcode: Integer

• acode: String

• fadd: String

• fphone_no: String

Page 10: MANET- Disaster Management

Page 10 of 43

POLICESTATIONS- This table contains the basic details about the police station in an area. The complete schema of this table is:

POLICESTATIONS (code, location, areacode, name, phone_no)

Data types of the fields-

• code: Integer

• location: String

• areacode: Integer

• name: String

• phone_no: String

FIRST_AID_BOX- This table contains the basic details about first aid. The complete schema of this table is:

FIRST_AID_BOX (aid_code, injury, aid_required)

Data types of the fields-

• aid_code: Integer

• injury: String

• aid_required: String

AREA_CODE- This table contains the area codes and area names. The complete schema of this table is:

AREA_CODE (area_code, area_name)

Data types of the fields-

• area_code: Integer

• area_name: String

CAMPS- This table contains the basic details about the medical camps set up for relief work in an area. The complete schema of this table is:

CAMPS (camp_code, camp_area, location).

Data types of the fields -

• camp_code: Integer

• camp_area: String

• location: String

Page 11: MANET- Disaster Management

Page 11 of 43

SQLiteOpenHelper class: We used the SQLiteOpenHelper class to create the database.A helper class to manage database creation and version management. A list of constructors and methods of this class used here is as follows-

SQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version)

Create a helper object to create, open, and/or manage a database.

Public Methods

SQLiteDatabase getReadableDatabase() Create and/or open a database.

SQLiteDatabase getWritableDatabase() Create and/or open a database that will be used for reading and writing.

abstract void onCreate(SQLiteDatabase db) Called when the database is created for the first time.

Void onOpen(SQLiteDatabase db) Called when the database has been opened.

abstract void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) Called when the database needs to be upgraded.

Cursor Class: To get the values fetched from database we have used object of the Cursor class. The methods of this class used here are listed below-

Public Methods

abstract int getCount() Returns the numbers of rows in the cursor.

abstract String getString(int columnIndex) Returns the value of the requested column as a String.

abstract Boolean

moveToFirst() Move the cursor to the first row.

abstract Boolean

moveToNext() Move the cursor to the next row.

Intents:

In order to move between pages we have used objects of class Intent. In order to share text messages we have taken the help of Intent type objects. Intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an Activity. Intent provides a facility for performing late runtime binding between the codes in different applications. Its most significant use is in the launching of activities, where it can be thought of as the glue between activities. It is basically a passive data structure holding an abstract description of an action to be performed.

The standard action defined by Intent for launching activities (usually through startActivity (Intent))used in our application is ACTION_SEND .This has been used to share text messages. This is an implicit intent.

We have used explicit intents to define the exact class to be run.

Page 12: MANET- Disaster Management

Page 12 of 43

Get started with our application:

Figure 4.1

This is the opening page of ‘The Manet-based Disaster Management System’. The different options are being shown tab-wise. The different options are ‘First Aid’, ‘Help Desk’, ‘Message’ and ‘Shortest Path’. The tab ‘First Aid’ redirects to the First Aid database that shows the first aid to be given for different injuries, whereas the ‘Help Desk’ shows the list of different hospitals, nursing homes, blood banks, fire stations, police stations and medical camps. The ‘Message’ tab helps rescuers communicate with each other via Bluetooth messaging. The rescuers can find the shortest path between their source and desired destination with the help of Floyd-Warshall algorithm.

Page 13: MANET- Disaster Management

Page 13 of 43

Figure 4.2

Figure 4.3

The First Aid option in the tab gives the user access to the First Aid database that shows the different first aids to be given in case of different injuries. This will allow the rescuers to save time by giving the victims the primary first aid.

The ‘Help Desk’ tab will show the options- Hospitals, Nursing Homes, Blood Banks, Fire Stations, Police Stations and Medical Camps. With the clicking of the options under the tab ‘Help Desk’, the application accesses the database to show the list of Hospitals, Nursing Homes, Blood Banks, Fire Stations, Police Stations and Medical Camps available near the disaster stricken area.

Page 14: MANET- Disaster Management

Page 14 of 43

Figure 4.4

Figure 4.5

The ‘Help Desk’ tab shows the option ‘Hospitals/Nursing Homes’. On selecting that option, the user can see the list of hospitals/ nursing homes in the disaster stricken area. The database also shows the location of the facility, its phone number and the facilities available.

The ‘Police Station’ option under the ‘Help Desk’ tab shows the Police Stations in the given location. The database shows the phone number, the area and the location of the police station.

Page 15: MANET- Disaster Management

Page 15 of 43

Figure 4.6

Figure 4.7

The ‘Medical Camp’ option under the ‘Help Desk’ tab will show the area and the location of the medical camps set up in the disaster stricken area.

The ‘Blood Bank’ option under the ‘Help Desk’ tab will show the list of blood banks available in the disaster stricken area. It will show the blood groups available, location and the phone number of the facility. It will also show whether blood is available at the facility.

Page 16: MANET- Disaster Management

Page 16 of 43

Figure 4.8

The ‘Fire Stations’ database will be accessed on selecting the ‘Fire Stations’ option available under the ‘Help Desk’ tab. It will show the Area, Location and Phone number of the fire stations in the area.

Page 17: MANET- Disaster Management

Page 17 of 43

The screenshots for text message transfer are as follows:

Figure 4.9

Page 18: MANET- Disaster Management

Page 18 of 43

CHAPTER 5

Sample Code:

Code to create database and populate the database with data:

import android.os.Bundle; import android.os.Environment; import android.app.Activity; import android.view.Menu; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); newhandler db=new newhandler(this); db.addarea(new Area("Khidderpore")); db.addarea(new Area("bodyguard")); db.addarea(new Area("CMRI")); db.addarea(new Area("National Library")); db.addContact(new contactz("super speciality","cmri","iqbalpore","12345")); db.addContact(new contactz("no emergency","kothari","iqbalpore","12346")); db.addaid(new FirstAid("1","burn","burnol+")); db.addbloodbank(new Bloodbank("A+" ,"yes","iqbalpore","12345")); db.addfirestation(new firestation(1,"khidderpore","near khidderpore crossing","6789")); db.addcamp(new camp("khidderpore","beside bodyguard lines")); db.addpolicestation(new policestation("beside zoo","1","alipore","12345")); db.close(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } package com.example.newversion; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.content.ContentValues; import android.content.Context; public class newhandler extends SQLiteOpenHelper { private static final int DATABASE_VERSION=1; private static final String DATABASE_NAME1="disaster_databasefinaltests2"; private static final String TABLE_NAME="contact_details_hospitals"; private static final String center_id="c_id"; private static final String center_facilities="center_facilities"; private static final String center_name="center_name"; private static final String center_location="area"; private static final String center_ph_no="phone_no"; private static final String TABLE_NAME1="FIRST_AID_BOX"; private static final String aid_code="aid"; private static final String injury="type_of_injury"; private static final String aid_required="solution"; private static final String TABLE_NAME2="AREA_CODE"; private static final String area_code="code";

Page 19: MANET- Disaster Management

Page 19 of 43

private static final String area_name="name"; private static final String TABLE_NAME3="BLOODBANKS"; private static final String bcode="bcode"; private static final String blood_group="blood_group"; private static final String available="available"; private static final String bloodbankaddress="bloodbankaddress"; private static final String phone_no="phone_no1"; private static final String TABLE_NAME4="FIRESTATIONS"; private static final String fcode="fcode"; private static final String acode="acode"; private static final String aname="aname"; private static final String fadd="fadd"; private static final String fphone_no="fphone_no"; private static final String TABLE_NAME5="CAMPS"; private static final String camp_area_code="camp_code"; private static final String camp_area_name="camp_area"; private static final String camp_location="location"; private static final String TABLE_NAME6="POLICESTATIONS"; private static final String policestation_code="code"; private static final String location="location"; private static final String areacode="areacode"; private static final String areaname="name"; private static final String p_phone_no="phone_no"; private static final String TABLE_NAME7="ROADS"; private static final String route_no="route"; private static final String sourcenode="source"; private static final String destnode="dest"; private static final String weight="length"; private static final String GoTo="towards"; public newhandler(Context context) { super(context,"/storage/extSdCard/DB"+ "/" + DATABASE_NAME1,null,DATABASE_VERSION); } public void onCreate(SQLiteDatabase db) { String CREATE_AREA_CODE_TABLE="CREATE TABLE "+TABLE_NAME2+"("+area_code+" INTEGER PRIMARY KEY,"+area_name+" TEXT"+ " );"; db.execSQL(CREATE_AREA_CODE_TABLE); String CREATE_CONTACTS_TABLE="CREATE TABLE "+TABLE_NAME+"("+center_id+" INTEGER PRIMARY KEY,"+center_facilities+" TEXT,"+center_name+" TEXT,"+center_location+" TEXT,"+center_ph_no+" TEXT"+ " );"; db.execSQL(CREATE_CONTACTS_TABLE); String CREATE_FIRSTAID_TABLE="CREATE TABLE "+TABLE_NAME1+"("+aid_code+" INTEGER PRIMARY KEY,"+injury+" TEXT,"+aid_required+" TEXT"+ " );"; db.execSQL(CREATE_FIRSTAID_TABLE); String CREATE_BLOODBANK_TABLE="CREATE TABLE "+TABLE_NAME3+"("+bcode+" INTEGER PRIMARY KEY,"+blood_group+" TEXT,"+available+" TEXT,"+bloodbankaddress+" TEXT,"+phone_no+" TEXT"+" );"; db.execSQL(CREATE_BLOODBANK_TABLE); String CREATE_FIRESTATIONS_TABLE="CREATE TABLE "+TABLE_NAME4+"("+fcode+" INTEGER PRIMARY KEY,"+acode+" INTEGER,"+aname+" TEXT,"+fadd+" TEXT,"+fphone_no+" TEXT"+" );"; db.execSQL(CREATE_FIRESTATIONS_TABLE); String CREATE_CAMP_TABLE="CREATE TABLE "+TABLE_NAME5+"("+camp_area_code+" INTEGER PRIMARY KEY AUTOINCREMENT,"+camp_area_name+" TEXT,"+camp_location+" TEXT"+" );";

Page 20: MANET- Disaster Management

Page 20 of 43

db.execSQL(CREATE_CAMP_TABLE); String CREATE_TABLE_POLICESTATIONS="CREATE TABLE "+TABLE_NAME6+"("+policestation_code+" INTEGER PRIMARY KEY,"+location+" TEXT,"+areacode+" TEXT,"+areaname+" TEXT,"+p_phone_no+" TEXT"+" );"; db.execSQL(CREATE_TABLE_POLICESTATIONS); String CREATE_TABLE_ROUTES="CREATE TABLE "+TABLE_NAME7+"("+route_no+" INTEGER PRIMARY KEY,"+sourcenode+" INTEGER,"+destnode+" INTEGER,"+weight+" INTEGER,"+GoTo+" TEXT"+ " );"; db.execSQL(CREATE_TABLE_ROUTES); } public void onUpgrade(SQLiteDatabase db,int oldversion,int newversion) { db.execSQL("DROP TABLE IF EXISTS"+TABLE_NAME); db.execSQL("DROP TABLE IF EXISTS"+TABLE_NAME1); db.execSQL("DROP TABLE IF EXISTS"+TABLE_NAME2); db.execSQL("DROP TABLE IF EXISTS"+TABLE_NAME3); db.execSQL("DROP TABLE IF EXISTS"+TABLE_NAME4); db.execSQL("DROP TABLE IF EXISTS"+TABLE_NAME4); db.execSQL("DROP TABLE IF EXISTS"+TABLE_NAME5); db.execSQL("DROP TABLE IF EXISTS"+TABLE_NAME6); db.execSQL("DROP TABLE IF EXISTS"+TABLE_NAME7); onCreate(db); } public void addContact(contactz c) { SQLiteDatabase db=this.getWritableDatabase(); ContentValues values=new ContentValues(); values.put(center_facilities,c.getType()); values.put(center_name,c.getName()); values.put(center_location,c.getLocation()); values.put(center_ph_no,c.getPh_no()); db.insert(TABLE_NAME,null,values); } public void addaid(FirstAid a){ SQLiteDatabase db1=this.getWritableDatabase(); ContentValues valuesa=new ContentValues(); valuesa.put(injury, a.getinjury()); valuesa.put(aid_required, a.getaid()); db1.insert(TABLE_NAME1, null, valuesa); } public void addarea(Area a){ SQLiteDatabase db=this.getWritableDatabase(); ContentValues values=new ContentValues(); values.put(area_name, a.getname()); db.insert(TABLE_NAME2, null, values); } public void addbloodbank(Bloodbank b){ SQLiteDatabase db=this.getWritableDatabase(); ContentValues values=new ContentValues(); values.put(blood_group, b.getgroup()); values.put(available, b.getavaibility()); values.put(bloodbankaddress, b.getbloodbankaddress()); values.put(phone_no, b.getphno()); db.insert(TABLE_NAME3, null, values); } public void addfirestation(firestation f){ SQLiteDatabase db=this.getWritableDatabase(); ContentValues values=new ContentValues(); values.put(acode, f.getcode()); values.put(aname, f.getaname()); values.put(fadd, f.getfadd()); values.put(fphone_no, f.getfphno());

Page 21: MANET- Disaster Management

Page 21 of 43

db.insert(TABLE_NAME4, null, values); } public void addcamp(camp c) { SQLiteDatabase db=this.getWritableDatabase(); ContentValues values=new ContentValues(); //values.put(camp_area_code, c.getcode()); values.put(camp_area_name, c.getarea()); values.put(camp_location, c.getlocation()); db.insert(TABLE_NAME5, null, values); } void addpolicestation(policestation p){ SQLiteDatabase db=this.getWritableDatabase(); ContentValues values=new ContentValues(); values.put(location, p.getlocation()); values.put(areacode, p.getcode()); values.put(areaname, p.getarea()); values.put(p_phone_no, p.getphno()); db.insert(TABLE_NAME6, null, values); } public void addroute(weight r){ SQLiteDatabase db=this.getWritableDatabase(); ContentValues values=new ContentValues(); values.put(sourcenode,r.getsource() ); values.put(destnode, r.getdest()); values.put(weight, r.getwt()); values.put(GoTo, r.getgo()); db.insert(TABLE_NAME7, null, values); } public Cursor getContacts(){ String s="CMRI" ; String query ="SELECT "+area_code+" FROM "+TABLE_NAME2+" WHERE "+area_name+" LIKE '"+ s+"'"; SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(query, null); return cursor; } } package com.example.newversion; public class FirstAid { String aid_code; String injury; String aid_required; public FirstAid(String ac,String i,String ar) { this.aid_code=ac; this.injury=i; this.aid_required=ar; } public String getcode() { return this.aid_code;

Page 22: MANET- Disaster Management

Page 22 of 43

} public String getinjury() { return this.injury; } public String getaid() { return this.aid_required; } } package com.example.newversion; public class weight { public int sourcenode; public int destnode; public int weight; public String GoTo; public weight(int s,int d,int w,String g) { sourcenode=s; destnode=d; weight=w; GoTo=g; } public int getsource(){ return this.sourcenode; } public int getdest(){ return this.destnode; } public int getwt(){ return this.weight; } public String getgo() { return this.GoTo; } } package com.example.newversion; public class policestation { public String location; public String areacode; public String areaname; public String p_phone_no; public policestation(String l,String c,String n,String p) { location=l; areacode=c; areaname=n; p_phone_no=p; } public String getlocation(){ return this.location; } public String getcode(){ return this.areacode; } public String getarea(){ return this.areacode; }

Page 23: MANET- Disaster Management

Page 23 of 43

public String getphno(){ return this.p_phone_no; } } package com.example.newversion; public class firestation { public int acode; public String aname; public String fadd; public String fphone_no; public firestation(int a,String n,String fa,String p) { acode=a; aname=n; fadd=fa; fphone_no=p; } public int getcode(){ return this.acode; } public String getaname(){ return this.aname; } public String getfadd(){ return this.fadd; } public String getfphno(){ return this.fphone_no; } } package com.example.newversion; public class Area { public String area_name; public Area(String n) { // TODO Auto-generated constructor stub this.area_name=n; } public String getname() { return this.area_name; } } package com.example.newversion; public class Bloodbank { public String blood_group; public String available; public String bloodbankaddress; public String phone_no; public Bloodbank(String b,String a,String bad,String phno) { blood_group=b; available=a;

Page 24: MANET- Disaster Management

Page 24 of 43

bloodbankaddress=bad; phone_no=phno; } public String getgroup() { return this.blood_group; } public String getavaibility() { return this.available; } public String getbloodbankaddress() { return this.bloodbankaddress; } public String getphno() { return this.phone_no; } } package com.example.newversion; public class camp { public String camp_area_name; public String camp_location; public camp(String n,String l) { camp_area_name=n; camp_location=l; } public String getarea(){ return this.camp_area_name; } public String getlocation(){ return this.camp_location; } } package com.example.newversion; public class contactz { private String center_facilities; private String center_name; private String center_location; private String center_ph_no; public contactz(String ct,String cname,String cl,String cph) { this.center_facilities=ct; this.center_name=cname; this.center_location=cl; this.center_ph_no=cph; // TODO Auto-generated constructor stub } public String getType() { return this.center_facilities;

Page 25: MANET- Disaster Management

Page 25 of 43

} public String getName() { return this.center_name; } public String getLocation() { return this.center_location; } public String getPh_no() { return this.center_ph_no; } }

Code to access database and to create user interface: Code to create the Tab: package com.example.accessdatabase; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentTabHost; public class MainActivity extends FragmentActivity{ public String TABLE_NAME="contact_details_hospitals"; public String TABLE_NAME1="FIRST_AID_BOX"; public String TABLE_NAME2="AREA_CODE"; public String TABLE_NAME3=""; public String TABLE_NAME5=""; public String TABLE_NAME6=""; private FragmentTabHost mTabHost; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); mTabHost.addTab(mTabHost.newTabSpec("first").setIndicator("First Aid"),FIRSTAID.class,null); mTabHost.addTab(mTabHost.newTabSpec("hospital").setIndicator("Help Desk"),Hospitals.class,null); mTabHost.addTab(mTabHost.newTabSpec("sendmsg").setIndicator("Message"),Msg.class,null); mTabHost.addTab(mTabHost.newTabSpec("firstp").setIndicator("find path"),findingp.class,null); } public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }

Page 26: MANET- Disaster Management

Page 26 of 43

Code to form the fragment list: package com.example.accessdatabase; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; import android.support.v4.app.ListFragment; public class Hospitals extends ListFragment { public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); String[] values = new String[] { "HOSTIPALS/NURSING HOMES", "BLOOD BANKS", "FIRE STATIONS", "POLICE STATIONS", "MEDICAL CAMPS" }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1, values); setListAdapter(adapter); } public void onListItemClick(ListView l,View v, int position, long id) { String item = (String) getListAdapter().getItem(position); Context c=getActivity(); Toast.makeText(c,item, Toast.LENGTH_LONG).show(); if(item=="BLOOD BANKS"){ Intent i=new Intent(); i.setClass(getActivity(), showbloodbank.class); startActivity(i); } else if(item=="FIRE STATIONS"){ Intent i=new Intent(); i.setClass(getActivity(), showfirestation.class); startActivity(i); } else if(item=="POLICE STATIONS"){ Intent i=new Intent(); i.setClass(getActivity(), showpolice.class); startActivity(i); } else if(item=="MEDICAL CAMPS"){ Intent i=new Intent(); i.setClass(getActivity(), showmedicalcamp.class); startActivity(i); } else { Intent i=new Intent(); i.setClass(getActivity(), showhosp.class); startActivity(i); }

Page 27: MANET- Disaster Management

Page 27 of 43

} } package com.example.accessdatabase; import android.os.Bundle; import android.content.Intent; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; public class FIRSTAID extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.firstaid, container, false); Button button=(Button)view.findViewById(R.id.button1); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent explicitIntent = new Intent(); explicitIntent.setClass(getActivity(), second.class); startActivity(explicitIntent); } }); return view; } } package com.example.accessdatabase; import android.app.Activity; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.widget.TextView; public class second extends Activity{ String TABLE_NAME1="FIRST_AID_BOX"; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second); String c="/storage/extSdCard/DB" + "/" + "disaster_databasefinaltests2"; SQLiteDatabase db=SQLiteDatabase.openDatabase(c,null,0); String query = "SELECT * FROM " + TABLE_NAME1; Cursor cur=db.rawQuery(query, null); TextView show=new TextView(this); String Data=""; String headers=""; headers="\t\t\t INJURY TYPE"+"\t\t\t"+"AID REQUIRED \n\n"; if(cur.moveToFirst()) { do { String type1=cur.getString(1); String name1=cur.getString(2);

Page 28: MANET- Disaster Management

Page 28 of 43

Data=Data +"\t \t \t \t"+type1 +"\t \t \t \t"+name1+"\n\n"; }while(cur.moveToNext()); } show.setText(headers+Data); setContentView(show); db.close(); } } package com.example.accessdatabase; import android.app.Activity; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.widget.TextView; public class showhosp extends Activity { String TABLE_NAME="contact_details_hospitals"; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.shwhsp); //TextView tv=(TextView)findViewById(R.id.editText1); //tv.setText("sreyosi"); String c="/storage/extSdCard/DB" + "/" + "disaster_databasefinaltests2"; SQLiteDatabase db=SQLiteDatabase.openDatabase(c,null,0); String query = "SELECT * FROM " + TABLE_NAME; Cursor cur=db.rawQuery(query, null); TextView show=new TextView(this); String Data=""; String headers=""; headers="FACILITIES\t\t"+"NAME \t\t"+"LOCATION"+"\t\t"+"PHONE NO"+"\n\n"; if(cur.moveToFirst()) { do { String type1=cur.getString(1); String type2=cur.getString(2); String type3=cur.getString(3); String type4=cur.getString(4); Data=Data +type1 +"\t\t"+type2+"\t\t\t"+type3+"\t\t\t"+type4+"\n\n\n"; }while(cur.moveToNext()); } show.setText(headers+Data); setContentView(show); db.close(); } } package com.example.accessdatabase; import android.app.Activity; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.widget.TextView; public class showmedicalcamp extends Activity { String TABLE_NAME="CAMPS";

Page 29: MANET- Disaster Management

Page 29 of 43

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.showmedcmp); String c="/storage/extSdCard/DB" + "/" + "disaster_databasefinaltests2"; SQLiteDatabase db=SQLiteDatabase.openDatabase(c,null,0); String query = "SELECT * FROM " + TABLE_NAME; Cursor cur=db.rawQuery(query, null); TextView show=new TextView(this); String Data=""; String headers=""; headers="AREA\t\t\t\t\t"+"LOCATION "+"\n\n"; if(cur.moveToFirst()) { do { String type1=cur.getString(1); String type2=cur.getString(2); Data=Data +type1 +"\t\t\t"+type2+"\n\n\n"; }while(cur.moveToNext()); } show.setText(headers+Data); setContentView(show); db.close(); } } package com.example.accessdatabase; import android.app.Activity; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.widget.TextView; public class showpolice extends Activity{ String TABLE_NAME="POLICESTATIONS"; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.shwpol); String c="/storage/extSdCard/DB" + "/" + "disaster_databasefinaltests2"; SQLiteDatabase db=SQLiteDatabase.openDatabase(c,null,0); String query = "SELECT * FROM " + TABLE_NAME; Cursor cur=db.rawQuery(query, null); TextView show=new TextView(this); String Data=""; String headers=""; headers="LOCATION\t\t\t"+" \t\t"+"AREA\t\t\t"+"PHONE NO"+"\n\n"; if(cur.moveToFirst()) { do { String type1=cur.getString(1); String type2=cur.getString(3); String type3=cur.getString(4); Data=Data +type1 +"\t\t\t\t\t\t"+type2+"\t\t\t\t"+type3+"\n\n\n"; }while(cur.moveToNext());

Page 30: MANET- Disaster Management

Page 30 of 43

} show.setText(headers+Data); setContentView(show); db.close();

} } package com.example.accessdatabase; import android.app.Activity; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.widget.TextView; public class showfirestation extends Activity{ String TABLE_NAME="FIRESTATIONS"; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.shwfrstn); String c="/storage/extSdCard/DB" + "/" + "disaster_databasefinaltests2"; SQLiteDatabase db=SQLiteDatabase.openDatabase(c,null,0); String query = "SELECT * FROM " + TABLE_NAME; Cursor cur=db.rawQuery(query, null); TextView show=new TextView(this); String Data=""; String headers=""; headers="AREA\t\t"+"LOCATION\t\t\t"+"PHONE NO"+"\n\n"; if(cur.moveToFirst()) { do { String type1=cur.getString(2); String type2=cur.getString(3); String type3=cur.getString(4); Data=Data +type1 +"\t"+type2+"\t"+type3+"\n\n\n"; }while(cur.moveToNext()); } show.setText(headers+Data); setContentView(show); db.close(); } } package com.example.accessdatabase; import android.app.Activity; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.widget.TextView; public class showbloodbank extends Activity { String TABLE_NAME="BLOODBANKS"; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.shwblbnk); String c="/storage/extSdCard/DB" + "/" + "disaster_databasefinaltests2";

Page 31: MANET- Disaster Management

Page 31 of 43

SQLiteDatabase db=SQLiteDatabase.openDatabase(c,null,0); String query = "SELECT * FROM " + TABLE_NAME; Cursor cur=db.rawQuery(query, null); TextView show=new TextView(this); String Data=""; String headers=""; headers="BLOOD GROUP\t"+"AVAILABLE \t" +"LOCATION"+"\t"+"PHONE NO"+"\n\n"; if(cur.moveToFirst()) { do { String type1=cur.getString(1); String type2=cur.getString(2); String type3=cur.getString(3); String type4=cur.getString(4); Data=Data +"\t\t\t"+type1 +"\t\t\t\t"+type2+"\t\t\t\t"+type3+"\t\t\t\t"+type4+"\n\n\n"; }while(cur.moveToNext()); } show.setText(headers+Data); setContentView(show); db.close(); } } package com.example.accessdatabase; import java.util.ArrayList; import java.util.List; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.Button; //import android.widget.ProgressBar; import android.widget.Spinner; import android.widget.TextView; public class findingp extends Fragment { String TABLE_NAME1="AREA_CODE"; public int i,j,k,n=4,i1,j1,s1,d1; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view1 = inflater.inflate(R.layout.findpath, container, false); Spinner spinner2=(Spinner)view1.findViewById(R.id.spinner2); Spinner spinner3=(Spinner)view1.findViewById(R.id.spinner3); Button button=(Button)view1.findViewById(R.id.button2); TextView tv=(TextView)view1.findViewById(R.id.editText2); List<String> Contact=new ArrayList<String>(); String c="/storage/extSdCard/DB" + "/" + "disaster_databasefinaltests2"; SQLiteDatabase db=SQLiteDatabase.openDatabase(c,null,0); String query = "SELECT * FROM " + TABLE_NAME1; Cursor cur=db.rawQuery(query, null);

Page 32: MANET- Disaster Management

Page 32 of 43

if (cur.moveToFirst()) { do { String type=cur.getString(1); String str=type; Contact.add(str); } while (cur.moveToNext()); } cur.close(); db.close(); //String [] s={"sre"}; ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item,Contact); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner2.setAdapter(dataAdapter); ArrayAdapter<String> dataAdapter1 = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item,Contact); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner3.setAdapter(dataAdapter1); return view1; } public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Button button=(Button)getView().findViewById(R.id.button2); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v1) { String TABLE_NAME2="ROADS"; String area_name="name"; String area_code="code"; String TABLE_NAME1="AREA_CODE"; String temp=""; int w[][]= new int[][]{ {0,5,99,10}, {5,0,3,99}, {99,3,0,1}, {10,99,1,0} }; int pre[][]=new int[][]{ {0,1,99,1}, {2,0,2,99}, {99,3,0,3}, {99,99,4,0} }; int path[]=new int[4]; Spinner spinner2=(Spinner)getView().findViewById(R.id.spinner2); Spinner spinner3=(Spinner)getView().findViewById(R.id.spinner3); TextView tv=(TextView)getView().findViewById(R.id.editText2); String s=spinner2.getSelectedItem().toString(); String d=spinner3.getSelectedItem().toString(); String c="/storage/extSdCard/DB" + "/" + "disaster_databasefinaltests2"; SQLiteDatabase db=SQLiteDatabase.openDatabase(c,null,0); String query1="SELECT "+area_code+" FROM "+TABLE_NAME1+" WHERE "+area_name+" LIKE '"+ s+"'" ; Cursor cur=db.rawQuery(query1, null); if(cur.moveToFirst()) {

Page 33: MANET- Disaster Management

Page 33 of 43

temp=cur.getString(0); } s1=Integer.parseInt(temp); String n1=temp; cur.close(); db.close(); String c1="/storage/extSdCard/DB" + "/" + "disaster_databasefinaltests2"; SQLiteDatabase db1=SQLiteDatabase.openDatabase(c1,null,0); String query2="SELECT "+area_code+" FROM "+TABLE_NAME1+" WHERE "+area_name+" LIKE '"+ d+"'"; Cursor cur2=db1.rawQuery(query2, null); if(cur2.moveToFirst()) { temp=cur2.getString(0); } d1=Integer.parseInt(temp); cur2.close(); db1.close(); String cf="/storage/extSdCard/DB" + "/" + "disaster_databasefinaltests2"; for(k=0;k<n;k++) { for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(w[i][ j]>(w[i][ k]+w[k][ j])) { w[i][ j]=w[i][ k]+w[k][ j]; pre[i][ j]=pre[k][ j]; } } } } i=1; int l=1; while(s1!=d1) { path[i]=pre[s1-1][d1-1]; d1=path[i]; i++; l++; } String way="" ; SQLiteDatabase db3=SQLiteDatabase.openDatabase(c1,null,0); String query3="SELECT * FROM "+TABLE_NAME1; Cursor cur3=db3.rawQuery(query3, null); for(i=l-1;i>=0;i--) { cur3.moveToFirst(); for(j=0;j<4;j++) {

Page 34: MANET- Disaster Management

Page 34 of 43

int g=Integer.parseInt(cur3.getString(0)); if(g==path[i]&& i==0){ way=way+cur3.getString(1); break; } else if(g==path[i] && i!=0) { way=way+cur3.getString(1)+"--->"; break; } cur3.moveToNext(); } } way=way+d; tv.setText(way); } }); } }

Code to share text message: package com.example.accessdatabase; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; public class Msg extends Fragment{ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.msgsnd, container, false); Button button=(Button)view.findViewById(R.id.sendbuttn); EditText editText1=(EditText)view.findViewById(R.id.msgip); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Button button=(Button)getView().findViewById(R.id.sendbuttn); EditText editText1=(EditText)getView().findViewById(R.id.msgip); Intent senddata = new Intent(); senddata.setAction(Intent.ACTION_SEND); senddata.putExtra(Intent.EXTRA_TEXT, editText1.getText().toString()); senddata.setType("text/plain"); startActivity(senddata); } }); return view; } }

AndroidManifest.xml for the application to access database and to create the database: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.accessdatabase"

Page 35: MANET- Disaster Management

Page 35 of 43

android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.accessdatabase.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".FIRSTAID" /> <activity android:name=".Hospitals"/> <activity android:name=".second"/> <activity android:name=".Msg"/> <activity android:name=".showhosp"/> <activity android:name=".showpolice"/> <activity android:name=".showbloodbank"/> <activity android:name=".showmedicalcamp"/> <activity android:name=".showfirestation"/> </application> </manifest>

activity_main.xml <android.support.v4.app.FragmentTabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TabWidget android:id="@android:id/tabs" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0"/> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="0"/> <FrameLayout android:id="@+id/realtabcontent" android:layout_width="match_parent" android:layout_height="0dp"

Page 36: MANET- Disaster Management

Page 36 of 43

android:layout_weight="1"/> </LinearLayout> </android.support.v4.app.FragmentTabHost>

shwhsp.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginRight="93dp" android:layout_marginTop="121dp" android:ems="10" > <requestFocus /> </EditText> </RelativeLayout>

Hospitals.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" > </RelativeLayout>

shwblbnk.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > </RelativeLayout>

showpol.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" </RelativeLayout>

shwfrstn.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > </RelativeLayout>

Page 37: MANET- Disaster Management

Page 37 of 43

shwmedcmp.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > </RelativeLayout>

findpath.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <Spinner android:id="@+id/spinner2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="48dp" /> <Spinner android:id="@+id/spinner3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/spinner2" android:layout_marginTop="33dp" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignTop="@+id/spinner3" android:layout_marginRight="25dp" android:layout_marginTop="48dp" android:text="FIND" /> <EditText android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/button2" android:layout_marginTop="82dp" android:layout_toLeftOf="@+id/button2" android:ems="10" > <requestFocus /> </EditText> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="ENTER SOURCE" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/spinner2"

Page 38: MANET- Disaster Management

Page 38 of 43

android:text="ENTER DESTINATION" android:textAppearance="?android:attr/textAppearanceMedium" /> </RelativeLayout>

firstaid.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" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/sub_frag" android:layout_alignRight="@+id/sub_frag" android:layout_marginBottom="76dp" android:layout_marginRight="80dp" /> <Spinner android:id="@+id/spinner1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" /> </RelativeLayout>

msgsnd.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <EditText android:id="@+id/msgip" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="55dp" android:ems="10" android:hint="TYPE MESSAGE HERE" android:inputType="textMultiLine" > <requestFocus /> </EditText> <Button android:id="@+id/sendbuttn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="SEND" /> </RelativeLayout>

Page 39: MANET- Disaster Management

Page 39 of 43

CHAPTER 6 Test, Results and Discussions: The application was tested in a small area, i.e. Khidderpore. It is assumed that if the application can work in the small area, it would be working for a bigger area.

Figure 5 Test code for the above graph: #include<stdio.h>

#include<conio.h>

void flyod(int [][4],int [][4]);

void main()

{

int i,j,k,n=4,s,t,path[20],c;

int w[][4]={ {0,5,99,10}, {5,0,3,99},{99,3,0,1},{10,99,1,0}};

int pre[][4]={ {0,1,99,1},{2,0,2,99},{99,3,0,3},{99,99,4,0}};

clrscr();

flyod(w,pre);

printf("\n pre:");

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

printf("\t%d",pre[i][j]);

printf("\n");

}

printf("wt\n");

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

KPM

NL

CMRI B

10

5

3 1

Page 40: MANET- Disaster Management

Page 40 of 43

printf("\t%d",w[i][j]);

printf("\n");

}

printf("\n enter source and dest");

scanf("%d%d",&s,&t);

path[0]=t;

i=1;

c=1;

while(s!=t)

{

path[i]=pre[s-1][t-1];

t=path[i];

i++,c++;

}

for(i=c-1;i>=0;i--)

printf("->%d",path[i]);

getch();

}

void flyod(int w[][4],int pre[][4])

{

int i,j,k,n=4,i1,j1;

for(k=0;k<n;k++)

{

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

if(w[i][j]>(w[i][k]+w[k][j]))

{ w[i][j]=w[i][k]+w[k][j];

pre[i][j]=pre[k][j];

}

}

}

printf("\n k=%d",k);

Page 41: MANET- Disaster Management

Page 41 of 43

for(i1=0;i1<n;i1++)

{

for(j1=0;j1<n;j1++)

printf("\t%d",w[i1][j1]);

printf("\n");

}

}

}

Screenshot for the above graph:

Figure 6 The code was tested using C. 4 nodes- Khidderpore More (KPM), National Library (NL), Bodyguard (B) and Calcutta Medical Research Institute (CMRI) was taken for the test case. The path between two nodes is calculated using Floyd-Warshall as shown above.

Page 42: MANET- Disaster Management

Page 42 of 43

CHAPTER 7 Future Prospects:

• The application has been developed for an Android-based smart phone, because of Android’s easy availability, user-friendliness and reasonable costs. In future, the application would be modified to be used by any other mobile operating system.

• The MANET-based Disaster Management System uses Bluetooth to send messages. But Bluetooth has a limited range of network availability. ‘Wi-Fi direct’ and Mobile Adhoc networks can be used to exchange news between rescuers.

• The Bellman-Ford algorithm is used to find the shortest path between the given source and destination. Due to implementation complexities, the Djikstra algorithm was not used by the application. Johnson’s algorithm and the Viterbi algorithm are also optimal algorithms to find the shortest path, but these algorithms have huge time and space complexities. In future, the Bellman-Ford algorithm would be replaced by Prim’s or Kruskal’s algorithm to find the shortest path between two nodes.

Conclusion: Android-based Smartphones are easily available today at reasonable costs. So formation of MANETs during disasters can be done economically and these can serve the rescuers in those areas. The Android-based application developed must have the following requirements:

• User interface must be simple, easy to learn, and fool-proof.

• Devices do not need complicate setup procedure.

• Devices must be fault-tolerant such that misusage will not crash a device.

• Only basic functions are required, advanced features are optional.

• The system must not demand high power, must be able to recharge using a portable power generator. Without plenty of resources and time, it is not easy to develop a system that meets all the functional requirements listed above, especially the first three. User-friendliness and robustness cost a fortune to achieve. Therefore, our recommendation is to trade functionality for simplicity, developing basic functions only and giving up most advanced features. The developed application, i.e. The Manet-based Disaster Management System has an integrated interface to both “First Aid” and “Help Desk” functions. These tables altogether consist of such information as medical resources, rescue teams, shelter and life-support resources. During disasters, many victims saved from the debris die in minor injuries because of inefficiency of medical resource management. For instance, they were not taken to the adequate hospitals in time resulting in fatal infections. Without a good arrangement system for wounded victims, most rescued victims were probably sent to nearby hospitals. As a consequence, some hospitals were overcrowded while others are underutilized. Victims must not waste their time hopping from hospitals to hospitals. This problem can only be solved by communication among rescuers using “Send Message”. The rescuers would be able to send each other messages about the relief centers using Bluetooth. When disaster strikes, the first thing to do is to dispatch pioneering rescue teams to all potential stricken spots immediately to perform damage assessment. To save transportation time, “Find Path” is used to compute the fastest route to the stricken spots. When the assessment reports become available, “Help Desk” can work together to allocate medical and relief resources more accurately. The most important lessons we learned from numerous disasters are that mobile communication system is vulnerable and the loss of communication system and information network may have a catastrophic consequence. This documentation analyzes the causes that paralyzed the entire communication systems in various disasters and proposes a Mobile-adhoc Network that uses android-based Smartphones to construct a MANET based emergency communication and information system.

Page 43: MANET- Disaster Management

Page 43 of 43

Annexure:

1. Rescue Information System for Earthquake Disasters Based on MANET Emergency Communication Platform Hung-Chin Jang Yao-Nan Lien Tzu-Chieh Tsai Department of Computer Science, National Chengchi University

2. Professional Android™ Application Development –by Roto Meier 3. Eclipse and Java for Total Beginners Tutorial Companion Document Eclipse And Java For Total Beginners Companion

Tutorial Document by Mark Dexter 4. ANDROID TUTORIAL Simply Easy Learning by tutorialspoint.com 5. A Mobile Ad Hoc Network Implementation for Android Smartphones David Flanagan Rochester Institute of Technology 6. A Propose Architecture of MANET for Disaster Area Architecture R.P.Mahapatra, Tanvir Ahmad Abbasi, and Mohd Suhaib

Abbasi 7. Introduction to Algorithms by Thomas H.Cormen, Charles E.Leiserson, Ronald L.Rivest, Clifford Stein 8. http://developer.android.com/reference/packages.html 9. http://androidhive.com 10. http://developer.android.com/reference/packages.html 11. http://www.tutorialspoint.com/android/ 12. http://stackoverflow.com/ 13. http://www.javacodegeeks.com/ 14. http://www.javacode.in/ 15. http://www.java2s.com/ 16. http://www.programmingsimplified.com/java-source-codes 17. http://www.coreservlets.com/android-tutorial/ 18. http://android.appstorm.net/roundups/developer/15-apps-for-programming-on-android/ 19. http://www.linux.com/learn/docs/683628-android-programming-for-beginners-part-1 20. http://www.xda-developers.com/android/want-to-learn-how-to-program-for-android-start-here/ 21. http://www.codeproject.com/Articles/102065/Android-A-beginner-s-guide 22. https://code.google.com/p/android-query/