100% found this document useful (1 vote)
270 views

MCWC Lab File

The document discusses Android versions and the Android development environment setup. It provides details on: 1) The different Android versions from 1.0 to Oreo, along with their code names and release dates. 2) The key components needed for the Android development environment including Java, Android SDK, and Eclipse IDE. 3) Steps to download and install the Android SDK and ADT plugin to configure the development environment in Eclipse. 4) An overview of debugging tools Logcat and DDMS, how to access DDMS in Eclipse, and uses of Logcat to view system logs.

Uploaded by

BhruguTundeliya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
270 views

MCWC Lab File

The document discusses Android versions and the Android development environment setup. It provides details on: 1) The different Android versions from 1.0 to Oreo, along with their code names and release dates. 2) The key components needed for the Android development environment including Java, Android SDK, and Eclipse IDE. 3) Steps to download and install the Android SDK and ADT plugin to configure the development environment in Eclipse. 4) An overview of debugging tools Logcat and DDMS, how to access DDMS in Eclipse, and uses of Logcat to view system logs.

Uploaded by

BhruguTundeliya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 54

SUBJECT : MCWC SUBJECT CODE : 2170710

LAB: 1
Introduction to Android and its version. Configuring android
development environment.
Android: - Android is a mobile operating system developed by Google. It is used by
several smartphones and tablets.
The Android operating system (OS) is based on the Linux kernel. Unlike Apple's iOS, Android
is open source, meaning developers can modify and customize the OS for each phone.
Therefore, different Android-based phones often have different graphical user interfaces GUIs
even though they use the same OS.

Android Versions: -
Code name Version number Initial release date API level Security patches

Petit Four 1.1 February 9, 2009 2 Unsupported

(No codename) 1.0 September 23, 2008 1 Unsupported

Cupcake 1.5 April 27, 2009 3 Unsupported

Donut 1.6 September 15, 2009 4 Unsupported

Eclair 2.0 – 2.1 October 26, 2009 5–7 Unsupported

Froyo 2.2 – 2.2.3 May 20, 2010 8 Unsupported

Gingerbread 2.3 – 2.3.7 December 6, 2010 9 – 10 Unsupported

Honeycomb 3.0 – 3.2.6 February 22, 2011 11 – 13 Unsupported

Ice Cream
4.0 – 4.0.4 October 18, 2011 14 – 15 Unsupported
Sandwich

Jelly Bean 4.1 – 4.3.1 July 9, 2012 16 – 18 Unsupported

KitKat 4.4 – 4.4.4 October 31, 2013 19 – 20 Supported

Lollipop 5.0 – 5.1.1 November 12, 2014 21 – 22 Supported

Marshmallow 6.0 – 6.0.1 October 5, 2015 23 Supported

Nougat 7.0 – 7.1.2 August 22, 2016 24 – 25 Supported

Oreo 8.0 August 21, 2017 26 Supported

1
150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

You will learn how to set the environment to develop Android application .This Comprises of
downloading, configuring and installing several software components required to make the IDE
complete and ready for developing purpose.

Required components to setup your Android IDE are as follows:

 Java development kit or JDK since applications are being developed in java
 Android Software Development Kit(SDK)
 Eclipse IDE

Downloading and Installing the Android SDK:

The Android SDK is a complete set of API Libraries and developer tools. By configuring these
tools and libraries with Eclipse, an Android-specific development environment will be ready.
The link to download the latest Android SDK from the Android developer’s website is as
follows:

http://developers.android.com/sdk/index.html

The Android SDK is a kit, which helps in buildings, testing and debugging application for
Android. By accessing above link, you will be directed to the Android developer’s site, where
you will find [Download the SDK button]. This button will download Android SDK as an ADT
Bundle that includes everything you need to develop Android application. This bundle includes
following items:

 Eclipse + ADT Plugin


 Android SDK tools
 The Latest Platform Android
 The Latest Platform system image for the emulator

You need to click on it and then select the check box to accept its terms and condition. Finally,
the Android SDK pack will be downloaded as a zip folder.

Now, perform the following steps to install Android SDK:

1. Unzip the ZIP file named adt-bundle-<os_platform>.zip and save it to an appropriate


location, such as D:\Development.
2. Open the adt-bundle-<os_platform>/eclipse/ directory and launch Eclipse. The Java –
ADT window will open as shown in Figure 1:

2
150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Figure 1: Java-ADT window

