MCWC - Lab Manual

Download as pdf or txt
Download as pdf or txt
You are on page 1of 48

LABORATORY MANUAL

Mobile Computing and Wireless


Communication
SUBJECT CODE: 2170710
COMPUTER SCIENCE AND ENGINEERING
DEPARTMENT
B.E. 7th SEMESTER

NAME:

ENROLLMENT NO:

BATCH NO:

YEAR:

Amiraj College of Engineering and Technology,


Nr.Tata Nano Plant, Khoraj, Sanand, Ahmedabad.
1
Amiraj College of Engineering and Technology,
Nr.Tata Nano Plant, Khoraj, Sanand, Ahmedabad.

CERTIFICATE

This is to certify that Mr. / Ms. ______________________________________________


Of class____________________ Enrolment No ___________________________has
Satisfactorily completed the course in ____________________________________as
by the Gujarat Technological University for ____ Year (B.E.) semester___ of
Computer Science And Engineering in the Academic year ______.

Date of Submission:-

Faculty Name and Signature Head of Department


(Subject Teacher) (Computer)
Mobile Computing and Wireless Communication (2170710)

CMPUTER SCIENCE AND ENGINEERING


DEPARTMENT
B.E. 7th SEMESTER
SUBJECT: Mobile Computing and Wireless
Communication
SUBJECT CODE: 2170710
List Of Experiments
Sr. Date of Date of
Title Sign Remark
No. Performance submission

Develop an android app which displays


1. “Hello, welcome to Android Lab” message.
Develop an android app which displays a form
2 to get following information from user.
Using Android, Create a login Activity. It asks
“username” and “password” from user. If
3 username and password are valid, it displays
Welcome message using new activity.
Develop calculator Android Application.
4

Study of perform infrared communication.


5

6 Study of Bluetooth file transfer in android.

ACET(CSE Page 1
)
Mobile Computing and Wireless Communication (2170710)

Study of to identify the Bluetooth devices in


7
the wireless range.
Create an application that shows different
8 country name on listview and on selecting it
will show flag of that country.

9 Create an application using firebase.

Case Study n different real time mobile


10 computing services

ACET(CSE Page 2
)
Mobile Computing and Wireless Communication (2170710)

PRACTICAL-1
AIM:- Develop an android app which displays “Hello, welcome to Android Lab”
message.
Software used: Java JDK 1.8, Android Studio.

PROGRAM:
Activity_prac1.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="iwt.waytoweb.practicals.Prac5">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello Welcome to Android Lab!"
android:textSize="25dp"
android:textStyle="bold"
android:textColor="@color/colorAccent"
android:layout_marginTop="20dp"/>
</RelativeLayout>

ACET(CSE Page 3
)
Mobile Computing and Wireless Communication (2170710)

OUTPUT:

ACET(CSE Page 4
)
Mobile Computing and Wireless Communication (2170710)

PRACTICAL-2
AIM:- Develop an android app which displays a form to get following information
from user.

1. Username
2. Password
3. E-mail Address
4. Phone Number
5. Country
6. State
7. Gender
8. Interests
9. Birth Date
10. Birth Time Form should be follow by a button with label “Submit”. When
user click the button, a message should be displayed to user describing the
information entered.
Utilize Suitable UI controls.
PROGRAM:
Activity_prac2.xml:

<?xml version="1.0" encoding="utf-8"?>


<ScrollView android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
tools:context="iwt.waytoweb.practicals.Prac6"
android:orientation="vertical" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Registration"

ACET(CSE Page 5
)
Mobile Computing and Wireless Communication (2170710)

android:textColor="@android:color/holo_blue_dark"
android:textSize="30dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:textStyle="bold|italic"
android:id="@+id/title"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="User Name"
android:inputType="text"
android:layout_marginTop="10dp"
android:textColorHint="@android:color/black"
android:textColor="@android:color/holo_red_light"
android:id="@+id/unm" />

<EditText
android:textColorHint="@android:color/black"
android:textColor="@android:color/holo_red_light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:id="@+id/pwd" />

<EditText
android:textColorHint="@android:color/black"
android:textColor="@android:color/holo_red_light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email ID"
android:inputType="textEmailAddress"
android:id="@+id/eid" />

<EditText
android:textColorHint="@android:color/black"
android:textColor="@android:color/holo_red_light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone Number"
android:inputType="phone"
android:maxLength="10"
android:id="@+id/pno" />

