Sie sind auf Seite 1von 18

MADRAS INSTITUTE OF TECHNOLOGY

ANNA UNIVERSITY, CHENNAI – 600 044

B.Tech Information Technology (6/8)

Creative and innovative Project (IT 8611)

ASAY APP: CHATTING AND SHARING FILES VIA WIFI


DIRECT IN ANDROID

Project Members
M. Akshay - 2013506060
K. Ashok - 2013506065

1|Page
TABLE OF CONTENTS:

S.NO TITLE PAGE.NO

ABSTRACT 3

1. INTRODUCTION 3

2. EXISTING WORK 4

3. PROPOSED WORK 5

4. IMPLEMENTATION 6
REQUIREMENTS

5. IMPLEMENTATION 7
STEPS

6. CONCLUSION 17

7. REFERENCES 18

2|Page
Abstract:

The objective of the project is to allow people to chat with many people at once
and share important documents. This application can be developed based on Android
operating system. The programming language is Java. The project can be tested on an
Android Emulator which is a tool that allow developers to easily test an application
without having to install the application on a real device. The Android-based instant
message application uses the client/server architecture. The client can add a registered
user to be his/her friend and send or receive a text message while the friend is on-line.
Currently, the communication in this application can be implemented using TCP. A
SQL database can be used as a backbone to store the user information. This app allows
the user to share file in any format and a wide range of data exchange is made possible.
It allow you to share documents with your friends. Ex. PDF, text files and multimedia.
Without downloading the documents the user can open the documents and view them
within the app.

1. Introduction:
Today, roughly 10% of all people in the world use Wi-Fi to stay connected.
Everyone needs information in faster access and easy way. Now technologies are
developing in such a way, everything become wireless. People can connect to one
another without joining a traditional home, office or hotspot network. Mobile phones
and other devices can able to make a one-to-one connection, or several devices can
connect simultaneously. The technology greatly enhances the portability of content
and applications across all of a user’s devices using a single industry-wide technology.

3|Page
2. EXISTING WORK:

2.1. A Measurement study of peer-to-peer file sharing system

Author: Stefan saroiu, p. Krishna Gummadi, Steven D. Gribble

Ideas:

To proper evaluation of a peer to peer system by take into account the


characteristics of the peers that choose to participate.The characteristics includes the
bandwidths between these hosts and the internet at large, IP latencies to send packets to
these hosts, how often connect and disconnect from the system, How many file hosts
share and download, the degree of cooperation between the hosts.

2.2. Device to device communication with Wi-Fi direct

Author: Daniel Campus-Mur, Andres Garcia-saaveda and pable Serrano

Ideas:

This paper deals with the overview of the novel functionalities defined in Wi-
Fi direct, and present an experimental evaluation that portrays the performance to be
expected in real scenarios.

2.3. Content-centric Routing in Wi-Fi direct multi-group network

Author: c. Casetti, p.Giaccone

Ideas:

This paper address the implementation of content-centric routing in a D2D


architecture for Android devices based on Wi-Fi direct, a protocol recently standardized
by the Wi-Fi Alliance.

4|Page
3.PROPOSED WORK:

The Application has to be built over the application framework. To develop


an Android Application Package (APK) for instant messaging using the Wi-Fi direct.
The application features include: image/jpeg, GIF, audio/mp3, video/mp4, and
application/ msword . Application Design Overview: Every application runs in its
own Linux process. Android starts the process when any of the application's
components need to be executed, then shuts down the process when it's no longer
needed or when the system must recover memory for other applications. Current
Process: A socket connection is established between the two users to exchange
messages and multimedia. The information about the friends is stored in the
database. The designed features for the messaging application are the friend finder,
chat and group chat.

5|Page
4. IMPLEMENTATION REQUIREMENTS:

4.1. ANDROID STUDIO 1.5.0:

Android Studio is the official integrated development environment (IDE) for


