Вы находитесь на странице: 1из 24

Abstract:

In our project we created an Application in Android. The Android platform includes


support for the Bluetooth network stack, which allows a device to wirelessly exchange data
with other Bluetooth devices. The application framework provides access to the Bluetooth
functionality through the Android Bluetooth APIs. These APIs let applications wirelessly
connect to other Bluetooth devices, enabling point-to-point and multipoint wireless
features.
In this project we can communicate with each other without cellular network. We
can send message, data, files from one device to other device.
We can not run this application on the eclipse emulator , because it doesnt have
Bluetooth.We should run the application on the Android operating system. We have to use
android phone. We have to transfer .apk file from C:\\workspace\\project\\bin to android
phone through USB or bluetooth. Then install that application on the phone. Run it.

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

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

Snap Shots On Eclipse Platform

7.2

Snap Shots On Device


REFERENCES

PAGE NO.
3

6
9
14

17
19

24

1. INTRODUCTION:

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

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:

Scan for other Bluetooth devices


Query the local Bluetooth adapter for paired Bluetooth devices
Establish RFCOMM channels
Connect to other devices through service discovery
Transfer data to and from other devices
Manage multiple connections

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,

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

Page 3

It was Created by telecoms vendor Ericsson in 1994

It can connect several devices, overcoming problems of synchronization.

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

Bluetooth uses frequency hopping in timeslots.

Bluetooth uses a fast acknowledgement and a frequency-hopping scheme to make the


communications link robust
Compared with other systems operating in the same frequency band, the Bluetooth

radio typically hops faster and uses shorter packets.


This is because short packages and fast hopping limit the impact of microwave

ovens and other sources of disturbances.

1.2.

ANDROID:

Android is a Linux-based operating system designed primarily for touchscreen mobile


devices such as smartphones and tablet computers. It is currently developed by Google in
conjunction with the Open Handset Alliance. Initially developed by Android Inc, whom
Google financially backed and later purchased in 2005,Android was unveiled in 2007 along
Department of Computer Engineering
Vishwakarma Institute of Technology, Pune

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:

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

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

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

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.

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

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

b) File type: DEXIS Digital X-ray fille


X-ray image saved in the proprietary X-ray format; used by the DEXIS Digital Xray system for dental imaging; captures dental radiographs and saves them in a digital
format.

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

Page 9

DEXIS was acquired by Danaher Corporation in 2005.


c) File type: Disketch Project fille
Disc label project created by Disketch label design software; saves the layout
for a CD or DVD and can include text and imported images; may be printed with a
standard printer or a printer that supports disc labels.
Disketch now uses the .DEPROJ extension for disc label projects. The DEX format is
deprecated but can still be opened by current versions of Disketch.
d) File type: Excel Spreadsheet file
Spreadsheet or group of spreadsheets created by MS Excel; contains data formatted in
cells, which are organized into rows and columns.The .XLS extension is much more
commonly used for Excel files.

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

5) Android Manifest File :


Android projects use a special configuration file called the Android manifest file to
determine application settingssettings such as the application name and version, as well as
what permissions the application requires to run and what application components it is
comprised of.
Configuring the Android Manifest File
The Android application manifest file is a specially formatted XML file that must accompany
each Android application. This file contains important information about the applications
identity. Here you define the applications name and version information and what application components the application relies upon, what permissions the application requir- es to
run, and other application configuration information.
The Android manifest file is named AndroidManifest.xml and must be included at the top
level of any Android project. The information in this file is used by the Android system to-

Install and upgrade the application package.


Display the application details such as the application name, description, and icon to

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

service, broadcast receiver, or content provider.


Enable application settings such as debugging and configuring instrumentation for
application testing.

Editing the Android Manifest File

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

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,

ServiceConnection, int) to communicate with a background Service. Android platform


allows transition by means of Intent Interface.

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.

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

Page 12

AnimationDrawable: create animations frame by frame from a series of Drawable


objects. XML Tag <animation-list>
AnimationSet: tween animation series can perform simple transformations (position,
size, rotation and transparency) on the contents of a View object. Tags XML <set>,
<alpha>, <scale>, <translate>, <rotate>

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.

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

4.2.

Android Activity

Activity (ProjectActivity.java)An Android Activity is a single-focused task that


makes up part of your app.

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.

Typically, multiple Activities together form a complete Android application.

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

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

a device to wirelessly exchange data with other Bluetooth devices.


Using the Bluetooth APIs, an Android application can perform the following:

Scan for other Bluetooth devices

Query the local Bluetooth adapter for paired Bluetooth devices

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

Page 15

Establish RFCOMM channels

Connect to other devices through service discovery

Transfer data to and from other devices

Manage multiple connections

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.

We should run the application on the Android operating system.

We have to use android phone.

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

Page 17

We have to transfer .apk file from C:\\workspace\\project\\bin to android phone


through USB or bluetooth.

Then install that application on the phone.

Run it.

How the application works ..?

When we click on project icon in mobile then Bluetooth is turning ON.

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.

Select the device from list to which we want to paired.

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.

Snap Shots On Eclipse Platform

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

Page 18

Default android output window

Output for the project on eclipse

7.2.

Snap shots on devices


1.

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

Page 19

2.

3.

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

Page 20

4.

5.

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

Page 21

6.

7.

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

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

Department of Computer Engineering


Vishwakarma Institute of Technology, Pune

Page 24