ACET(CSE Page 6
)
Mobile Computing and Wireless Communication (2170710)

<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="@android:color/black"
android:textColor="@android:color/holo_red_light"
android:hint="Country"
android:inputType="phone"
android:maxLength="10"
android:id="@+id/country" />

<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:id="@+id/state">

</Spinner>

<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Male"
android:textColor="@android:color/black" />

<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Female"
android:textColor="@android:color/black" />
</RadioGroup>

<EditText
android:textColorHint="@android:color/black"
android:textColor="@android:color/holo_red_light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Intersets"
android:maxLength="10"
android:id="@+id/interset"/>

<EditText
android:textColorHint="@android:color/black"

ACET(CSE Page 7
)
Mobile Computing and Wireless Communication (2170710)

android:textColor="@android:color/holo_red_light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Birthdate"
android:maxLength="10"
android:id="@+id/birthdate" />

<EditText
android:textColorHint="@android:color/black"
android:textColor="@android:color/holo_red_light"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Birth Time"
android:maxLength="10"
android:id="@+id/birthtime" />

<Button
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginLeft="60dp"
android:text="Register"
android:id="@+id/regi" />
</LinearLayout>
</ScrollView>

Prac 2.java:

package iwt.waytoweb.practicals;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;

public class Prac2 extends AppCompatActivity {


EditText username,password,email,phone,interest,birthdate,birthtime;
AutoCompleteTextView country;
Spinner states;
Button submit;
ArrayAdapter arrayAdapter,arrayAdapter1;

ACET(CSE Page 8
)
Mobile Computing and Wireless Communication (2170710)

String[] Country={"India","Indonesia","Africa","Afghanistan"};
String[] state={"gujarat","goa","maharashtra","rajsthan","aasam","bihar","west bangol"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prac6);
submit= (Button) findViewById(R.id.regi);
states= (Spinner) findViewById(R.id.state);
country= (AutoCompleteTextView) findViewById(R.id.country);
arrayAdapter=new ArrayAdapter(Prac6.this,android.R.layout.simple_spinner_item,state);
states.setAdapter(arrayAdapter);
country.setThreshold(1);
country.setAdapter(arrayAdapter1);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(Prac2.this, "Registered successfully ... ",
Toast.LENGTH_SHORT).show();
}
});
}
}

ACET(CSE Page 9
)
Mobile Computing and Wireless Communication (2170710)

OUTPUT:

ACET(CSE Page 10
)
Mobile Computing and Wireless Communication (2170710)

PRACTICAL-3
AIM:-Using Android, Create a login Activity. It asks “username” and “password”
from user. If username and password are valid, it displays Welcome message using
new activity.
Software used: Java JDK 1.8, Android Studio

PROGRAM:
Activity_prac3.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:layout_centerHorizontal="true"
tools:context="iwt.waytoweb.practicals.Prac7">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:textColor="#FF212355"
android:textStyle="italic"
android:textSize="30dp"
android:gravity="center"
android:layout_marginTop="20dp" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="enter email:"
android:id="@+id/email"
android:layout_marginTop="60dp" />

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="enter password:"

ACET(CSE Page 11
)
Mobile Computing and Wireless Communication (2170710)

android:id="@+id/pwd"
android:layout_marginTop="120dp"
android:inputType="textPassword" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="login"
android:id="@+id/login_btn"
android:layout_marginTop="180dp" />
</RelativeLayout>

Activity_WelcomePage.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="iwt.waytoweb.practicals.WelcomePage">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to the new page!"
android:textSize="25dp"
android:textStyle="bold"
android:textColor="@color/colorAccent"
android:layout_marginTop="20dp"/>
</RelativeLayout>

Prac3.java

package iwt.waytoweb.practicals;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

ACET(CSE Page 12
)
Mobile Computing and Wireless Communication (2170710)

import android.widget.Toast;
public class Prac3 extends AppCompatActivity {
EditText email,password;
Button login;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prac7);
email= (EditText) findViewById(R.id.email);
password= (EditText) findViewById(R.id.pwd);
login= (Button) findViewById(R.id.login_btn);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (email.getText().toString().equals("admin")) {
if( password.getText().toString().equals("1234567"))
{
Intent intent=new Intent(getApplicationContext(),WelcomePage.class);
startActivity(intent);
}
}
else
{
Toast.makeText(Prac3.this, "Try Again. .. ", Toast.LENGTH_SHORT).show();
} } }); } }