developing for the Android platform. It was announced on May 16, 2013 at the Google
I/O conference. Android Studio is freely available under the Apache License 2.0.
Android Studio was in early access preview stage starting from version 0.1 in May
2013, then entered beta stage starting from version 0.8 which was released in June 2014.
The first stable build was released in December 2014, starting from version 1.0. Based
on JetBrains' IntelliJ IDEA software, Android Studio is designed specifically for
Android development. It is available for download on Windows, Mac OS X and Linux,
and replaced Eclipse Android Development Tools (ADT) as Google's primary IDE for
native Android application development. New features are expected to be rolled out
with each release of Android Studio. The following features are provided in the current
version:

-based build support.

Android-specific refactoring and quick fixes.

mpatibility and other problems.

-signing capabilities.

-based wizards to create common Android designs and components.

-and-drop UI components, option to


preview layouts on multiple screen configurations.

6|Page
-in support for Google Cloud Platform, enabling integration with Google Cloud
Messaging and App Engine.

4.2. PLATFORM:

WINDOWS OPERATING SYSTEM

4.3. BASIC REQUIREMENTS:

o Mobile Phones

o Images and other required files in Mobile Phones

o WIFI Direct facility in Mobile Phones

5. IMPLEMENTATION STEPS:

5.1 Creating P2P Connections with Wi-Fi:

The Wi-Fi peer-to-peer (P2P) APIs allow applications to connect to nearby


devices without needing to connect to a network or hotspot (Android's Wi-Fi P2P
framework complies with the Wi-Fi Direct™ certification program). Wi-Fi P2P allows
your application to quickly find and interact with nearby devices, at a range beyond the
capabilities of Bluetooth.

5.2 Set Up Application Permissions:

In order to use Wi-Fi P2P, add the CHANGE_WIFI_STATE, and


INTERNET permissions to your manifest. Wi-Fi P2P doesn't require an internet
connection, but it does use standard Java sockets, which require the INTERNET
permission. So you need the following permissions to use Wi-Fi P2P. EXAMPLE:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.nsdchat" ...

7|Page
<uses-permission android:required="true"
android:name="android.permission.ACCESS_WIFI_STATE"/>

<uses-permission android:required="true"
android:name="android.permission.CHANGE_WIFI_STATE"/>

<uses-permission android:required="true"
android:name="android.permission.INTERNET"/> ...

5.3 Set Up a Broadcast Receiver and Peer-to-Peer Manager:

To use Wi-Fi P2P, you need to listen for broadcast intents that tell your
application when certain events have occurred. In your application, instantiate an
IntentFilter and set it to listen for the following:

WIFI_P2P_STATE_CHANGED_ACTION

Indicates whether Wi-Fi P2P is enabled

WIFI_P2P_PEERS_CHANGED_ACTION

Indicates that the available peer list has changed.

WIFI_P2P_CONNECTION_CHANGED_ACTION

Indicates the state of Wi-Fi P2P connectivity has changed.

WIFI_P2P_THIS_DEVICE_CHANGED_ACTION

Indicates this device's configuration details have changed.

EXAMPLE:

private final IntentFilter intentFilter = new IntentFilter(); ...

@Override public void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
8|Page
setContentView(R.layout.main);

// Indicates a change in the Wi-Fi P2P status.


intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACT
ION); // Indicates a change in the list of available peers.

intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTI
ON);

// Indicates the state of Wi-Fi P2P connectivity has changed.


intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGE
D_ACTION);

// Indicates this device's details have changed.


intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGE
D_ACTION);

... }

At the end of the onCreate() method, get an instance of the WifiP2pManager, and call its
initialize()method. This method returns a WifiP2pManager.Channel object, which
you'll use later to connect your app to the Wi-Fi P2P framework. EXAMPLE:
@Override

Channel mChannel;

public void onCreate(Bundle savedInstanceState) { ....

mManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);


mChannel = mManager.initialize(this, getMainLooper(), null); }

9|Page
Now create a new BroadcastReceiver class that you'll use to listen for changes
to the System's Wi-Fi P2P state. In the onReceive() method, add a condition to handle
each P2P state change listed above.

EXAMPLE:

@Override