You should not move any of the file or directories from the adt-bundle-<os_platform> directory;
otherwise ADT will not be able to locate the SDT and you will need to manually update the ADT
preferences.

ADT is the extension to increase the capabilities of Eclipse to create Android Projects, create an
Application UI, add packages of android API, and debug the Android application. The steps to
download the ADT plugin are as follows:

1. Start the Eclipse from the location you have installed earlier.

2. Select Help Install New Software, as shown in Figure 2:

3
150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Figure 2: Showing Help menu

3. Click the Add button from the top-right, as shown in Figure 3:

Figure 3

4
150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

4. ADT plugins as named and enter the following location in the location box:

https://dl-ssl.google.com/android/eclipse/

If any problem persists in fetching ADT plugins, just try to use http instead of https in the
uniform Resource locator

5. Click the OK button.

The Add Repository diagonals box disappears.

6. Click the Select All button and then click the Next button, as shown in Figure 4:

Figure 4

In the next window, you will see the tools to be downloaded.

7. Click the Next button. Read and accept the license agreement Terms and Conditions appearing
in the next page.

8. Click the Finish button. There might be home security warning, just ignore them.

9. Click the OK button on the box that is displaying warning. This will start the installation. On
completion of installing, you will be prompted to restart the Eclipse.

10. Click the Restart button to restart the Eclipse.

5
150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Practical 2
Aim : Study of debugging tools: Logcat and DDMS.
 Introduction
 In this increasingly fragmented and complex world of Android application development,
thoroughly testing your Android app is becoming a real challenge. One of the biggest headaches
is how to test your Android app in all the conceivable real-world scenarios. To make matters
worse, most Android app development scenarios are mobile-specific, and will be unfamiliar to
developers who have previously dealt only with desktop and Web environments.
 You may have an Android device with your targeted operating system on hand, but you'll still
struggle to recreate every possible situation, which is why the emulator has become the Android
developer's best friend. But even Android emulators have their limitations, and the testing phase
is crucial to the success of your Android app.
 The good news for Android developers is that once you have the Android SDK and ADT plugin
installed, you'll have access to one of the most powerful debugging tools out there: the Dalvik
Debug Monitor Server (DDMS.)
 What is DDMS?
 The DDMS is an invaluable tool for checking the memory usage of your Android app, drilling
down into errors, simulating a range of real-world conditions, and much more. The DDMS can
analyze an Android project running in the emulator, or it can be connected to a real device (if both
are connected, the DDMS will default to the emulator.)
 Where to find DDMS?
 To access the DDMS, open the Window menu and select Open Perspective. Select Other, which
will present you with a list of additional options. Select DDMS.

 This will bring up the DDMS perspective with the default views (note that you can always access
additional views by opening the Window menu and selecting Show View). In this article, I'll take
you through these different DDMS views and explain why they're so important for Android
development

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

 What is Logcat?
 Logcat is a command-line tool that dumps a log of system messages, including stack traces when
the device throws an error and messages that you have written from your app with the Log class. 
 Syntax in Command-Line
 To run logcat through the adb shell, the general usage is:
[adb] logcat [<option>] ... [<filter-spec>] ...

 You can run logcat as an adb command or directly in a shell prompt of your emulator or
connected device. To view log output using adb, navigate to your SDK platform-tools/ directory
and execute:

adb logcat

 Filtering Log Output


 The tag of a log message is a short string indicating the system component from which the
message originates (for example, "View" for the view system).
 The priority is one of the following character values, ordered from lowest to highest priority:
o V: Verbose (lowest priority)
o D: Debug
o I: Info
o W: Warning
o E: Error
o F: Fatal
o S: Silent (highest priority, on which nothing is ever printed)

 Logging from Code


 The Log class allows you to create log entries in your code that display in the logcat tool.
Common logging methods include:
o Log.v(String, String) (verbose)
o Log.d(String, String) (debug)
o Log.i(String, String) (information)
o Log.w(String, String) (warning)
o Log.e(String, String) (error)

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Practical 3
Aim : Event Handling in Android (Three Methods).
 Introduction
 Events are a useful way to collect data about a user's interaction with interactive components of
Applications.Like button presses or screen touch etc. The Android framework maintains an event
queue as first-in, first-out (FIFO) basis. You can capture these events in your program and take
appropriate action as per requirements.
 What is Event Handler?
 When an event happens and we have registered an event listener for the event, the event listener