ACET(CSE Page 13
)
Mobile Computing and Wireless Communication (2170710)

OUTPUT:

ACET(CSE Page 14
)
Mobile Computing and Wireless Communication (2170710)

PRACTICAL-4
AIM:-Develop calculator Android Application.
Software used: Java JDK 1.8, Android Studio

PROGRAM:
Activity_prac4.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
android:id="@+id/relative1">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edt1"/>

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:id="@+id/button1"
android:layout_marginTop="94dp"
android:layout_below="@+id/edt1"
android:layout_toStartOf="@+id/button4"
android:layout_alignRight="@+id/button4"
android:layout_alignEnd="@+id/button4" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:id="@+id/button2"
android:layout_alignTop="@+id/button1"
android:layout_toLeftOf="@+id/button3"
android:layout_toStartOf="@+id/button3" />

ACET(CSE Page 15
)
Mobile Computing and Wireless Communication (2170710)

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:id="@+id/button3"
android:layout_alignTop="@+id/button2"
android:layout_centerHorizontal="true" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:id="@+id/button4"
android:layout_below="@+id/button1"
android:layout_toLeftOf="@+id/button2" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:id="@+id/button5"
android:layout_alignBottom="@+id/button4"
android:layout_alignLeft="@+id/button2"
android:layout_alignStart="@+id/button2" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:id="@+id/button6"
android:layout_below="@+id/button3"
android:layout_alignLeft="@+id/button3"
android:layout_alignStart="@+id/button3" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:id="@+id/button7"
android:layout_below="@+id/button4"
android:layout_toLeftOf="@+id/button2" />

ACET(CSE Page 16
)
Mobile Computing and Wireless Communication (2170710)

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:id="@+id/button8"
android:layout_below="@+id/button5"
android:layout_alignLeft="@+id/button5"
android:layout_alignStart="@+id/button5" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9"
android:id="@+id/button9"
android:layout_below="@+id/button6"
android:layout_alignLeft="@+id/button6"
android:layout_alignStart="@+id/button6" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:id="@+id/buttonadd"
android:layout_alignTop="@+id/button3"
android:layout_toRightOf="@+id/button3"
android:layout_marginLeft="46dp"
android:layout_marginStart="46dp"
android:layout_alignRight="@+id/edt1"
android:layout_alignEnd="@+id/edt1" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:id="@+id/buttonsub"
android:layout_below="@+id/buttonadd"
android:layout_alignLeft="@+id/buttonadd"
android:layout_alignStart="@+id/buttonadd"
android:layout_alignRight="@+id/buttonadd"
android:layout_alignEnd="@+id/buttonadd" />

<Button

ACET(CSE Page 17
)
Mobile Computing and Wireless Communication (2170710)

style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*"
android:id="@+id/buttonmul"
android:layout_below="@+id/buttonsub"
android:layout_alignLeft="@+id/buttonsub"
android:layout_alignStart="@+id/buttonsub"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="."
android:id="@+id/button10"
android:layout_below="@+id/button7"
android:layout_toLeftOf="@+id/button2" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:id="@+id/button0"
android:layout_below="@+id/button8"
android:layout_alignLeft="@+id/button8"
android:layout_alignStart="@+id/button8" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C"
android:id="@+id/buttonC"
android:layout_below="@+id/button9"
android:layout_alignLeft="@+id/button9"
android:layout_alignStart="@+id/button9" />

<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/"
android:id="@+id/buttondiv"

ACET(CSE Page 18
)
Mobile Computing and Wireless Communication (2170710)

android:layout_below="@+id/buttonmul"
android:layout_alignLeft="@+id/buttonmul"
android:layout_alignStart="@+id/buttonmul"
android:layout_alignRight="@+id/buttonmul"
android:layout_alignEnd="@+id/buttonmul" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="="
android:id="@+id/buttoneql"
android:layout_below="@+id/button0"
android:layout_marginTop="37dp"
android:layout_alignRight="@+id/buttondiv"
android:layout_alignEnd="@+id/buttondiv"
android:layout_alignLeft="@+id/button10"
android:layout_alignStart="@+id/button10" />
</RelativeLayout>