public void onReceive(Context context, Intent intent) {

String action = intent.getAction();

if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
// Determine if Wifi P2P mode is enabled or not, alert // the Activity.

int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);

if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
activity.setIsWifiP2pEnabled(true); } else {
activity.setIsWifiP2pEnabled(false); } } else if
(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION.equals(action)) {

// The peer list has changed! We should probably do something about //


that.

} else if
(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(acti
on)) {

// Connection state changed! We should probably do something about //


that.

} else if
(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION.equals(acti

10 | P a g e
on)) { DeviceListFragment fragment = (DeviceListFragment)
activity.getFragmentManager() .findFragmentById(R.id.frag_list);
fragment.updateThisDevice((WifiP2pDevice) intent.getParcelableExtra(
WifiP2pManager.EXTRA_WIFI_P2P_DEVICE));

}}

Finally, add code to register the intent filter and broadcast receiver when
your main activity is active, and unregister them when the activity is paused. The best
place to do this is the onResume() and onPause()methods.

/** register the BroadcastReceiver with the intent values to be matched */

@Override

public void onResume() { super.onResume();

receiver = new WiFiDirectBroadcastReceiver(mManager, mChannel, this);


registerReceiver(receiver, intentFilter); }

@Override

public void onPause() { super.onPause(); unregisterReceiver(receiver); }

5.4 Initiate Peer Discovery:

To start searching for nearby devices with Wi-Fi P2P, call discoverPeers().
This method takes the following arguments:

-to-
peer mManager.

invokes for successful and unsuccessful discovery.

11 | P a g e
EXAMPLE:

