MCWC - Lab Manual
MCWC - Lab Manual
MCWC - Lab Manual
NAME:
ENROLLMENT NO:
BATCH NO:
YEAR:
CERTIFICATE
Date of Submission:-
ACET(CSE Page 1
)
Mobile Computing and Wireless Communication (2170710)
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
<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:
<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;
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
<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
<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;
ACET(CSE Page 19
)
Mobile Computing and Wireless Communication (2170710)
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)
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:
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:
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)
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).
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.
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)
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">
<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;
ListView mListView;
//Ids of flag Images that are placed in res> drawable folder. They return the int value
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
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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
//Get the String value of the item where the user clicked
intent.putExtra("flag",FlagId[position]);
startActivity(intent);
});
@Override
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
@Override
ACET(CSE Page 33
)
Mobile Computing and Wireless Communication (2170710)
// Handle action bar item clicks here. The action bar will
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;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_country);
Intent i = getIntent();
imageView.setImageResource(FlagId);
@Override
// 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
// Handle action bar item clicks here. The action bar will
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:
<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 :
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)
}
@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);
listOfMessages.setAdapter(adapter);
ACET(CSE Page 42
)
Mobile Computing and Wireless Communication (2170710)
OUTPUT:
ACET(CSE Page 43
)