0% found this document useful (0 votes)
28 views

Unit-5 E-Health

Hi

Uploaded by

suhasperumalla
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)
28 views

Unit-5 E-Health

Hi

Uploaded by

suhasperumalla
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/ 42

SCHOOL OF ELECTRICAL AND ELECTRONICS

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

UNIT V eHEALTH-SECA4004

92
UNIT-VAPPLICATION DEVELOPMENT FOR eHEALTH
Introduction to Android, Creating Android Activities, Android User interface design, Access
Wi-fi and Bluetooth with mobile applications-Web based App for eHealth applications.

ANDROID

Android is an open source and Linux-based operating system for mobile devices such as smart
phones and tablet computers. Android was developed by the Open Handset Alliance, led by
Google, and other companies. This tutorial will teach you basic Android programming and will
also take you through some advance concepts related to Android application development.
5.1 ANDROID - OVERVIEW
Android is an open source and Linux-based Operating System for mobile devices such as
smartphones and tablet computers. Android was developed by the Open Handset Alliance,
led by Google, and other companies.
Android offers a unified approach to application development for mobile devices which
means developers need only develop for Android, and their applications should be able to
run on different devices powered by Android.
The first beta version of the Android Software Development Kit (SDK) was released by
Google in 2007 where as the first commercial version, Android 1.0, was released in
September 2008.
On June 27, 2012, at the Google I/O conference, Google announced the next Android
version, 4.1 Jelly Bean. Jelly Bean is an incremental update, with the primary aim of
improving the user interface, both in terms of functionality and performance.
The source code for Android is available under free and open source software licenses.
Google publishes most of the code under the Apache License version 2.0 and the rest, Linux
kernel changes, under the GNU General Public License version 2 as shown in Figure 5.1.

93
Figure 5.1 Android Features

Features of Android

Android is a powerful operating system competing with Apple 4GS and supports great features.
Few of them are listed below

Feature & Description

Beautiful UI
Android OS basic screen provides a beautiful and
intuitiveuser interface.

Connectivity
GSM/EDGE, IDEN, CDMA, EV-DO, UMTS,
Bluetooth, Wi- Fi, LTE, NFC and WiMAX.

Storage
SQLite, a lightweight relational database, is used for
datastorage purposes.

94
Media support
H.263, H.264, MPEG-4 SP, AMR, AMR-WB, AAC,
HE-AAC, AAC 5.1, MP3, MIDI, Ogg Vorbis, WAV,

GIF, and BMP.

Messaging
SMS and MMS

Web browser
Based on the open-source WebKit layout engine,
coupled with Chrome's V8 JavaScript
supporting HTML5 and CSS3.

Multi-touch
Android has native support for multi-touch which
was initially made available in handsets such
HTC Hero.

Multi-tasking
User can jump from one task to another and
time variousapplication can run simultaneously.

Resizable widgets
Widgets are resizable, so users can expand them to
show morecontent or shrink them to save space.

Multi-Language
Supports single direction and bi-directional text.

GCM
Google Cloud Messaging (GCM) is a service
lets developers send short message data to their
users on Android devices, without needing a
proprietary sync solution.

Wi-Fi Direct
A technology that lets apps discover and
directly, over a high-bandwidth peer-
connection.

95
Android Beam
A popular NFC-based technology that lets
instantly share, just by touching two NFC-enabled
phones together.
JPEG, PNG,

ANDROID APPLICATIONS

Android applications are usually developed in the Java language using the Android
SoftwareDevelopment Kit.
Once developed, Android applications can be packaged easily and sold out either through
a store such as Google Play, SlideME, Opera Mobile Store, Mobango, F-droid
and the Amazon Appstore.
Android powers hundreds of millions of mobile devices in more than 190 countries
around the world. It's the largest installed base of any mobile platform and growing fast.
Every day more than 1 million new Android devices are activated worldwide.
This tutorial has been written with an aim to teach you how to develop and package
Android application. We will start from environment setup for Android application
programming and then drill down to look into various aspects of Android applications.

CATEGORIES OF ANDROID APPLICATIONS

History of Android

The code names of android ranges from A to N currently, such as Aestro, Blender, Cupcake,
Donut, Eclair, Froyo, Gingerbread, Honeycomb, Ice Cream Sandwitch, Jelly Bean, KitKat,
Lollipop and Marshmallow. Let's understand the android history in a sequence as shown in
Figure 5.2.

96
Figure 5.2 History of Android

ANDROID - ENVIRONMENT SETUP


You will be glad to know that you can start your Android application development on either of the
following operating systems
Microsoft Windows XP or later version.
Mac OS X 10.5.8 or later version with Intel chip.
Linux including GNU C Library 2.7 or later.
Second point is that all the required tools to develop Android applications are freely available and
can be downloaded from the Web. Following is the list of software's you will need before you start
your Android application programming.
Java JDK5 or later version
Android Studio
Here last two components are optional and if you are working on Windows machine then these
components make your life easy while doing Java based application development. So let us have a
look how to proceed to set required environment.

SET-UP JAVA DEVELOPMENT KIT (JDK)

You can download the latest version of Java JDK from Oracle's Java site Java SE Downloads.
You will find instructions for installing JDK in downloaded files, follow the given instructions to
install and configure the setup. Finally set PATH and JAVA_HOME environment variables to refer
to the directory that contains java and javac, typically java_install_dir/bin and java_install_dir
respectively.
97
If you are running Windows and installed the JDK in C:\jdk1.8.0_102, you would have to put
the following line in your C:\autoexec.bat file.
set PATH=C:\jdk1.8.0_102\bin;%PATH% set
JAVA_HOME=C:\jdk1.8.0_102
Alternatively, you could also right-click on My Computer, select Properties, then Advanced, then
Environment Variables. Then, you would update the PATH value and press the OK button.
On Linux, if the SDK is installed in /usr/local/jdk1.8.0_102 and you use the C shell, youwould
put the following code into your .cshrc file.
setenv PATH /usr/local/jdk1.8.0_102/bin:$PATH
setenv JAVA_HOME /usr/local/jdk1.8.0_102
Alternatively, if you use Android studio, then it will know automatically where you have
installed your Java.

ANDROID IDES