mManager.discoverPeers(mChannel, new WifiP2pManager.ActionListener() {

@Override

public void onSuccess() {

// Code for when the discovery initiation is successful goes here.

// No services have actually been discovered yet, so this method // can often be
left blank. Code for peer discovery goes in the

// onReceive method, detailed below. }

@Override

public void onFailure(int reasonCode) { // Code for when the discovery


initiation fails goes here. // Alert the user that something went wrong. }
});

Keep in mind that this only initiates peer discovery. The discoverPeers()
method starts the discovery process and then immediately returns. The system notifies
you if the peer discovery process is successfully initiated by calling methods in the
provided action listener. Also, discovery will remain active until a connection is
initiated or a P2P group is formed.

5.5. Connect to a Peer:

In order to connect to a peer, create a new WifiP2pConfig object, and copy


data into it from theWifiP2pDevice representing the device you want to connect to.
Then call the connect() method.

12 | P a g e
EXAMPLE:

@Override

public void connect() { // Picking the first device found on the network.
WifiP2pDevice device = peers.get(0);

WifiP2pConfig config = new WifiP2pConfig(); config.deviceAddress =


device.deviceAddress; config.wps.setup = WpsInfo.PBC;

mManager.connect(mChannel, config, new ActionListener() {

@Override

public void onSuccess() { // WiFiDirectBroadcastReceiver will notify us.


Ignore for now.

@Override

public void onFailure(int reason) {

Toast.makeText(WiFiDirectActivity.this, "Connect failed. Retry.",


Toast.LENGTH_SHORT).show();

} });

The WifiP2pManager.ActionListener implemented in this snippet only


notifies you when the initiationsucceeds or fails. To listen for changes in connection
state, implement theWifiP2pManager.ConnectionInfoListener interface.

Its onConnectionInfoAvailable() callback will notify you when the state of the
connection changes. In cases where multiple devices are going to be connected to a

13 | P a g e
single device (like a game with 3 or more players, or a chat app), one device will be
designated the "group owner".

EXAMPLE:

@Override

public void onConnectionInfoAvailable(final WifiP2pInfo info) {

// InetAddress from WifiP2pInfo struct. InetAddress groupOwnerAddress =


info.groupOwnerAddress.getHostAddress());

// After the group negotiation, we can determine the group owner. if


(info.groupFormed && info.isGroupOwner) { // Do whatever tasks are specific
to the group owner. // One common case is creating a server thread and accepting
// incoming connections. } else if (info.groupFormed) { // The other device
acts as the client. In this case, // you'll want to create a client thread that connects
to the group // owner. } }

Now go back to the onReceive() method of the broadcast receiver, and modify
the section that listens for aWIFI_P2P_CONNECTION_CHANGED_ACTION intent.
When this intent is received, call requestConnectionInfo(). This is an asynchronous call,
so results will be received by the connection info listener you provide as a parameter.
EXAMPLE:

if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(acti
on)) {

if (mManager == null) { return; }

NetworkInfo networkInfo = (NetworkInfo) intent


.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);

14 | P a g e
if (networkInfo.isConnected()) {

// We are connected with the other device, request connection // info


to find group owner IP

mManager.requestConnectionInfo(mChannel, connectionListener); }

5.6 Creating a Switch and enabling Wifi programmatically:

To access the Wi-Fi state, we have to add the following permissions inside
the AndroidManifest.xml file:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />


<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_
STATE" />
<uses-permission android:name="android.permission.INTERNET" />

To enable and disable Wi-Fi, we have to add the following code to the java
file.

public void toggleWiFi(boolean status) {


WifiManager wifiManager = (WifiManager) this.getSystemService(Context.
WIFI_SERVICE);
if (status == true && !wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(true);
} else if (status == false && wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(false);
}
}
5.7 Chatting via Wi-Fi Direct:

After establishing connection between the two Android Devices, there should
be an option for chatting. Chatting operation is similar to transferring files. A textbox
should be provided for two users. Whatever is entered in the box, that is displayed inside
the bubble. One bubble is in Red Color while the other is in Green Color.

15 | P a g e
5.8 Using Swipe operation to Switch between images in Help Section:

A View Pager is created in layout file. An Image Adapter can be used to swipe
between images. Finally set the adapter of View Pager to Image Adapter.

ImageView imageView = new ImageView(context);

int padding = Context.getResources().getDimensionPixelSize


(R.dimen.activity_vertical_margin);

imageView.setPadding(padding, padding, padding, padding);

imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

imageView.setImageResource(GalImages[position]);

((ViewPager) container).addView(imageView, 0);

return imageView;

16 | P a g e
6. CONCLUSION:

The introduction of the Wi-Fi Direct protocol represents an opportunity to


support P2P in a way that can effectively relieve the overload on some mobile
networks. Both Internet Service Providers (ISPs) and consumers could benefit from
this. Wi-Fi Direct will allow a mobile to connect directly with another mobile in its
range that is also running the protocol, with no hubs or routers are involved. Data
rates are expected to be over 250 Mbps with a coverage range of about 100 meters.
In this project, we have first connected the mobile phones via Wi-Fi Direct and then
transferred files between them. The limitations of Wi-Fi direct make it less user
friendly. The numbers of devices with Wi-Fi direct devices are very few. The major
problem a user confronts when using the Wi-Fi direct is that the device are not
compatible with each other. The device crashes or gets stuck if we try to exchange
multimedia. The solution to overcome this problem is to develop the link layer and
see that the connection is still on when the exchange is going on. This Application
would work in a better way if there is device compatibility and Wi-Fi direct is
extended to all the smart devices. Finally, if Wi-Fi Direct becomes a widespread
technology as expected, it faces the challenge of improving coexistence.

17 | P a g e
7. REFERENCES:

[1] http://stackoverflow.com/questions/14207392/android-button-click-go-to-
another-xml-page
[2] http://stackoverflow.com/questions/14229342/navigate-from-one-page-to-
another
[3] http://www.mkyong.com/android/android-activity-from-one-screen-to-another-
screen/

[4] http://developer.android.com/training/basics/firstapp/starting-activity.html

[5] http://stackoverflow.com/questions/25638335/how-to-transfer-files-between-
android-devices-using-wifi-direct

[6] A Measurement study of peer-to-peer file sharing system by Stefan saroiu, p.


Krishna Gummadi, Steven D. Gribble

[7] Device to device communication with Wi-Fi direct by Daniel Campus-Mur,


Andres Garcia-saaveda and pable Serrano

18 | P a g e

Das könnte Ihnen auch gefallen