Prac4.java

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {


Button button0 , button1 , button2 , button3 , button4 , button5 , button6 ,
button7 , button8 , button9 , buttonAdd , buttonSub , buttonDivision ,
buttonMul , button10 , buttonC , buttonEqual ;
EditText edt1 ;
float mValueOne , mValueTwo ;
boolean mAddition , mSubtract ,mMultiplication ,mDivision ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

button0 = (Button) findViewById(R.id.button0);


button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button4 = (Button) findViewById(R.id.button4);

ACET(CSE Page 19
)
Mobile Computing and Wireless Communication (2170710)

button5 = (Button) findViewById(R.id.button5);


button6 = (Button) findViewById(R.id.button6);
button7 = (Button) findViewById(R.id.button7);
button8 = (Button) findViewById(R.id.button8);
button9 = (Button) findViewById(R.id.button9);
button10 = (Button) findViewById(R.id.button10);
buttonAdd = (Button) findViewById(R.id.buttonadd);
buttonSub = (Button) findViewById(R.id.buttonsub);
buttonMul = (Button) findViewById(R.id.buttonmul);
buttonDivision = (Button) findViewById(R.id.buttondiv);
buttonC = (Button) findViewById(R.id.buttonC);
buttonEqual = (Button) findViewById(R.id.buttoneql);
edt1 = (EditText) findViewById(R.id.edt1);

button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"1");
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"2");
}
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"3");
}
});
button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"4");
}
});
button5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"5");
}
});
button6.setOnClickListener(new View.OnClickListener() {
@Override

ACET(CSE Page 20
)
Mobile Computing and Wireless Communication (2170710)

public void onClick(View v) {


edt1.setText(edt1.getText()+"6");
}
});
button7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"7");
}
});
button8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"8");
}
});
button9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"9");
}
});
button0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+"0");
}
});
buttonAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

if (edt1 == null){
edt1.setText("");
}else {
mValueOne = Float.parseFloat(edt1.getText() + "");
mAddition = true;
edt1.setText(null);
}
}
});
buttonSub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueOne = Float.parseFloat(edt1.getText() + "");
mSubtract = true ;

ACET(CSE Page 21
)
Mobile Computing and Wireless Communication (2170710)

edt1.setText(null);
}
});
buttonMul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueOne = Float.parseFloat(edt1.getText() + "");
mMultiplication = true ;
edt1.setText(null);
}
});
buttonDivision.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueOne = Float.parseFloat(edt1.getText()+"");
mDivision = true ;
edt1.setText(null);
}
});
buttonEqual.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mValueTwo = Float.parseFloat(edt1.getText() + "");
if (mAddition == true){
edt1.setText(mValueOne + mValueTwo +"");
mAddition=false;
}
if (mSubtract == true){
edt1.setText(mValueOne - mValueTwo+"");
mSubtract=false;
}
if (mMultiplication == true){
edt1.setText(mValueOne * mValueTwo+"");
mMultiplication=false;
}
if (mDivision == true){
edt1.setText(mValueOne / mValueTwo+"");
mDivision=false;
}
}
});
buttonC.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText("");
}

ACET(CSE Page 22
)
Mobile Computing and Wireless Communication (2170710)

});
button10.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText(edt1.getText()+".");
}
});
}

OUTPUT:

ACET(CSE Page 23
)
Mobile Computing and Wireless Communication (2170710)

PRACTICAL-5
AIM:-Study of perform infrared communication.

THEORY:-
IR data transmission is also employed in short-range communication among computer
peripherals and personal digital assistants. These devices usually conform to standards published
by IrDA, the Infrared Data Association. Remote controls and IrDA devices use infrared light-
emitting diodes (LEDs) to emit infrared radiation that is focused by a plastic lens into a narrow
beam. The beam is modulated, i.e. switched on and off, to prevent interference from other
sources of infrared (like sunlight or artificial lighting). The receiver uses a silicon photodiode to
convert the infrared radiation to an electric current. It responds only to the rapidly pulsing signal
created by the transmitter, and filters out slowly changing infrared radiation from ambient light.
Infrared communications are useful for indoor use in areas of high population density. IR does
not penetrate walls and so does not interfere with other devices in adjoining rooms. Infrared is
the most common way for remote controls to command appliances. Infrared remote control
protocols like RC-5, SIRC, are used to communicate with infrared.

Free space optical communication using infrared lasers can be a relatively inexpensive way to
install a communications link in an urban area operating at up to 4 gigabit/s, compared to the cost
of burying fiber optic cable, except for the radiation damage. "Since the eye cannot detect IR,
blinking or closing the eyes to help prevent or reduce damage may not happen."