calls the Event Handlers, which is the method that actually handles the event.
 Event Handling Methods
o onClick()
This is called when the user either clicks or touches or focuses upon any widget like button, text, image
etc. We use onClick() event handler to handle such event.

Application.java

package com.javacodegeeks.android.example.androidonclicklistenerexample;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.view.View.OnClickListener;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
Button button = (Button) findViewById(R.id.button1);

button.setOnClickListener(new OnClickListener() {

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "Button Clicked",
Toast.LENGTH_SHORT).show();
}

});
return true;
}
}
o onLongClick()

This is called when the user either clicks or touches or focuses upon any widget like button, text, image
etc. for one or more seconds. You will use onLongClick() event handler to handle such event.

Activity.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=".MainActivity">

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Event Handling "
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="30dp"/>

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point "
android:textColor="#ff87ff09"
android:textSize="30dp"
android:layout_above="@+id/imageButton"
android:layout_centerHorizontal="true"

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

android:layout_marginBottom="40dp" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Small font"
android:id="@+id/button"
android:layout_below="@+id/imageButton"
android:layout_centerHorizontal="true" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Font"
android:id="@+id/button2"
android:layout_below="@+id/button"
android:layout_alignRight="@+id/button"
android:layout_alignEnd="@+id/button" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/textView"
android:layout_below="@+id/button2"
android:layout_centerHorizontal="true"
android:textSize="25dp" />

</RelativeLayout>

o onFocusChange()

This is called when the widget looses its focus ie. user goes away from the view item. You will use
onFocusChange() event handler to handle such event.

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Practical: 4
Aim: Passing Data to Another Activity (Explicit Intent)

MainActivity.java
package com.example.abc;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public
class MainActivity extends ActionBarActivity {
Button btn1, btn2;
Toast toast;
EditText et1, et2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1 =
(EditText) findViewById(R.id.editText1);
et2 = (EditText) findViewById(R.id.editText2);
}
public void click(View v) {
String str1 = et1.getText().toString();
String str2 = et2.getText().toString();
Intent intent = new Intent(getApplicationCont
ext(), Activity2.class);
intent.putExtra("name", str1);
intent.putExtra("email", str2);
startActivity(intent);
}
}
G.H.P ATEL COLLEGE OF ENGINEERING AND TECHNOLOGY
SUBJECT NAME:

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

MOBILE COMPUTING AND WIRELESS


COMMUNICATION
SUBJECT CODE :
2170710
160113107001
PAGE NO
-
Activity2.java
package com.example.abc;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import
android.widget.TextView;
public class Activity2 extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity2);
Bundle bundle = getIntent(
).getExtras();
String s1 = bundle.getString("name");
String s2 = bundle.getString("email");
TextView t = (TextView) findViewById(R.id.textView1);
t.setText("Welcome "+s1+" "+s2);
}
}
Output:

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Practical: 5
Aim: Passing Data to Another Activity (Intent)
Examples of Implicit Intent.

CODE
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.p1.MainActivity"
tools:ignore="MergeRootFrame" >

<Button
android:id="@+id/button1"
android:onClick="clicked_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/b" />

<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >

<requestFocus />
</EditText>

</LinearLayout>
activity_main_activity2.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.p1.MainActivity2"
tools:ignore="MergeRootFrame" >

<TextView
android:id="@+id/textView1"
android:layout_width="157dp"
android:layout_height="34dp"
android:text="TextView" />

</LinearLayout>

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

MainActivity.java
package com.example.p1;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends ActionBarActivity {
EditText et1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=(EditText)findViewById(R.id.editText1);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
String str;
str=et1.getText().toString();
Intent intent=new Intent(getApplicationContext(),MainActivity2.class);
intent.putExtra("key", str);
startActivity(intent);
// TODO Auto-generated method stub
}
});
}}

MainActivity2.java
package com.example.p1;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.TextView;
public class MainActivity2 extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity2);
Bundle bundle=getIntent().getExtras();
String str=bundle.getString("key");
TextView t=(TextView) findViewById(R.id.textView1);
t.setText("hello "+str);
}
}

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

OUTPUT

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Practical 6
Method Description
onCreate called when activity is first created.
onStart called when activity is becoming visible to the user
onResume called when activity will start interacting with the user
onPause called when activity is not visible to the user
onStop called when activity is no longer visible to the user
onRestart called after your activity is stopped, prior to start
onDestroy called before the activity is destroyed

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

