Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Page 1
INDEX:
CHAPTER NO.
8.
CHAPTER NAME
1.
INTODUCTION
1.1
BLUETOOTH
1.2
ANDROID
2.
3.
4.
DESIGN DETAILS
APPENDIX
ACTIVITY
4.1
BLUETOOTH PERMISSIONS:
4.2
Android Activity
4.3
5.
6.
7.
BLUETOOTH In ANDROID
PROGRAM FLOW
WORKING
SNAP SHOTS:
7.1
7.2
PAGE NO.
3
6
9
14
17
19
24
1. INTRODUCTION:
Page 2
This project describes how to use the Android 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
Using the Bluetooth APIs, an Android application can perform the following:
In this project we can communicate with each other without cellular network. We
can send message from one device to other device.
1.1.
BLUETOOTH
Bluetooth is a proprietary open wireless technology standard for exchanging data over
short distances from fixed and mobile devices,
Page 3
Bluetooth is managed by the Bluetooth Special Interest Group, which has more than
16,000 member companies in the areas of telecommunication, computing,
networking, and consumer electronics
1.2.
ANDROID:
Page 4
with the founding of the Open Handset Alliance, a consortium of 86 hardware, software, and
telecommunication companies devoted to advancing open standards for mobile devices.
Google releases the Android code as open source, under the Apache License. The Android
Open Source Project (AOSP), led by Google, is tasked with the maintenance and further
development of Android. Additionally, Android has a large community of developers writing
applications ("apps") that extend the functionality of devices, written primarily in a
customized version of Java. They are available for download through Google Play or thirdparty sites. In October 2012, there were approximately 700,000 apps available for Android,
and the estimated number of applications downloaded from Google Play (and the nowdefunct Android Market) was 25 billion.
The first Android-powered phone was sold in October 2008, and by the end of 2010 Android
had become the world's leading smartphone platform, overtaking Symbian which held the
record previously.It had a worldwide smartphone market share of 75% during the third
quarter of 2012, with 500 million devices activated and 1.3 million activations per day.
Application of the operating system has also moved beyond mobile phones and tablets,
currently televisions, netbooks and cameras are some of the types of devices Android is
featured in.
2. DESIGN DETAILS:
All of the Bluetooth APIs are available in the android.bluetoothpackage.
The following classes are used in coding:
Page 5
1. BluetoothAdapter :
It represents the local Bluetooth adapter (Bluetooth radio). TheBluetoothAdapteris
the entry-point for all Bluetooth interaction. Using this, you can discover other
Bluetooth devices, query a list of bonded (paired) devices.
2. BluetoothDevice :
Represents a remote Bluetooth device. Use this to request a connection with remote
device through a BluetoothSocket or query information about the device such as its
name, address, class, and bonding state.
3. BluetoothSocket:
It represents the interface for a Bluetooth socket (similar to a TCPSocket). This is
the connection point that allows an application to exchange data with another
Bluetooth device via InputStream and OutputStream.
4. BluetoothServerSocket:
It represents an open server socket that listens for incoming requests (similar to a
TCP ServerSocket). In order to connect two Android devices, one device must open
a server socket with this class. When a remote Bluetooth device makes a connection
request to the this device, theBluetoothServerSocket will return a connected
BluetoothSocket when the connection is accepted.
5. BluetoothClass:
Describes the general characteristics and capabilities of a Bluetooth device. This is a
read-only set of properties that define the device's major and minor device classes
Page 6
and its services. However, this does not reliably describe all Bluetooth profiles and
services supported by the device, but is useful as a hint to the device type.
6. BluetoothProfile:
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 Working
with Profiles.
7. BluetoothHeadset:
Provides support for Bluetooth headsets to be used with mobile phones. This
includes both Bluetooth Headset and Hands-Free (v1.5) profiles.
8. BluetoothHealthCallback:
An abstract class that you use to implement BluetoothHealthcallbacks. You must
extend this class and implement the callback methods to receive updates about
changes in the applications registration state and Bluetooth channel state
9. BluetoothA2dp:
Defines how high quality audio can be streamed from one device to another over a
Bluetooth connection. "A2DP" stands for Advanced Audio Distribution Profile.
10. BluetoothHealth :
Represents a Health Device Profile proxy that controls the Bluetooth service.
Page 7
11. BluetoothHealthCallback :
An abstract class that you use to implement BluetoothHealthcallbacks. You must
extend this class and implement the callback methods to receive updates about
changes in the applications registration state and Bluetooth channel state.
12. BluetoothHealthAppConfiguration :
Represents an application configuration that the Bluetooth Health third-party
application registers to communicate with a remote Bluetooth health device.
13. BluetoothProfile.ServiceListener :
An interface that notifies BluetoothProfile IPC clients when they have been
connected to or disconnected from the service (that is, the internal service that runs
a particular profile).
3. APPENDIX:
1)
.apk file:
Androidapplication package file (APK) is the file format used to distribute and install
application software and middleware onto Google's Android operating system. To make an
Department of Computer Engineering
Vishwakarma Institute of Technology, Pune
Page 8
APK file, a program for Android is first compiled, and then all of its parts are packaged into
one file. This holds all of that program's code (such as .dex files), resources, assets,
certificates, and manifest file. As is the case with many file formats, APK files can have any
name needed, but must end with the four character, three letter extension, .apk.
APK files are ZIP file formatted packages based on the JAR file format, with .apkfile
extensions. The MIME type associated with APK files is application/vnd.android.packagearchive.
2) .DEX file:
DEX files can be created manually or by automatically translating compiled Java programs.
Multiple DEX files are zipped into a single .APK package, which serves as the final Android
application file.
DEX File Extension:
a) File type: Dalvik Executable fille
Executable file format that contains compiled code written for Android, Google's
Linux-based mobile phone platform; technically referred to as a "Dalvik Executable,"
and can be interpreted by the Dalvik virtual machine.
DEX files can be created manually or by automatically translating compiled Java
programs. Multiple DEX files are zipped into a single .APK package, which serves as
the final Android application file
Page 9
3) strings.xml :
The string constants are being accessed from the resources so they are with their
default
values.We
can
change
them
using
strings.xml
file
which
resides
in
res/values/strings.xml
4) Content providers :
Content providers are Androids central mechanism that enables you to access data of
other applications mostly information stored in databases or flat files. As such content
providers are one of Androids central component types to support the modular approach
common to Android. Without content providers accessing data of other apps would be a mess.
Content providers support the four basic operations, normally called CRUD-operations.
CRUD is the acronym for create, read, update and delete. With content providers those
objects simply represent data most often a record (tuple) of a database but they could also
be a photo on your SD-card or a video on the web.
Department of Computer Engineering
Vishwakarma Institute of Technology, Pune
Page 10
users.
Specify application system requirements, including which Android SDKs are supported, what hardware configurations are required (for example, d-pad navigation), and
which platform features the application relies upon (for example, uses multitouch
capabilities).
Launch application activities.
Manage application permissions.
Configure other advanced application configuration details, including acting as a
Page 11
The manifest resides at the top level of your Android project. You can edit the
Android manifest file using the Eclipse Manifest File resource editor (a feature of the
Android ADT plug-in for Eclipse) or by manually editing the XML.
6) Intent :
An intent is an abstract description of an operation to be performed. It can be used
with startActivity to launch an Activity, broadcastIntent to send it to any interested
BroadcastReceiver
components,
and
startService(Intent)
or
bindService(Intent,
7) Drawable class :
Drawable class is an abstraction that represents "something that can be drawn." This class
is extended to define a variety of more specific graphical objects. Many of these resources
can be defined as using XML files. Some of them are:
BitmapDrawable: image based on a graphic file (PNG or JPG). <bitmap> XML tag.
ShapeDrawable: make a graph from vector primitives, such as basic shapes (circles,
squares, etc.) or paths (Path). It can not be defined by an XML file.
LayerDrawable: contains an array of Drawable that are displayed in the order of the
array. The array index is greater than that shown above. Label <layer-list>.
StateListDrawable: contains a list of Drawable objects, using a bit mask can select
visible objects. <selector> XML tag.
GradienDrawable: color gradient that can be used in buttons or backgrounds.
TransitionDrawable:LayerDrawables an extension that allows a transition between
the first and the second layer. To start the transition must call startTransition(). To
view the first layer must call resetTransition(). <transition> XML tag.
Page 12
4. ACTIVITY:
4.1.
BLUETOOTH PERMISSIONS:
In order to use Bluetooth features in your application, you need to declare at least one
of two Bluetooth permissions: BLUETOOTH and BLUETOOTH_ADMIN.
Department of Computer Engineering
Vishwakarma Institute of Technology, Pune
Page 13
You must request the BLUETOOTH permission in order to perform any Bluetooth
communication, such as requesting a connection, accepting a connection, and
transferring data.
You must request the BLUETOOTH_ADMIN permission in order to initiate device
discovery or manipulate Bluetooth settings.
The Android Bluetooth API is used 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.
4.2.
Android Activity
Activity will display a user interface in the supplied Window, and interact with the
user to perform the task.
A single Activity could be displaying a list of emails or showing a map of the current
location.
Page 14
The generated Activity extends from the class android.app.Activity and overrides a
single method, onCreate.
Activities are driven by events coming from the Android operating system, moving
the Activity through different stages of its life cycle.
4.3.
BLUETOOTH In ANDROID:
The Android platform includes support for the Bluetooth network stack, which allows
Page 15
The Android platform includes support for the Bluetooth network stack, which allows a
device to wirelessly exchange
5. PROGRAM FLOW :
1) When we run program , i.e. we create activity for first time and onCreate() method is
called.
2) Here we setup the window layout.We specify components of page in main.xml file.
3) In onCreate() method we check the availability of Adapter(if it is null or not).If it is
null we show toast message.
4) Then onStart() method is called.Here we make the request for making BT on,if it is
not.
5) onResume() method is called when ACTION_REQUEST_ENABLE returns.
Department of Computer Engineering
Vishwakarma Institute of Technology, Pune
Page 16
6) We make our device discoverable by clicking on options. This will make our device
discoverable for 300 sec.
7) To search for new device or to connect with paired device,we setup device_list.xml
layout.
8) When we click on scan for devices button then it will display all discovered
devices.
9) We get the name of device to which want connect by startActivityForResult(),which
will give its result through onActivityResult() method.
10) Then setUpChat() method is called, where define ConversationArrayAdapter to store
the conversation.
11) Here, we also initialize the listener for send button.
12) We can send our messages by clicking on send button.
13) When Another activity comes in foreground then onPause() method is called and we
return to our activity again onResume() method is called.
14) onStop() method is called when another activity is covering this one and when
activity is finished then onDestroy() is called,where we close Btchat service
6. WORKING:
We can not run this application on the eclipse emulator ,because it doesnt have
Bluetooth.
Page 17
Run it.
When Bluetooth is turned on then we have to make the device discoverable and then
select connect device from MENU bar .
Android devices whose Bluetooth is ON are display in the first list and the other
devices are display in the second list.
If any case devices are not appeared in the list then we have to click on scan for
devices button.
When the devices are connected then we can send the messages by clicking on Send
button.
The messages which we send and received are display above the Send button.
7. SNAP SHOTS:
7.1.
Page 18
7.2.
Page 19
2.
3.
Page 20
4.
5.
Page 21
6.
7.
Page 22
8. REFERENCES:
Department of Computer Engineering
Vishwakarma Institute of Technology, Pune
Page 23
http://blog.vimviv.com/android/intent-android/
www.android-developer.com
www.android.com
Page 24