Infrared lasers are used to provide the light for optical fiber communications systems. Infrared
light with a wavelength around 1,330 nm (least dispersion) or 1,550 nm (best transmission) are
the best choices for standard silica fibers.

IR data transmission of encoded audio versions of printed signs is being researched as an aid for
visually impaired people through the RIAS (Remote Infrared Audible Signage) project.
Transmitting IR data from one device to another is sometimes referred to as beaming.

ACET(CSE Page 24
)
Mobile Computing and Wireless Communication (2170710)

PRACTICAL-6
AIM:-Study of Bluetooth file transfer in android.

Theory:
To develop an Android application making use of data transfers via Bluetooth (BT), one would
logically start at the Android Developer's Bluetooth page, where all the required steps are
described in details: device discovery, pairing, client/server sockets, RFCOMM channels, etc.

But before jumping into sockets and threads programming just to perform a basic BT operation,
let's consider a simpler alternative, based on one of Android's most important features: the ability
for a given application to send the user to another one, which, in this case, would be the device's
default BT application. Doing so will have the Android OS itself do all the low-level work for
us. First things first, a bit of defensive programming:
import android.bluetooth.BluetoothAdapter;
//...
// inside method
// Check if bluetooth is supported
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
if (btAdapter == null) {
// Device does not support Bluetooth
// Inform user that we're done.
}

The above is the first check we need to perform. Done that, let's see how he can start BT from
within our own application.

Android will then display all the activities that are able to complete the action we want, in
a chooser list. Here's an example:

// bring up Android chooser


Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file_to_transfer) );
//...
startActivity(intent);

ACET(CSE Page 25
)
Mobile Computing and Wireless Communication (2170710)

In the code snippet above, we are letting the Android system know that we intend to send a text
file. The system then displays all installed applications capable of handling that action:

We can see that the BT application is among those handlers. We could of course let the user pick
that application from the list and be done with it. But if we feel we should be a tad more user-
friendly, we need to go further and start the application ourselves, instead of simply displaying it
in a midst of other unnecessary options...But how?

One way to do that would be to use Android's Package Manager this way:

//list of apps that can handle our intent