There are so many sophisticated Technologies are available to develop android applications, the
familiar technologies, which are predominantly using tools as follows
Android Studio
Eclipse IDE(Deprecated)
5.2 ANDROID - ARCHITECTURE

Android operating system is a stack of software components which is roughly divided into five
sections and four main layers as shown below in the architecture diagram as shown in figure
5.3.

98
Figure 5.3 Android Architecture

LINUX KERNEL

At the bottom of the layers is Linux - Linux 3.6 with approximately 115 patches. This provides a
level of abstraction between the device hardware and it contains all the essential hardware drivers
like camera, keypad, display etc. Also, the kernel handles all the things that Linux is really good at
such as networking and a vast array of device drivers, which take the pain out of interfacing to
peripheral hardware.

LIBRARIES

On top of Linux kernel there is a set of libraries including open-source Web browser engine WebKit,
well known library libc, SQLite database which is a useful repository for storage and sharing of
application data, libraries to play and record audio and video, SSL libraries responsible for Internet
security etc.

ANDROID LIBRARIES

This category encompasses those Java-based libraries that are specific to Android development.
Examples of libraries in this category include the application framework libraries in addition to
those that facilitate user interface building, graphics drawing and database access. A summary of
some key core Android libraries available to the Android developer is as follows
android.app Provides access to the application model and is the cornerstone of all
Android applications.

99
android.content Facilitates content access, publishing and messaging betweenapplications
and application components.
android.database SQLite
database management classes.
android.opengl A Java interface to the OpenGL ES 3D graphics rendering API.
android.os Provides applications with access to standard operating system services
including messages, system services and inter-process communication.
android.text Used to render and manipulate text on a device display.
android.view The fundamental building blocks of application user interfaces.
android.widget -built user interface components such as buttons,
labels, list views, layout managers, radio buttons etc.
android.webkit -browsing capabilities to be built
into applications.
Having covered the Java-based core libraries in the Android runtime, it is now time to turn our
attention to the C/C++ based libraries contained in this layer of the Android software stack.

ANDROID RUNTIME

This is the third section of the architecture and available on the second layer from the bottom.
This section provides a key component called Dalvik Virtual Machine which is a kind of
Java Virtual Machine specially designed and optimized for Android.
The Dalvik VM makes use of Linux core features like memory management and multi-
threading, which is intrinsic in the Java language. The Dalvik VM enables every Android
application to run in its own process, with its own instance of the Dalvik virtual machine.
The Android runtime also provides a set of core libraries which enable Android application
developers to write Android applications using standard Java programming language.

APPLICATION FRAMEWORK

The Application Framework layer provides many higher-level services to applications in the form of
Java classes. Application developers are allowed to make use of these services in their applications.
The Android framework includes the following key services
Activity Manager Controls all aspects of the application lifecycle and activity
stack.
Content Providers Allows applications to publish and share data with other
applications.
Resource Manager Provides access to non-code embedded resources such as strings,
color settings and user interface layouts.
Notifications Manager Allows applications to display alerts and notifications to the
user.

100
View System An extensible set of views used to create application user interfaces.

ANDROID - APPLICATION COMPONENTS

Application components are the essential building blocks of an Android application. These
components are loosely coupled by the application manifest file AndroidManifest.xml that
describes each component of the application and how they interact.
There are following four main components that can be used within an Android application

Components & Description

Activities
They dictate the UI and handle the user interaction to
the smart phone screen.

Services
They handle background processing associated with
anapplication.

Broadcast Receivers
They handle communication between

Content Providers
They handle data and database management issues.

ACTIVITIES

An activity represents a single screen with a user interface,in-short Activity performs actions on
the screen. For example, an email application might have one activity that shows a list of new
emails, another activity to compose an email, and another activity for reading emails. If an
application has more than one activity, then one of them should be marked as the activity that is
presented when the application is launched.
An activity is implemented as a subclass of Activity class as follows
public class MainActivity extends Activity {
}

101
SERVICES

A service is a component that runs in the background to perform long-running operations. For
example, a service might play music in the background while the user is in a different
application, or it might fetch data over the network without blocking user interaction with an
activity.
A service is implemented as a subclass of Service class as follows
public class MyService extends Service {
}

BROADCAST RECEIVERS

Broadcast Receivers simply respond to broadcast messages from other applications or from the
system. For example, applications can also initiate broadcasts to let other applications know that
some data has been downloaded to the device and is available for them to use, so this is
broadcast receiver who will intercept this communication and will initiate appropriate action.
A broadcast receiver is implemented as a subclass of BroadcastReceiver class and each
message is broadcaster as an Intent object.
public class MyReceiver extends BroadcastReceiver {
public void onReceive(context,intent){}
}

CONTENT PROVIDERS

A content provider component supplies data from one application to others on request. Such
requests are handled by the methods of the ContentResolver class. The data may be stored in the
file system, the database or somewhere else entirely.
A content provider is implemented as a subclass of ContentProvider class and must implement
a standard set of APIs that enable other applications to perform transactions.
public class MyContentProvider extends ContentProvider {
public void onCreate(){}
}

ADDITIONAL COMPONENTS

There are additional components which will be used in the construction of above mentioned
entities, their logic, and wiring between them. These components are

102
Components & Description

Fragments

Represents a portion of user interface in an Activity.

Views
UI elements that are drawn on-screen including
buttons, lists forms etc.

Layouts
View hierarchies that control screen format and
appearance ofthe views.

Intents
Messages wiring components together.

Resources
External elements, such as strings, constants and
drawablepictures.

Manifest
Configuration file for the application.

ANDROID - HELLO WORLD EXAMPLE

Let us start actual programming with Android Framework. Before you start writing your
first example using Android SDK, you have to make sure that you have set-up your Android
development environment properly as explained in Android - Environment Set-up tutorial. I
also assume that you have a little bit working knowledge with Android studio.
So let us proceed to write a simple Android Application which will print "Hello World!".
Create Android Application
The first step is to create a simple Android Application using Android studio. When you
click on Android studio icon, it will show screen as shown below

103
Figure 5.4 Android new studio

You can start your application development by calling start a new android studio project
as shown in figure 5.4. in a new installation frame should ask Application name, package
information and location of the project as shown in figure 5.5

Figure 5.5 Android project