File: activity_main.xml

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


<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

tools:context="example.javatpoint.com.activitylifecycle.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

It provides the details about the invocation of life cycle methods of activity. In this example,
the content of the logcat are displayed.

File: MainActivity.java
package example.javatpoint.com.activitylifecycle;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("lifecycle","onCreate invoked");
}
@Override
protected void onStart() {
super.onStart();
Log.d("lifecycle","onStart invoked");
}
@Override
protected void onResume() {
super.onResume();
Log.d("lifecycle","onResume invoked");
}
@Override

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

protected void onPause() {


super.onPause();
Log.d("lifecycle","onPause invoked");
}
@Override
protected void onStop() {
super.onStop();
Log.d("lifecycle","onStop invoked");
}
@Override
protected void onRestart() {
super.onRestart();
Log.d("lifecycle","onRestart invoked");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d("lifecycle","onDestroy invoked");
}
}
Output

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

logcat: onCreate, onStart and onResume methods are invoked.

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Now click on the HOME Button. Then, onPause method is invoked.

After a while, onStop method is invoked.

Now emulator is on the home. Now click on the center button to launch the app again.
Now click on the lifecycleactivity icon.

In emulator, application is started again.


Now click on the back button. Now you will see onPause methods is invoked.

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

After a while, onStop and onDestroy methods are invoked.

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Practical-7

Aim: Develop simple android app to simulate the options Menu.

Menu_main.xml
<menu 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"
tools:context="com.example.menubar.MainActivity" >

<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:title="@string/action_settings"
app:showAsAction="never">
<menu>
<item
android:id="@+id/action_settings1"
android:orderInCategory="100"
android:title="Settings 1"
app:showAsAction="never"/>
<item
android:id="@+id/action_settings2"
android:orderInCategory="100"
android:title="Settings 2"
app:showAsAction="never"/>
</menu>
</item>
<item
android:id="@+id/action_logout"
android:orderInCategory="100"
android:title="Logout"
app:showAsAction="never"/>
<item
android:id="@+id/action_search"
android:orderInCategory="100"
android:title="Search"
app:showAsAction="always"/>
</menu>

MainActivity.java
package com.example.home.menubar;
import android.os.Bundle;

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
Toast.makeText(getBaseContext(), "Settings selected",
Toast.LENGTH_LONG).show();
} else if (id == R.id.action_search) {
Toast.makeText(getBaseContext(), "Search selected",
Toast.LENGTH_LONG).show();
} else if (id == R.id.action_logout) {
Toast.makeText(getBaseContext(), "Logout selected",
Toast.LENGTH_LONG).show();
} else if (id == R.id.action_settings1) {
Toast.makeText(getBaseContext(), "Settings 1 selected",
Toast.LENGTH_LONG).show();
} else if (id == R.id.action_settings2) {
Toast.makeText(getBaseContext(), "Settings 2 selected",
Toast.LENGTH_LONG).show();
}
return super.onOptionsItemSelected(item);
}
}

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Output

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Practical-8

Aim: Develop simple android app to simulate the Linear Layout and
Relative Layout

Menu_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.example.jonit.lab4.MainActivity">

<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">

<ImageView
android:layout_width="match_parent"
android:layout_height="50dp"
app:srcCompat="@drawable/fb"
android:id="@+id/i" />

<TextView
android:text="Faebook"
android:layout_width="match_parent" android:paddingTop="5dp"

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

android:layout_height="wrap_content" android:gravity="center"
android:id="@+id/textView2"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
</LinearLayout>
</RelativeLayout>

Output

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Practical-9

Aim: Develop simple android app to simulate the Scroll View Layout,
The Table Layout and The Frame Layout

Menu_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: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.example.lab5.MainActivity$PlaceholderFragment" >

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

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

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

<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:src="@drawable/ic_launcher" />

<TableLayout
android:layout_width="match_parent"
android:layout_gravity="center"
android:layout_height="wrap_content" >

<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="1dp"

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

android:text="Apple"

android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>

<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="1dp"
android:text="Alphabet"

android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>

<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="1dp"
android:text="Amazon"

android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>

<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="1dp"
android:text="Microsoft"

android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
</TableLayout>
</FrameLayout>
</LinearLayout>
</ScrollView>

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

</RelativeLayout>
Output

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Practical 10
Aim : Orientation in Android
 Introduction
 The screen orientation attribute is provided by the activity element in the Android Manifest.Xml