PackageManager pm = getPackageManager();
List appsList = pm.queryIntentActivities( intent, 0);
if(appsList.size() > 0 {
// proceed
}

The above Package Manager method returns the list we saw earlier of all activities susceptible to
handle our file transfer intent, in the form of a list of Resolve Info objects that encapsulate
information we need:

packageName
//select bluetooth =
String packageName = null; info.activityInf
SCtrEinTg(CcSlE
A as)sName = o.packageNam
null; boolean found = e;
false;
for(ResolveInfo info: appsList){
Mobile Computing and Wireless Communication (2170710)

Page 24
Mobile Computing and Wireless Communication (2170710)

We now have the necessary information to start BT ourselves:

//set our intent to launch Bluetooth


intent.setClassName(packageName, className);
startActivity(intent);

What we did was to use the package and its corresponding class retrieved earlier. Since we are a
curious bunch, we may wonder what the class name for the "com.android.bluetooth" package is.
This is what we would get if we were to print it
out: com.broadcom.bt.app.opp.OppLauncherActivity. OPP stands for Object Push Profile, and is
the Android component allowing to wirelessly share files.

All fine and dandy, but in order for all the above code to be of any use, BT doesn't simply need
to be supported by the device, but also enabled by the user. So one of the first things we want to
do, is to ask the user to enable BT for the time we deem necessary (here, 300 seconds):
import android.bluetooth.BluetoothAdapter;
//...
// duration that the device is discoverable
private static final int DISCOVER_DURATION = 300;
// our request code (must be greater than zero)
private static final int REQUEST_BLU = 1;
//...
public void enableBlu(){
// enable device discovery - this will automatically enable Bluetooth
IntentdiscoveryIntent= new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoveryIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION,
DISCOVER_DURATION );
startActivityForResult(discoveryIntent, REQUEST_BLU);
}

ACET(CSE Page 25
)
Mobile Computing and Wireless Communication (2170710)

Once we specify that we want to get a result back from our activity with startActivityForResult,
the following enabling dialog is presented to the user:

Now whenever the activity finishes, it will return the request codewe have sent
(REQUEST_BLU), along with the data and a result code to our main activity through
the onActivityResult callback method. We know which request code we have to check against,
but how about the result code? Simple: if the user responds "No" to the above permission
request (or if an error occurs), the result code will be RESULT_CANCELED. On the other hand,
if the user accepts, the BT documentation specifies that the result code will be equal to the
duration that the device is discoverable (i.e. DISCOVER_DURATION, i.e. 300).

So the way to process the BT dialog above would be:

// When startActivityForResult completes...


protected void onActivityResult (int requestCode,
int resultCode,
Intent data) {
if (resultCode == DISCOVER_DURATION
&& requestCode == REQUEST_BLU) {
// processing code goes here
}
else{ // cancelled or error
Toast.makeText(this, R.string.blu_cancelled,
Toast.LENGTH_SHORT).show();
}
}
Putting all our processing flow in order, here's what we are basically doing:

ACET(CSE Page 26
)
Mobile Computing and Wireless Communication (2170710)

Are we done yet? Almost. Last but not least, we need to ask for the BT permissions in the
Android manifest:

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

We're ready to deploy now. To test all this, we need to use at least two Android devices, one
being the file sender (where our application is installed) and the other any receiving device
supporting BT. Here are the screen shots. For the sender:

ACET(CSE Page 27
)
Mobile Computing and Wireless Communication (2170710)

ACET(CSE Page 28
)
Mobile Computing and Wireless Communication (2170710)

PRACTICAL-7
AIM:-Study of to identify the Bluetooth devices in the wireless range.
Software used: Python 3.4 and PyBluez package(version 0.22)

Theory:-
Bluetooth is a wireless technology standard for exchanging data over short distances (using
short-wavelength UHF radio waves in the ISM band from 2.4 to 2.485 GHz) from fixed and
mobile devices, and building personal area networks (PANs). Invented by telecom
vendor Ericsson in 1994, it was originally conceived as a wireless alternative to RS-232 data
cables.

Bluetooth is managed by the Bluetooth Special Interest Group (SIG), which has more than
30,000 member companies in the areas of telecommunication, computing, networking, and
consumer electronics. The IEEE standardized Bluetooth as IEEE 802.15.1, but no longer
maintains the standard. The Bluetooth SIG oversees development of the specification, manages
the qualification program, and protects the trademarks. A manufacturer must meet Bluetooth SIG
standards to market it as a Bluetooth device. A network of patents apply to the technology, which
are licensed to individual qualifying devices.

Implementation of Bluetooth: Bluetooth is a packet-based protocol with a master-slave structure.


One master may communicate with up to seven slaves in a piconet. All devices share the master's
clock. Packet exchange is based on the basic clock, defined by the master, which ticks at 312.5
µs intervals. Two clock ticks make up a slot of 625 µs, and two slots make up a slot pair of 1250
µs. In the simple case of single-slot packets the master transmits in even slots and receives in odd
slots. The slave, conversely, receives in even slots and transmits in odd slots. Packets may be 1, 3
or 5 slots long, but in all cases the master's transmission begins in even slots and the slave's in
odd slots.

Connection establishment and communication: A master BR/EDR Bluetooth device can


communicate with a maximum of seven devices in a piconet (an ad-hoc computer network using
Bluetooth technology), though not all devices reach this maximum. The devices can switch roles,
by agreement, and the slave can become the master (for example, a headset initiating a
connection to a phone necessarily begins as master—as initiator of the connection—but may
subsequently operate as slave).

At any given time, data can be transferred between the master and one other device (except for
the little-used broadcast mode[citation needed]). The master chooses which slave device to
address; typically, it switches rapidly from one device to another in a round-robin fashion. Since
it is the master that chooses which slave to address, whereas a slave is (in theory) supposed to
listen in each receive slot, being a master is a lighter burden than being a slave. Being a master of
seven slaves is possible; being a slave of more than one master is possible. The specification is
vague as to required behavior in scatternets.

ACET(CSE Page 29
)
Mobile Computing and Wireless Communication (2170710)

PROGRAM:

import bluetooth

nearby_devices = bluetooth.discover_devices(lookup_names=True)

print("found %d devices" % len(nearby_devices))

for addr, name in nearby_devices:

print(" %s - %s" % (addr, name))

OUTPUT:

ACET(CSE Page 30
)
Mobile Computing and Wireless Communication (2170710)

PRACTICAL-8
AIM:- Create an application that shows different country name on listview and on
selecting it will show flag of that country.

activity_main.xml:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<!-- Here we are defining ListView in our XML file-->

<ListView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:id="@+id/list"/>

</RelativeLayout>

MainActivity.java

package com.coderefer.simplelistview;

import android.content.Intent;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

ACET(CSE Page 31
)
Mobile Computing and Wireless Communication (2170710)

import android.widget.AdapterView;

import android.widget.ArrayAdapter;

import android.widget.ListView;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

//Defining android ListView

ListView mListView;

//Elements that will be displayed in android ListView

String[] Countries = new String[]{"India", "Australia", "Newzealand",

"Indonesia", "China", "Russia", "Japan", "South Korea"};

//Ids of flag Images that are placed in res> drawable folder. They return the int value

int[] FlagId = new int[]{R.drawable.flag_india, R.drawable.flag_australia,

R.drawable.flag_newzealand,R.drawable.flag_indonesia,

R.drawable.flag_china, R.drawable.flag_russia,R.drawable.flag_japan,

R.drawable.flag_southkorea};

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

mListView = (ListView) findViewById(R.id.list);

//Declaring Array adapter

ArrayAdapter<String> countryAdapter = new


ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, Countries);