104
Figure 5.6 Android target devices

After entered application name, it going to be called select the form factors your
application runs on, here need to specify Minimum SDK, in our tutorial, I have declared
as API23: Android 6.0(Mashmallow) as shown in figure 5.6
The next level of installation should contain selecting the activity to mobile, it
specifiesdefault layout for Applications as shown in figure 5.7

Figure 5.7 Adding an activity


At the final stage it going to be open development tool to write the application code as shown
in figure 5.8

105
Figure 5.8Anatomy of Android Application

Before you run your app, you should be aware of a few directories and files in the Android
project

106
107
Following section will give a brief overview of the important application files. The Main Activity
File
The main activity code is a Java file MainActivity.java. This is the actual application file
which ultimately gets converted to a Dalvik executable and runs your application. Following
is the default code generated by the application wizard for Hello World! application
Here, R.layout.activity_main refers to the activity_main.xml file located in
the res/layout folder. The onCreate() method is one of many methods that are figured when
an activity is loaded.

THE MANIFEST FILE

Whatever component you develop as a part of your application, you must declare all its
components in a manifest.xml which resides at the root of the application project directory.
This file works as an interface between Android OS and your application, so if you do not
declare your component in this file, then it will not be considered by the OS. For example, a
default manifest file will look like as following file
Here <application>...</application> tags enclosed the components related to the application.
Attribute android:icon will point to the application icon available under res/drawable-hdpi.
The application uses the image named ic_launcher.png located in the drawable folders
The <activity> tag is used to specify an activity and android:name attribute specifies the
fully qualified class name of the Activity subclass and the android:label attributes specifies a
string to use as the label for the activity. You can specify multiple activities using <activity>
tags.
The action for the intent filter is named android.intent.action.MAIN to indicate that this
activity serves as the entry point for the application. The category for the intent-filter is
named android.intent.category.LAUNCHER to indicate that the application can be launch
from the device's launcher icon.
The @string refers to the strings.xml file explained below. Hence, @string/app_name
refers to the app_name string defined in the strings.xml file, which is "HelloWorld".
Similar way, other strings get populated in the application.
Following is the list of tags which you will use in your manifest file to specify different Android
application components
<activity>elements for activities
<service> elements for services
<receiver> elements for broadcast receivers
<provider> elements for content providers
The STRINGS FILE
The strings.xml file is located in the res/values folder and it contains all the text that your
application uses. For example, the names of buttons, labels, default text, and similar types of strings
go into this file. This file is responsible for their textual content. For example, a default strings file
will look like as following file

108
THE LAYOUT FILE

The activity_main.xml is a layout file available in res/layout directory, that is referenced by


your application when building its interface. You will modify this file very frequently to
change the layout of your application. For your "Hello World!" application, this file will
have following content related to default layout
This is an example of simple RelativeLayout which we will study in a separate chapter.
The TextView is an Android control used to build the GUI and it have various attributes
like android:layout_width, android:layout_height etc which are being used to set its width
and height etc.. The @string refers to the strings.xml file located in the res/values folder.
Hence, @string/hello_world refers to the hello string defined in the strings.xml file, which is
"Hello World!".

RUNNING THE APPLICATION

Let's try to run our Hello World! application we just created. I assume you had created
your AVD while doing environment set-up. To run the app from Android studio, open one
of your project's activity files and click Run icon from the tool bar. Android studio
installs the app on your AVD and starts it and if everything is fine with your set-up and
application, it will display following Emulator window

Congratulations!!! you have developed your first Android Application and now just keep
following rest of the tutorial step by step to become a great Android Developer. All the very
best.

ANDROID RESOURCES ORGANIZING & ACCESSING

There are many more items which you use to build a good Android application. Apart from
coding for the application, you take care of various other resources like static content that
your code uses, such as bitmaps, colors, layout definitions, user interface strings, animation
instructions, and more. These resources are always maintained separately in various sub-
directories under res/ directory of the project.
This tutorial will explain you how you can organize your application resources, specify
alternative resources and access them in your applications.
Organize resource in Android Studio

ALTERNATIVE RESOURCES
Your application should provide alternative resources to support specific device
configurations.
For example, you should include alternative drawable resources ( i.e.images
) for different screen resolution and alternative string resources for different languages. At
runtime, Android detects the current device configuration and loads the appropriate
resources for your application.
To specify configuration-specific alternatives for a set of resources, follow the following
Create a new directory in res/ named in the form <resources_name>-
109
<config_qualifier>. Here resources_name will be any of the resources mentioned in
the above table, like layout, drawable etc. The qualifier will specify an individual
configuration for which these resources are to be used. You can check official
documentation for a complete list of qualifiers for different type of resources.
Save the respective alternative resources in this new directory. The resource files must
be named exactly the same as the default resource files as shown in the below example,
but these files will have content specific to the alternative. For example though image file
name will be same but for high resolution screen, its resolution will be high.
ACCESSING RESOURCES
During your application development you will need to access defined resources either in your code,
or in your layout XML files. Following section explains how to access your resources in both the
scenarios

ACCESSING RESOURCES IN CODE


When your Android application is compiled, a R class gets generated, which contains
resource IDs for all the resources available in your res/ directory. You can use R class to
access that resource using sub-directory and resource name or directly resource ID.

Example
To access res/drawable/myimage.png and set an ImageView you will use following code
Here first line of the code make use of R.id.myimageview to get ImageView defined with
id myimageview in a Layout file. Second line of code makes use of R.drawable.myimage to
get an image with name myimage available in drawable sub-directory under /res.
If you have worked with C, C++ or Java programming language then you must have seen
that your program starts from main() function. Very similar way, Android system initiates
its program with in an Activity starting with a call on onCreate() callback method. There is
a sequence of callback methods that start up an activity and a sequence of callback methods
that tear down an activity as shown in the below Activity life cycle diagram: (image
courtesy : android.com ) as shown in Figure 5.9.

110
Figure 5.9 Activity life cycle diagram

The Activity class defines the following call backs i.e. events. You don't need to implement all
the callbacks methods. However, it's important that you understand each one and implement
those that ensure your app behaves the way users expect.

An activity class loads all the UI component using the XML file available
in res/layout folder of the project. Following statement loads UI components
from res/layout/activity_main.xml file:
setContentView(R.layout.activity_main);