file. The orientations provided by the activity are Portrait, Landscape, Sensor, Unspecified and so
on. To perform a screen orientation activity you define the properties in the Android Manifest.Xml
file.
 Types of Orientation
o Unspecified : It is the default value. In such case, system chooses the
orientation.
o Portrait : In a portrait mode the screen will be taller not wider.
o Landscape : In a landscape mode the screen will be wider not taller.
o Sensor : Orientation is determined by the device orientation sensor.
 Example
 In this example, we will create two activities of different screen orientation. The first
activity (MainActivity) will be as "portrait" orientation and second activity
(SecondActivity) as "landscape" orientation type.

activity_main.xml

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


<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.javatpoint.com.screenorientation.MainActivity">

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="112dp"
android:onClick="onClick"
android:text="Launch next activity"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.612"

150110107064 AMIN
SUBJECT : MCWC SUBJECT CODE : 2170710

app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText1"
app:layout_constraintVertical_bias="0.613" />

<TextView
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="124dp"
android:ems="10"
android:textSize="22dp"
android:text="This activity is portrait orientation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

MainActivity.java

package example.javatpoint.com.screenorientation;

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

public class MainActivity extends AppCompatActivity {

Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

button1=(Button)findViewById(R.id.button1);
}
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,SecondActivity.class);
startActivity(intent);
}
}

150110107064 AMIN
SUBJECT : MCWC SUBJECT CODE : 2170710

activity_Second.xml

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


<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.javatpoint.com.screenorientation.SecondActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="180dp"
android:text="this is landscape orientation"
android:textSize="22dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

SecondActivity.java

package example.javatpoint.com.screenorientation;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SecondActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);

}}

150110107064 AMIN
SUBJECT : MCWC SUBJECT CODE : 2170710

AndroidManifest.xml

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.javatpoint.com.screenorientation">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="example.javatpoint.com.screenorientation.MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
<activity android:name=".SecondActivity"
android:screenOrientation="landscape">
</activity>
</application>

</manifest>

Output

150110107064 AMIN
SUBJECT : MCWC SUBJECT CODE : 2170710

Practical: 11
Aim: Create a Custom Button Toast & Create Custom Toast.
CODE
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.p10.MainActivity"
tools:ignore="MergeRootFrame" >

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/t" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/b" />

</LinearLayout>
MainActivity.java
package com.example.p10;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity implements OnClickListener {
Button btn1, btn2;
Toast toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = (Button) findViewById(R.id.button1);
btn2 = (Button) findViewById(R.id.button2);
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (R.id.button1 == v.getId()) {

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Toast toast = Toast.makeText(MainActivity.this,


"Button 1 is clicked", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 100, 100);
toast.show();
} else {
Toast toast = Toast.makeText(MainActivity.this,
"Button 2 is clicked", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 100, 100);
toast.show();
}
OUTPUT

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Practical-12

Aim: Develop simple android app to simulate View, Edit Text View,
Button View, Radio Button, Check Box, Image Button, Rating bar.

Fragment_main.xml

package com.example.jonit.lab3;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RatingBar;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


EditText e1;
Button b1;
RadioGroup rg;
CheckBox c1,c2;
RatingBar rb1;
String str;
ImageButton ib;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rg=(RadioGroup)findViewById(R.id.rg);
e1=(EditText)findViewById(R.id.editText2);
b1=(Button)findViewById(R.id.button);

rb1=(RatingBar)findViewById(R.id.ratingBar2);
c1=(CheckBox)findViewById(R.id.checkBox);
c2=(CheckBox)findViewById(R.id.checkBox2);

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

ib=(ImageButton)findViewById(R.id.imageButton2);

ib.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
System.exit(0);
}
});

b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createString();
if(R.id.rbll== rg.getCheckedRadioButtonId()) {
Toast.makeText(getApplicationContext(), str,
Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(getApplicationContext(), str,
Toast.LENGTH_SHORT).show();
}
}

});

private void createString() {

str= e1.getText().toString();
if(c1.isChecked()){
str=str+" "+c1.getText();
}
if(c2.isChecked()){
str=str+" "+c2.getText();
}
str=str+" Rating:"+rb1.getRating()+"/5";
}
}

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Output

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Practical-14

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.

Graphical Layout

Fragment_main.xml
<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:orientation="vertical"
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.example.menu.MainActivity$PlaceholderFragment" >

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