//Setting the android ListView's adapter to the newly created adapter

mListView.setAdapter(countryAdapter);

ACET(CSE Page 32
)
Mobile Computing and Wireless Communication (2170710)

mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

//The position where the list item is clicked is obtained from the

//the parameter position of the android listview

int itemPosition = position;

//Get the String value of the item where the user clicked

String itemValue = (String) mListView.getItemAtPosition(position

//In order to start displaying new activity we need an intent

Intent intent = new Intent(getApplicationContext(),CountryActivity.class);

//Putting the Id of image as an extra in intent

intent.putExtra("flag",FlagId[position]);

//Here we will pass the previously created intent as parameter

startActivity(intent);

});

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.menu_main, menu);

return true;

@Override

public boolean onOptionsItemSelected(MenuItem item) {

ACET(CSE Page 33
)
Mobile Computing and Wireless Communication (2170710)

// Handle action bar item clicks here. The action bar will

// automatically handle clicks on the Home/Up button, so long

// as you specify a parent activity in AndroidManifest.xml.

int id = item.getItemId();

//noinspection SimplifiableIfStatement

if (id == R.id.action_settings) {

return true;

return super.onOptionsItemSelected(item);

activity_country.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

android:paddingBottom="@dimen/activity_vertical_margin"

tools:context="com.coderefer.simplelistview.CountryActivity">

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/ivCountryFlag"

android:layout_centerVertical="true"

ACET(CSE Page 34
)
Mobile Computing and Wireless Communication (2170710)

android:layout_centerHorizontal="true" />

</RelativeLayout>

CountryActivity.java

package com.coderefer.simplelistview;

import android.content.Intent;

import android.support.v7.app.ActionBarActivity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.widget.ImageView;

public class CountryActivity extends ActionBarActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_country);

ImageView imageView = (ImageView) findViewById(R.id.ivCountryFlag);

Intent i = getIntent();

int FlagId = i.getIntExtra("flag",0);

imageView.setImageResource(FlagId);

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.menu_country, menu);

return true;

ACET(CSE Page 35
)
Mobile Computing and Wireless Communication (2170710)

@Override