An application can have one or more activities without any restrictions. Every activity you
define for your application must be declared in your AndroidManifest.xml file and the main
111
activity for your app must be declared in the manifest with an <intent-filter> that includes
the MAIN action and LAUNCHER category as follows:
If either the MAIN action or LAUNCHER category are not declared for one of your
activities, then your app icon will not appear in the Home screen's list of apps.
Let's try to run our modified Hello World! application we just modified. I assume you had
created your AVD while doing environment setup. To run the app from Android studio,
open one of your project's activity files and click Run icon from the toolbar. Android
studio installs the app on your AVD and starts it and if everything is fine with your setupand
application, it will display Emulator window and you should see following log messages in
LogCat window in Android studio
Let us try to click lock screen button on the Android emulator and it will generate following
events messages in LogCat window in android studio:
Let us again try to unlock your screen on the Android emulator and it will generate
following events messages in LogCat window in Android studio:
Next, let us again try to click Back button on the Android emulator and it will generate
following events messages in LogCat window in Android studio and this completes the
Activity Life Cycle for an Android Application.

A service has life cycle callback methods that you can implement to monitor changes in the service's
state and you can perform work at the appropriate stage. The following diagram on the left shows
the life cycle when the service is created with startService() and the diagram on the right shows the
life cycle when the service is created with bindService(): (image courtesy : android.com as shown
in figure 5.10

Figure 5.10 Service life cycle


To create an service, you create a Java class that extends the Service base class or one of its existing
subclasses. The Service base class defines various callback methods and the most important are
112
given below. You don't need to implement all the callbacks methods. However, it's important that
you understand each one and implement those that ensure your app behaves the way users expect.
Lets try to run our modified Hello World! application we just modified. I assume you had created
your AVD while doing environment setup. To run the app from Android studio, open one of your
project's activity files and click Run icon from the tool bar. Android Studio installs the app on
your AVD and starts it and if everything is fine with your set-up as shown in figure 5.11

Figure 5.11 Examples of service

and application, it will display following Emulator window


Now to start your service, let's click on Start Service button, this will start the service and as
per our programming in onStartCommand() method, a message Service Started will appear on
the bottom of the the simulator as follows as shown in figure 5.12

113
Figure 5.12To stop the service,
you can click the Stop Service buttonAndroid - UI Layouts

The basic building block for user interface is a View object which is created from the View
class and occupies a rectangular area on the screen and is responsible for drawing and event
handling. View is the base class for widgets, which are used to create interactive UI
components like buttons, text fields, etc.
The ViewGroup is a subclass of View and provides invisible container that hold other
Views or other ViewGroups and define their layout properties.
At third level we have different layouts which are subclasses of ViewGroup class and a
typical layout defines the visual structure for an Android user interface and can be created
either at run time using View/ViewGroup objects or you can declare your layout using
simple XML file main_layout.xml which is located in the res/layout folder of your project
as shown in figure 5.13

114
Figure 5.13 Layout params

This tutorial is more about creating your GUI based on layouts defined in XML file.
Alayout may contain any type of widgets such as buttons, labels, textboxes, and so on.

Android Layout TypesThere are number of Layouts provided by Android which you will
use in almost all the Android applications to provide different view, look and feel.

VIEW IDENTIFICATION

Following is a brief description of @ and + signs


The at-symbol (@) at the beginning of the string indicates that the XML parser should
parse and expand the rest of the ID string and identify it as an ID resource.
The plus-symbol (+) means that this is a new resource name that must be created and
added to our resources. To create an instance of the view object and capture it from the
layout, use the following

ANDROID - UI CONTROLS

115
Figure 5.14 UI Elements

A View is an object that draws something on the screen that the user can interact with anda
ViewGroup is an object that holds other View (and ViewGroup) objects in order to definethe
layout of the user interface.

CREATE UI CONTROLS

Input controls are the interactive components in your app's user interface. Android providesa wide
variety of controls you can use in your UI, such as buttons, text fields, seek bars, check box, zoom
buttons, toggle buttons, and many more

There are following three concepts related to Android Event Management


Event Listeners single
callback method. These methods will be called by the Android framework when the View to
which the listener has been registered is triggered by user interaction with the item in the UI.
Event Listeners Registration
Handler gets registered with an Event Listener so that the handler is called when the Event
Listener fires the event.
Event Handlers hen an event happens and we have registered an event listener for the
event, the event listener calls the Event Handlers, which is the method that actually handles
the event.

There are many more event listeners available as a part of View class like OnHoverListener,
OnDragListener etc which may be needed for your application. So I recommend to refer official
documentation for Android application development in case you are going to develop a
sophisticated apps.
EVENT LISTENERS REGISTRATION
Event Registration is the process by which an Event Handler gets registered with an Event Listener
so that the handler is called when the Event Listener fires the event. Though there are several tricky
ways to register your event listener for any event, but I'm going to list down only top 3 ways, out of
which you can use any of them based on the situation.
Using an Anonymous Inner Class

116
Activity class implements the Listener interface.
Using Layout file activity_main.xml to specify event handler
directly.
Below section will provide you detailed examples on all the three scenarios
Touch Model
Users can interact with their devices by using hardware keys or buttons or touching the
screen.Touching the screen puts the device into touch mode. The user can then interact
with it by touching the on-screen virtual buttons, images, etc.You can check if the device
is in touch mode by calling the View isInTouchMode() method.
Focus
in focus.
This indicates that ready to accept input from the user.
isFocusable() it returns true or false
isFocusableInTouchMode() (A
view may be focusable when using a hardware key but not when the device is in touch
mode)

EVENT HANDLING EXAMPLES

Event Listeners Registration Using an Anonymous Inner Class


Here you will create an anonymous implementation of the listener and will be useful if
each class is applied to a single control only and you have advantage to pass arguments
to event handler. In this approach event handler methods can access private data of
Activity. No reference is needed to call to Activity.
But if you applied the handler to more than one control, you would have to cut and paste
the code for the handler and if the code for the handler is long, it makes the code harder
to maintain.
Following are the simple steps to show how we will make use of separate Listener class
to register and capture click event. Similar way you can implement your listener for any
other required event type.

Description

You will use Android studio IDE to create an Android


application and name it as myapplication under
a package com.example.myapplication as explained in
the Hello World Example chapter.

Modify src/MainActivity.java file to add click event


listeners and handlers for the two buttons defined.

117
Modify the detault content of
res/layout/activity_main.xml file to include Android UI
controls.
No need to declare default string constants.Android
studio takescare default constants.

Run the application to launch Android emulator and


verify theresult of the changes done in the aplication.

Following is the content of the modified main activity


file src/com.example.myapplication/MainActivity.java. This file can include each of the
fundamental lifecycle methods.
Let's try to run your myapplication application. I assume you had created your AVD while
doing environment setup. To run the app from Android Studio, open one of your project's
activity files and click Run icon from the toolbar. Android Studio installs the app on your
AVD and starts it and if everything is fine with your setup and application, it will display
following Emulator window

Now you try to click on two buttons, one by one and you will see that font of the Hello World text
will change, which happens because registered click event handler method is being called against
each click event.

DEFINING STYLES
A style is defined in an XML resource that is separate from the XML that specifies the
layout. This XML file resides under res/values/ directory of your project and will
have <resources> as the root node which is mandatory for the style file. The name of the
XML file is arbitrary, but it must use the .xml extension.
You can define multiple styles per file using <style> tag but each style will have its name
that uniquely identifies the style. Android style attributes are set using <item> tag as shown

STYLE INHERITANCE
Android supports style Inheritance in very much similar way as cascading style sheet in web
design. You can use this to inherit properties from an existing style and then define only the
properties that you want to change or add.
Your color resource can then be applied to some theme attributes, such as the window
background and the primary text color, by adding <item> elements to your custom theme.
These attributes are defined in your styles.xml file. For example, to apply the custom color
to the window background, add the following two <item> elements to your custom theme,
defined in MyAndroidApp/res/values/styles.xml file

A nine-patch drawable is a special kind of image which can be scaled in width and height
while maintaining its visual integrity. Nine-patches are the most common way to specify the
appearance of Android buttons, though any drawable type can be us.

118
STEPS TO CREATE NINE-PATCH BUTTONS

Save this bitmap as /res/drawable/my_nine_patch.9.png


Define a new style
Apply the new button style to the buttonStyle attribute of your custom theme
Android Themes
Hope you understood the concept of Style, so now let's try to understand what is a Theme.
A theme is nothing but an Android style applied to an entire Activity or application, rather
than an individual View.
Thus, when a style is applied as a theme, every View in the Activity or application will
apply each style property that it supports. For example, you can apply the
same CustomFontStyle style as a theme for an Activity and then all text inside
that Activity will have green monospace font.
To set a theme for all the activities of your application, open the AndroidManifest.xml file
and edit the <application> tag to include the android:theme attribute with the style name.
For example
<application android:theme="@style/CustomFontStyle">
But if you want a theme applied to just one Activity in your application, then add the
android:theme attribute to the <activity> tag only. For
<activity android:theme="@style/CustomFontStyle">
There are number of default themes defined by Android which you can use directly or
inherit them using parent attribute as follows
To understand the concept related to Android Theme, you can check Theme Demo Example.
Styling the colour palette
The layout design can implementable based on them based colours, for example as
following design is designed based on them colour(blue)

The Android platform provides a large collection of styles and themes that you can use in your
applications. You can find a reference of all available styles in the R.style class. To use the styles
listed here, replace all underscores in the style name with a period. For example, you can apply the
Theme_NoTitleBar theme with "@android:style/Theme.NoTitleBar". You can see the following
source code for Android styles and themes

Android offers a great list of pre-built widgets like Button, TextView, EditText, ListView,
CheckBox, RadioButton, Gallery, Spinner, AutoCompleteTextView etc. which you can use directly
in your Android application development, but there may be a situation when you are not satisfied
with existing functionality of any of the available widgets. Android provides you with means of
creating your own custom components which you can customized to suit your needs.
If you only need to make small adjustments to an existing widget or layout, you can simply subclass
the widget or layout and override its methods which will give you precise control over the
appearance and function of a screen element.
This tutorial explains you how to create custom Views and use them in your application using
119
simple and easy steps as shown figure 5.15.

Figure 5.15 Example of Custom Components in Custom View hierarchyCreating a


Simple Custom Component
Description

You will use Android studio IDE to create an


Androidapplication and name
it as myapplication under a
package
com.example.tutorialspoint7.myapplication as
explained in the Hello World Example chapter.
Create an XML res/values/attrs.xml file to define
newattributes along with their data type.

Create src/mainactivity.java file and add the code


to define your custom component

120
Modify res/layout/activity_main.xml file and add
the code to create Colour compound view instance
along with few default attributes and new
attributes.
Run the application to launch Android emulator
and verify the result of the changes done in the
application.
5.3 ACCESS WI-FI ON AN ANDROID PHONE

Making Wi-Fi work on your Android phone requires two steps. First, you must activate
Wi- The second step is connecting to a
specific wireless network.
Wi-Fi stands for wireless fidelity.
letters B, N, and G.
Activating Wi-Fi
Follow these steps to activate Wi-Fi on your Android phone:
At the Home screen, touch the Apps icon.Open the Settings app.
Ensure that the Wi-Fi master control icon is on.
If not, slide the master control from Off to On to activate the Wi-Fi radio.

connected automatically. Otherwise, you have to connect to an available network, which is


covered in the next section.
To turn off Wi-Fi, repeat the steps in this section, but in Step 3 slide the master control icon
from On to Off. Turning off Wi-Fi disconnects your phone from any wireless networks.
Some phones may come with a Power Control widget affixed to a Home screen. One of the
buttons on that widget is used to turn Wi-Fi on or off.

Using Wi-Fi to connect to the Internet incur data usage charges.


The Wi-
If you want
be near a Wi-Fi access point for any length of time, turn off the Wi-Fi radio.
CONNECTING TO A WI-FI NETWORK
After activating the Wi-Fi radio on your Android phone, you can connect to an available wireless
network. Heed these steps:
Open the Settings app.
found in the apps drawer, but also find a shortcut in the quick actions drawer.
Choose Wi-Fi or Wireless & Networks.
touch the Master Control icon, which turns the Wi-Fi radio on or off; touch theWi-
Fi text on the left side of the Settings app screen.

121
You see a list of Wi-Fi networks. In the figure, the Imperial Wambooli network is

currently connected as shown in figure 5.16

Figure 5.16 Choose a wireless network from the list.

When no wireless networks are shown, sort of out of luck regarding Wi-Fi access
from your current location.
If prompted, type the network password.
Putting a check mark in the box by the Show Password option makes it easier to type a
long, complex network password.
Touch the Connect button.
You should be immediately connected to the network. If not, try the password again.
When the phone is connected, you see the Wi-Fi status icon atop the touchscreen,
-Fi is on
connected and communicating with a Wi-Fi network.

Some wireless networks broadcast their names, which adds security but also makes
accessing them more difficult. In these cases, touch the Add icon to manually add the
network. The command might be titled Add Network.
You need to type the network name, or SSID, and specify the type of security. You also need the
password, if one is used. You can obtain this information from the girl with the pink hair and
pierced lip who sold you coffee or from whoever is in charge of the wireless network at your
location.
122
Not every wireless network has a password. They should!
Some public networks are open to anyone, but you have to use the web browser app to
get on the web and find a login page that lets you access the network. Simply browse to
any page on the Internet, and the login page shows up.
The phone automatically remembers any Wi-
network password. An example is the AS_BOARD_ROOM network, shown.
To disconnect from a Wi-Fi network, simply turn off Wi-Fi.
Unlike the mobile network, a Wi- -
Fi when you plan to remain in one location for a while. If you wander too far away, your
phone loses the signal and is disconnected.
CONNECTING VIA WPS
Many Wi-Fi routers feature WPS, which stands for Wi-

WPS, you can use it to quickly connect your phone to the network.
To make the WPS connection, touch the WPS connection button on the router. The
button is labeled WPS or sports the WPS icon. On your phone, visit the Wi-Fi screen in
the settings app. Touch the WPS icon to connect to the network.

If the WPS router requires a PIN (Personal Identification Number), touch the Action
Overflow icon on the Wi-Fi settings screen and choose the WPS Pin Entry item.

5.5 BLUETOOTH
The Android platform includes support for the Bluetooth network stack, which allows a device to
wirelessly exchange data with other Bluetooth devices. The app framework provides access to the
Bluetooth functionality through Bluetooth APIs. These APIs let apps connect to other Bluetooth
devices, enabling point-to-point and multipoint wireless features.
Using the Bluetooth APIs, an app can perform the following:Scan for other Bluetooth devices.
Query the local Bluetooth adapter for paired Bluetooth devices.

123
Establish RFCOMM channels.
Connect to other devices through service discovery.
Transfer data to and from other devices.
Manage multiple connections.
This topic focuses on Classic Bluetooth. Classic Bluetooth is the right choice for more
battery-intensive operations, which include streaming and communicating between
devices. For Bluetooth devices with low power requirements, consider using Bluetooth
Low Energy connections.
This documentation describes different Bluetooth profiles and explains how to use the
Bluetooth APIs to accomplish the four major tasks necessary to communicate using
Bluetooth:
Setting up Bluetooth.
Finding devices that are either paired or available in the local area.
Connecting devices.
Transferring data between devices.
For a demonstration of using the Bluetooth APIs, see the Bluetooth Chat sample app.

THE BASICS

For Bluetooth-enabled devices to transmit data between each other, they must first form a channel of
communication using a pairing process. One device, a discoverable device, makes itself available
for incoming connection requests. Another device finds the discoverable device using a service
discovery process. After the discoverable device accepts the pairing request, the two devices
complete a bonding process in which they exchange security keys. The devices cache these keys for
later use. After the pairing and bonding processes are complete, the two devices exchange
information. When the session is complete, the device that initiated the pairing request releases the
channel that had linked it to the discoverable device. The two devices remain bonded, however, so
they can reconnect automatically during a future session as long as they're in range of each other
and neither device has removed the bond.
Use of the Bluetooth APIs requires declaring several permissions in your manifest file. Once
your app has permission to use Bluetooth, your app needs to access the
BluetoothAdapter and determine if Bluetooth is available on the device. If Bluetooth is
available,
There are three steps to make a connection:
Find nearby Bluetooth devices, either devices that are already paired or new ones. Connect to
a Bluetooth device.

Transfer data with the connected device.


Certain devices use a specific Bluetooth profile that declares the data it provides.

124
KEY CLASSES AND INTERFACES

All of the Bluetooth APIs are available in the android.bluetooth package.


The following are the classes and interfaces you need in order to create Bluetooth
connections:BluetoothAdapter
Represents the local Bluetooth adapter (Bluetooth radio).
The BluetoothAdapter is the entry-point for all Bluetooth interaction.
Using this, you can discover other Bluetooth devices, query a list of bonded (paired)
devices, instantiate a BluetoothDevice using a known MAC address, and create a
BluetoothServerSocket to listen for communications from other devices.
BLUE TOOTH DEVICE
REPRESENTS A REMote Bluetooth device. Use this to request a connection with a remote device
through a BluetoothSocket or query information about the device such as its name, address, class,
and bonding state.
BLUE TOOTH SOCKET
Represents the interface for a Bluetooth socket (similar to a TCP Socket). This is the connection
point that allows an app to exchange data with another Bluetooth device using InputStream and
OutputStream.
BLUE TOOTH SERVER SOCKET
Represents an open server socket that listens for incoming requests (similar to a TCP
ServerSocket). In order to connect two devices, one device must open a server socket with this
class. When a remote Bluetooth device makes a connection request to this device, the device
accepts the connection and then returns a connected BluetoothSocket.
BLUE TOOTH CLASS
Describes the general characteristics and capabilities of a Bluetooth device. This is a read-only set of
properties that defines the device's classes and services. Although this information provides a useful
hint regarding a device's type, the attributes of this class don't necessarily describe all Bluetooth
profiles and services that the device supports.
BLUE TOOTH PROFILE
An interface that represents a Bluetooth profile. A Bluetooth profile is a wireless interface
specification for Bluetooth-based communication between devices. An example is the Hands-Free
profile. For more discussion of profiles, see Bluetooth profiles.
BLUE TOOTH HEADSET
Provides support for Bluetooth headsets to be used with mobile phones. This includes both the
Bluetooth Headset profile and the Hands-Free (v1.5) profile.
BLUETOOTH A2DP
Defines how high-quality audio can be streamed from one device to another over a Bluetooth
connection using the Advanced Audio Distribution Profile (A2DP).
BLUETOOTH HEALTH
Represents a Health Device Profile proxy that controls the Bluetooth service.
125
BLUE TOOTH HEALTH CALLBACK
An abstract class that you use to implement BluetoothHealth callbacks. You must extend this class
and implement the callback methods to receive updates about changes in the registration state
and Bluetooth channel state.
BLUE TOOTH HEALTHAPP CONFIGURATION
Represents an app configuration that the Bluetooth Health third-party app registers to communicate
with a remote Bluetooth health device.
BLUE TOOTH PROFILE.SERVICELISTENER
An interface that notifies BluetoothProfile interprocess communication (IPC) clients when they
have been connected to or disconnected from the internal service that runs a particular profile.

ANDROID - BLUETOOTH

Among many ways, Bluetooth is a way to send or receive data between two different
devices. Android platform includes support for the Bluetooth framework that allows a device
to wirelessly exchange data with other Bluetooth devices.
Android provides Bluetooth API to perform these different operations. Scan for other
Bluetooth devices
Get a list of paired devices
Connect to other devices through service discovery
Android provides BluetoothAdapter class to communicate with Bluetooth. Create an object of
this calling by calling the static method getDefaultAdapter(). Its syntax is given below.
Apart from this constant, there are other constants provided the API , that supports different
tasks. They are listed below.

S Constant & description

ACTION_REQUEST_DISCOVERABLE
1
This constant is used for turn on discovering
ofBluetooth

ACTION_STATE_CHANGED
2 This constant will notify that Bluetooth state
has beenchanged

3 ACTION_FOUND

126
This constant is used for receiving information
about each device that is discovered

Apart form the parried Devices , there are other methods in the API that gives more control
over Blueetooth. They are listed below.

S Method & description

1 enable()
This method enables the adapter if not enabled

2 isEnabled()
This method returns true if adapter is enabled

3 disable()
This method disables the adapter

4 getName()
This method returns the name of the Bluetooth
adapter

5 setName(String name)
This method changes the Bluetooth name

getState()
6 This method returns the current state of the
BluetoothAdapter.

startDiscovery()
7 This method starts the discovery process of the
Bluetooth for 120 seconds.

127
Example

This example provides demonstration of BluetoothAdapter class to manipulate Bluetoothand show


list of paired devices by the Bluetooth.
To experiment with this example , you need to run this on an actual device.

Description

You will use Android studio to create an Android


application a package
com.example.sairamkrishna.myapplication.

Modify src/MainActivity.java file to add the code

Modify layout XML file


res/layout/activity_main.xml add any GUI
component if required.
Modify AndroidManifest.xml

Run the application and choose a running android


device and install the application on it and verify
the results.

128
5.5 STEPS OF HEALTHCARE MOBILE APP DEVELOPMENT SERVICES

Step 1. Choose your technological partner among healthcare software development


companies
When choosing the best healthcare dev company, consider previous projects, client reviews,
and the tech expertise.
Step 2. Ask developers for a quote to create a healthcare app
Fill in the contact form to schedule a meeting with a business development manager to
clarify more details of your project.
Step 3. Receive a rough estimate on medical app development
Based on the project's details, a business analyst, project manager, and solutions architect
will create a rough estimation for your project and send it to you.
Step 4. Launch the inception phase with a team of medical app developers
When you agree on the initial estimation, healthcare app developers will clarify more
details on your project to create user stories, mockups, and wireframes.
Step 5. Start the healthcare software development process
When you agree on all deliverables of the inception phase, the team will start building the
app iteration by iteration.

TYPES OF MOBILE HEALTH APPS

There are different types of apps for health aimed at various end-users, including medical
professionals, labs, and patients, which impact their features, some integrations, and the degree of
data security required.

PROFESSIONAL HEALTHCARE APP

Targeted at medical personnel, such apps include patient data, such as name, date of birth, insurance
number, address, and so on. Thus, when launching a professional healthcare development process,
you need to make a medical personal mobile app HIPAA compliant and pay extra attention to
private data encryption to avoid data breaches. mHealth apps for medical specialists include the
following types:

CLINICAL COMMUNICATION APPS

Such applications are developed to improve clinical decision-making and communication


with clinical specialists in a particular hospital. They include messaging and voice chat, file
sharing, and electronic health record systems.
One example of such an app is Halo, a communication, and collaboration platform for
clinical specialists, which includes the following features:
Send physicians and nurses Lab and PACS results
Integrate with EHR (electronic health records) to edit patient records in real-time Store files
on a cloud-based platform, Amazon Web Services

129
PATIENT COMMUNICATION APPS

This type of app boosts customer satisfaction, loyalty, health outcomes, and provides
more transparency between patients and doctors.
That is how the EASE mobile app works, offering users the following features: Invite
relatives to the network within the app to keep them informed about updates
Include HIPAA compliant texts, photos, and videos that will self-destruct after 60seconds
Send premade bulk messages to patients and their families to keep them informed
Prohibit saving files, texts, or other documents from the app to the device to ensure
patient privacy and avoid data breaches

MEDICAL RECORD APPS

Such apps simplify updating patient records, including blood pressure, medical visits,
examinations, prescriptions, and other information to keep track of a patient's progress.
Medical Record is an app that belongs to this mHealth app category. In addition to the
features above, the app also includes:
Prescription module allowing doctors to save medical info Appointment feature to schedule
an appointment with patients Recording videos or procedures instead of text messages
Searching patients by I.D.

RISK ASSESSMENT APPS

Such apps are integrated with Electronic Health Records (EHR) and wearable devices, which
allows monitoring patients' health conditions in real-time, tracking heart rate, and identifying
patients at risk. To build a risk assessment mobile app, developers often use machine
learning for pattern recognition, as we did for our recent project, a skin cancer detection
neural network.
An example of such an app is FHR 5-Tier(Forecast Health Risk and Predication), aimed at
obstetricians, midwives, and nurses who use electronic fetal monitoring (EFM) for patients
in labor. Let's look at its features:
The app allows interpreting fetal heart rate (FHR) tracings to decide about further patient
treatment in real-time
The five-color (green, blue, yellow, orange, and red) system is used in the app to allow
medical specialists to standardize the management of different fetal heart rate tracings.
When the app finds a risk to a patient's health, it uses colors Yellow, Orange, or Red to
notify the doctor about the patient's state of urgency and provide a list with recommended
actions.

BARCODE SCANNING APPS

Barcode scanning mobile apps in healthcare allow scanning a patient's electronic health
records and medication barcodes using a built-in camera in their mobile devices, avoiding
expensive barcode scanning devices.

130
Epic Rover is one healthcare app that belongs to this category, empowered by Scandid
Barcode scanner SDK. Apart from scanning a patient's medications barcodes, develop a
healthcare mobile app with the following features:
Integration with Epic electronic health records for better admission of medicines and
treatment
Visualization of patient-related info and progress in the form of charts
Build-in messenger to communicate with patients and other medical personnel And other
functions to make the doctors' work even more efficient.
MEDICATION DOSAGE APPS

Such applications are used by physicians to calculate individualized doses of medicine based
on the patient's age, weight, and other personal info, avoiding laborious manual calculations,
spreadsheets, and sophisticated tools.
One example is the DoseMeRx app for medical professionals. Let's find out more about its
features:
Integration with EHR, where the doctor can leave notes on the patient's state, medications,
and dosage assigned
Set up reminders so that patients can track their medication intake Build-in feature to predict
treatment outcomes
Integrated dose optimization feature that leverages Bayesian dosing methods to guide dose
optimization, based on clinically validated pharmacokinetic drug models, patient
characteristics, drug concentrations, and genotype

HOSPITAL MOBILE APP DEVELOPMENT

Healthcare mobile apps for patients

The patient-oriented mobile app market includes two main categories: medical and wellness. Below,
we highlight every type of app from both of these groups, their examples, and essential features.

Doctor-on-demand or Telemedicine apps

Even in a busy environment, patients can receive treatment and consultations from medical
specialists using telemedicine apps, without leaving their offices or homes. Such mobile
applications help patients to find a necessary medical specialist from a pool of doctors, book
an appointment, and attend it via video call and pay for the consultation via an integrated
payment gateway.
One typical doctor-on-demand mobile app is EVisit that includes other features:
Virtual waiting room with waiting time tracking where patients can prepare the information
required
Two-way video connection so patients can see the doctors they communicate with
Built-in messaging, EHR, search for medication, prescriptions, and other features to deliver
patients the medical experience of attending an offline appointment with a doctor.

131
Condition-based apps

Such apps are popular among users with epilepsy, diabetes, cardiovascular disease, asthma,
allergies, and even depression. While some apps in this category are more sophisticated
versions of a digital diary with visual medication management, others
use predictive analytics and machine learning to notify a user about a particular health
condition one should be aware of.
Founded by Munroe-Meyer Institute, Seizure Tracker is a perfect example of apps that
allow users to log their seizures, and includes a bunch of other features:
Video recording, so patients can describe their seizures, their triggers, and what happened
afterward
Manual input of seizure info, so the user can specify their seizure type, time of day,
length of the seizure, and other related information
Option to synchronize user profile with private Youtube channel to record info about
seizures and share it with relatives

Fitness apps

Such apps help users keep fit by tracking their daily activity, weight, number of calories
burned, a list with workout programs, and integration with wearable devices. In our previous
article devoted to fitness app development, we described other features of such apps and
gave you a guide on how to develop one.
MyFitnessPal is the most popular fitness mobile app, which includes:
Diet tracking with recommendations on calorie consumption based on the user's age, weight,
sex
User community where other users share their success stories about losing weight Calorie
counter to control the amount of food, water and coffee consumed

Diet and nutrition apps

Diet and nutrition apps are another popular category in the mHealth market, targeted at users
who want to lose weight. The standard set of a diet app includes a comprehensive library
with food and nutrition, a calorie counter, a diary with meals, and a progress chart.
Lose It! app belongs to this mobile app category and provides users with the following
features:
Barcode scanner to receive information about product nutrients within seconds, and track
intake of carb, macro, and calorie
Snap It allows users to log images of food taken on a mobile device
Meal planning to customize the user's eating and track macro, carb, protein, and overall
calorie intake

132
Meditation apps

Meditation mobile apps also belong to the mHealth market since they help users to maintain
their mental health with the help of guided meditations. As a rule, such apps include a library
with pre-recorded sessions of guided meditations, timer, gamification, and useful tips about
breathing exercises.
Calm, the best-known meditation mobile app, valued at $1 billion, helps users reduce stress
and improve sleep. To achieve these goals, they use not only ancient methods of relaxation,
but also a scientific approach based on ongoing studies conducted by scientist from Arizona
State University, Ryerson University in Toronto, Massachusetts General Hospital, and
others.
The main features of the Calm app are:
Guided meditations for different purposes (relationships, breaking habits, happiness, etc.

Mediations of different lengths for users with varying levels


A library with podcasts, sleeping stories, relaxing music, breathing programs, and
masterclasses

Regulations to consider before starting a healthcare app development

If you want to build a mobile medication app, things to consider are security regulations and
compliances across different countries that are mainly concerned with patient data safety.
Otherwise, if your app does not meet these regulations, no matter how good your app is, it
will be deleted from app marketplaces.
The good thing is to build a weight loss, calorie counter, or meditation app, you do not need
to make it compliant.

TEXT / REFERENCE BOOKS


1. Shortliffe, Edward H and Cimino James J. Biomedical Informatics, Computer Applications in Health Care and
Biomedicine, Springer-Verlag London 2014.
2. Lavis, JN (ed). Ontario's Health System: Key Insights for Engaged Citizens, Professionals and
Policymakers. 2016.
3. Hoyt RE, Yoshihashi A, Bailey N. Health informatics: Practical guide for healthcare and information
technology professionals. Lulu Press. 2014 Seventh edition.
4. Gaddi A, Capello F, Manca M. eHealth, Care and Quality of Life. 2014 electronic library holding in the Health
Science Library

133

You might also like