a<TextView
android:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name" />

<EditText
android:id="@+id/edtUser"
android:layout_width="wrap_content"

150110107064 AMIN
SUBJECT : MCWC SUBJECT CODE : 2170710

android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textEmailAddress" >

<requestFocus />
</EditText>

</LinearLayout>

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

<TextView
android:id="@+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password" />

<EditText
android:id="@+id/edtPass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPassword" >

<requestFocus />
</EditText>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />

</LinearLayout>
</LinearLayout>

fragment_second.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"

150110107064 AMIN
SUBJECT : MCWC SUBJECT CODE : 2170710

android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"

tools:context="com.example.mainactivity.SecondActivity$PlaceholderFragment" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome " />

</RelativeLayout>

MainActivity.java
package com.example.mainactivity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends ActionBarActivity {

Button sub;
EditText eu,ep;
String user,pass;
TextView t1,t2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);

sub=(Button)findViewById(R.id.button1);
eu=(EditText)findViewById(R.id.edtUser);
ep=(EditText)findViewById(R.id.edtPass);
t1=(TextView)findViewById(R.id.t1);
t2=(TextView)findViewById(R.id.t2);

150110107064 AMIN
SUBJECT : MCWC SUBJECT CODE : 2170710

sub.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
user=eu.getText().toString();
pass=ep.getText().toString();

if((user=="[email protected]") && (pass=="abcdefg")){

Intent i=new
Intent(getApplicationContext(),SecondActivity.class);
startActivity(i);
}
else
{
Toast.makeText(getApplicationContext(), "Invalid
User"+user+pass, Toast.LENGTH_LONG).show();

}
}
});
}
}
Output

150110107064 AMIN
SUBJECT : MCWC SUBJECT CODE : 2170710

Practical: -15
Aim: - Develop simple calculator.
.XML
<layout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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.sample.foo.samplecalculator.MainActivity">

<TextView
android:id="@+id/infoTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:textSize="30sp" />

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/infoTextView"
android:enabled="false"
android:gravity="bottom"
android:lines="2"
android:maxLines="2"
android:textSize="20sp" />

<Button
android:id="@+id/buttonSeven"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editText" android:text="7"
android:textSize="20sp" />

<Button
android:id="@+id/buttonEight"

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editText"
android:layout_toRightOf="@id/buttonSeven"
android:text="8"
android:textSize="20sp" />

<Button
android:id="@+id/buttonNine"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editText"
android:layout_toRightOf="@id/buttonEight"
android:text="9"
android:textSize="20sp" />

...

...

<Button
android:id="@+id/buttonDot"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonOne"
android:text="."
android:textSize="20sp" />

<Button
android:id="@+id/buttonZero"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/buttonEight"
android:layout_below="@id/buttonTwo"
android:text="0"
android:textSize="20sp" />

<Button
android:id="@+id/buttonEqual"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

android:layout_height="wrap_content"
android:layout_alignRight="@id/buttonNine"
android:layout_below="@id/buttonThree"
android:text="="
android:textSize="20sp" />

<Button
android:id="@+id/buttonDivide"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/buttonNine"
android:layout_toRightOf="@id/buttonNine"
android:text="/"
android:textSize="20sp" />

<Button
android:id="@+id/buttonMultiply"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/buttonSix"
android:layout_toRightOf="@id/buttonSix"
android:text="*"
android:textSize="20sp" />

<Button
android:id="@+id/buttonSubtract"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/buttonThree"
android:layout_toRightOf="@id/buttonThree"
android:text="-"
android:textSize="20sp" />

<Button
android:id="@+id/buttonAdd"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/buttonEqual"
android:layout_toRightOf="@id/buttonEqual"
android:text="+"
android:textSize="20sp" />

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

<Button
android:id="@+id/buttonClear"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@id/buttonAdd"
android:layout_below="@id/buttonAdd"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:text="C"
android:textSize="20sp" />
</RelativeLayout>
</layout>

.JAVA
private double valueOne = Double.NaN;
private double valueTwo;
private static final char ADDITION = '+';
private static final char SUBTRACTION = '-';
private static final char MULTIPLICATION = '*';
private static final char DIVISION = '/';

private char CURRENT_ACTION;


