Unit-5 E-Health
Unit-5 E-Health
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
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,
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.
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
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.
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
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
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.
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
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
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.
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
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.
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
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
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
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 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)
Description
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.
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
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.
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.
121
You see a list of Wi-Fi networks. In the figure, the Imperial Wambooli network is
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.
124
KEY CLASSES AND INTERFACES
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.
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.
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
Description
128
5.5 STEPS OF HEALTHCARE MOBILE APP DEVELOPMENT SERVICES
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.
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:
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
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.
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 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
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.
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 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.
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.
133