public boolean onOptionsItemSelected(MenuItem item) {

// Handle action bar item clicks here. The action bar will

// automatically handle clicks on the Home/Up button, so long

// as you specify a parent activity in AndroidManifest.xml.

int id = item.getItemId();

//noinspection SimplifiableIfStatement

if (id == R.id.action_settings) {

return true;

return super.onOptionsItemSelected(item);

OUTPUT:-

ACET(CSE Page 36
)
Mobile Computing and Wireless Communication (2170710)

PRACTICAL-9
AIM:- Create an application using firebase.
Software used: Java JDK 1.8, Android Studio, Firebase account.

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/activity_main"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context="com.tutsplus.mychatapp.MainActivity">

<android.support.design.widget.FloatingActionButton

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:clickable="true"

android:src="@drawable/ic_send_black_24dp"

android:id="@+id/fab"

android:tint="@android:color/white"

android:layout_alignParentBottom="true"

android:layout_alignParentEnd="true"

ACET(CSE Page 37
)
Mobile Computing and Wireless Communication (2170710)

app:fabSize="mini" />

<android.support.design.widget.TextInputLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_toLeftOf="@id/fab"

android:layout_alignParentBottom="true"

android:layout_alignParentStart="true">

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Input"

android:id="@+id/input"/>

</android.support.design.widget.TextInputLayout>

<ListView

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_alignParentTop="true"

android:layout_alignParentStart="true"

android:layout_above="@id/fab"

android:dividerHeight="16dp"

android:divider="@android:color/transparent"

android:id="@+id/list_of_messages"

android:layout_marginBottom="16dp"/>

</RelativeLayout>

message.xml:

ACET(CSE Page 38
)
Mobile Computing and Wireless Communication (2170710)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent" android:layout_height="match_parent">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_alignParentStart="true"

android:id="@+id/message_user"

android:textStyle="normal|bold" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBottom="@+id/message_user"

android:layout_alignParentEnd="true"

android:id="@+id/message_time" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/message_user"

android:layout_alignParentStart="true"

android:layout_marginTop="5dp"

android:id="@+id/message_text"

android:textAppearance="@style/TextAppearance.AppCompat.Body1"

android:textSize="18sp" />

</RelativeLayout>

ACET(CSE Page 39
)
Mobile Computing and Wireless Communication (2170710)

ChatMessage.java :

public class ChatMessage {


private String messageText;
private String messageUser;
private long messageTime;

public ChatMessage(String messageText, String messageUser) {


this.messageText = messageText;
this.messageUser = messageUser;
// Initialize to current time
messageTime = new Date().getTime();
}
public ChatMessage(){
}
public String getMessageText() {
return messageText;
}
public void setMessageText(String messageText) {
this.messageText = messageText;
}
public String getMessageUser() {
return messageUser;
}
public void setMessageUser(String messageUser) {
this.messageUser = messageUser;
}
public long getMessageTime() {
return messageTime;
}
public void setMessageTime(long messageTime) {
this.messageTime = messageTime;
}
}

Handle User Sign-In

if(FirebaseAuth.getInstance().getCurrentUser() == null) {
// Start sign in/sign up activity
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.build(),
SIGN_IN_REQUEST_CODE
);
} else {

ACET(CSE Page 40
)
Mobile Computing and Wireless Communication (2170710)

// User is already signed in. Therefore, display


// a welcome Toast
Toast.makeText(this,
"Welcome " + FirebaseAuth.getInstance()
.getCurrentUser()
.getDisplayName(),
Toast.LENGTH_LONG)
.show();
// Load chat room contents
displayChatMessages();
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == SIGN_IN_REQUEST_CODE) {
if(resultCode == RESULT_OK) {
Toast.makeText(this,
"Successfully signed in. Welcome!",
Toast.LENGTH_LONG)
.show();
displayChatMessages();
} else {
Toast.makeText(this,
"We couldn't sign you in. Please try again later.",
Toast.LENGTH_LONG)
.show();
// Close the app
finish();
}
}

}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == R.id.menu_sign_out) {
AuthUI.getInstance().signOut(this)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(MainActivity.this,
"You have been signed out.",
Toast.LENGTH_LONG)
.show();
// Close activity
finish();

ACET(CSE Page 41
)
Mobile Computing and Wireless Communication (2170710)

}
});
}
return true;
}
FloatingActionButton fab =
(FloatingActionButton)findViewById(R.id.fab);

fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
EditText input = (EditText)findViewById(R.id.input);

// Read the input field and push a new instance


// of ChatMessage to the Firebase database
FirebaseDatabase.getInstance()
.getReference()
.push()
.setValue(new ChatMessage(input.getText().toString(),
FirebaseAuth.getInstance()
.getCurrentUser()
.getDisplayName())
);
// Clear the input
input.setText("");
}
});
ListView listOfMessages = (ListView)findViewById(R.id.list_of_messages);
adapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class,
R.layout.message, FirebaseDatabase.getInstance().getReference()) {
@Override
protected void populateView(View v, ChatMessage model, int position) {
// Get references to the views of message.xml
TextView messageText = (TextView)v.findViewById(R.id.message_text);
TextView messageUser = (TextView)v.findViewById(R.id.message_user);
TextView messageTime = (TextView)v.findViewById(R.id.message_time);
// Set their text
messageText.setText(model.getMessageText());
messageUser.setText(model.getMessageUser());
// Format the date before showing it
messageTime.setText(DateFormat.format("dd-MM-yyyy (HH:mm:ss)",
model.getMessageTime()));
}
};

listOfMessages.setAdapter(adapter);

ACET(CSE Page 42
)
Mobile Computing and Wireless Communication (2170710)

OUTPUT:

ACET(CSE Page 43
)

You might also like