decimalFormat = new DecimalFormat("#.##########");
binding.buttonZero.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
binding.editText.setText(binding.editText.getText() + "0");
}
});
private void computeCalculation() {
if(!Double.isNaN(valueOne)) {
valueTwo = Double.parseDouble(binding.editText.getText().toString());
binding.editText.setText(null);

if(CURRENT_ACTION == ADDITION)
valueOne = this.valueOne + valueTwo;
else if(CURRENT_ACTION == SUBTRACTION)
valueOne = this.valueOne - valueTwo;
else if(CURRENT_ACTION == MULTIPLICATION)
valueOne = this.valueOne * valueTwo;
else if(CURRENT_ACTION == DIVISION)
valueOne = this.valueOne / valueTwo;
}
else {

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

try {
valueOne = Double.parseDouble(binding.editText.getText().toString());
}
catch (Exception e){}
}
}
binding.buttonAdd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
computeCalculation();
CURRENT_ACTION = ADDITION;
binding.infoTextView.setText(decimalFormat.format(valueOne) + "+");
binding.editText.setText(null);
}
});

binding.buttonSubtract.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
computeCalculation();
CURRENT_ACTION = SUBTRACTION;
binding.infoTextView.setText(decimalFormat.format(valueOne) + "-");
binding.editText.setText(null);
}
});

binding.buttonMultiply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
computeCalculation();
CURRENT_ACTION = MULTIPLICATION;
binding.infoTextView.setText(decimalFormat.format(valueOne) + "*");
binding.editText.setText(null);
}
});

binding.buttonDivide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
computeCalculation();
CURRENT_ACTION = DIVISION;
binding.infoTextView.setText(decimalFormat.format(valueOne) + "/");
binding.editText.setText(null);
}
});

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

binding.buttonEqual.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
computeCalculation();
binding.infoTextView.setText(binding.infoTextView.getText().toString() +
decimalFormat.format(valueTwo) + " = " +
decimalFormat.format(valueOne));
valueOne = Double.NaN;
CURRENT_ACTION = '0';
}
});
Output: -

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Practical – 16
Aim: To Study about ad hoc network and show its working

An ad hoc network is a type of temporary computer-to-computer connection. In ad hoc mode,


you can set up a wireless connection directly to another computer without having to connect
to a Wi-Fi access point or router.

Ad Hoc Wireless Network Features and Uses


 Ad hoc networks are useful when you need to share files or other data directly with
another computer but don't have access to a Wi-Fi network.
 More than one laptop can be connected to the ad hoc network, as long as all of the
adapter cards are configured for ad hoc mode and connect to the same SSID (service
state identifier). The computers need to be within 100 meters of each other.
 If you are the person who sets up the ad hoc network, when you disconnect from the
network, all the other users are also disconnected. An ad hoc network is deleted when
everyone on it disconnects—which can be good or bad, depending on your view; it's
truly a spontaneous network.
 You can use an ad hoc wireless network to share your computer's internet connection
with another computer.

Ad Hoc Wireless Network Limitations

 For file and printer sharing, all users need to be in the same workgroup, or if one com-
puter is joined to a domain, the other users have to have accounts on that computer in
order to access shared items.
 Other limitations of ad hoc wireless networking include the lack of security and a
slow data rate. Ad hoc mode offers minimal security. If an attacker comes
within range of your ad hoc network, he won't have any trouble connecting.

Configuration of Ad Hoc Network.

Step 1: Launch an elevated command prompt under Windows 8 (one with


administrator privileges).

Step 2: Run the following command to verify that your network interface supports
virtualization:
netsh wlan show drivers

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

If Hosted network supported says Yes, you’re all set. Otherwise, you need to upgrade
your hardware, if the software update doesn’t fix it.

Step 3: Now, set up the ad hoc wireless network using this command. Replace the
parts in markup tags with your own choices
netsh wlan set hostednetwork mode=allow ssid=<enter_network_name_here>
key=<enter_password_here>

Step 4: Until now, your hosted network has been created. Now, you need to start it.
Use the command below:
netsh wlan start hostednetwork

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Step 5: You’re all set, with just one thing remaining. If it’s not already enabled, you
need to allow Internet Connection Sharing (ICS) for your currently-active internet
connection. Simply head over to Network & Sharing Center, and in the properties for
the current internet connection, enable ICS. Make sure to select the ad hoc
connection under Home networking connection.

150110107039
SUBJECT : MCWC SUBJECT CODE : 2170710

Now you can connect any device to the internet using the ad hoc wireless network
with internet connection sharing that you just created on your Windows 8 PC

150110107039

You might also like