0% found this document useful (0 votes)
10 views

Android Lab Manual

The document contains 10 experiments related to developing Android applications. The experiments include developing applications using GUI components, layout managers, database, GPS location, notifications, threading and intents.

Uploaded by

Shivangi Rawat
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Android Lab Manual

The document contains 10 experiments related to developing Android applications. The experiments include developing applications using GUI components, layout managers, database, GPS location, notifications, threading and intents.

Uploaded by

Shivangi Rawat
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

INDEX

S. DATE EXPERIMENTS SIGN REMARKS


NO.

1 Develop an application that uses GUI


components, Font and Colors

2 Develop an application that uses Layout


Managers and event listeners.

3 Develop a native calculator application.

4 Write an application that draws basic graphical


primitives on the screen.

5 Develop an application that makes use of


database.

6 Implement an application that creates an alert


upon receiving a message.

7 Implement an application that Implements Multi-


threading

8 Develop a native application that uses GPS


location information.

9 Create an mobile application that create alarm


clock.

10 Create an application that make use of Explicite


and Implicite intent.
Ex.No:1 Develop an application that uses GUI components, Font and Colours
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">

<EditText
android:id="@+id/myText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="Enter Your Text Here"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.432"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.102" />
<Button
android:id="@+id/incBtn"
android:layout_width="138dp"
android:layout_height="51dp"
android:text="INC"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.185"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.329" />
<Button
android:id="@+id/decBtn"
android:layout_width="126dp"
android:layout_height="52dp"
android:text="DEC"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.777"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.329" />
<Button
android:id="@+id/colorBtn"
android:layout_width="275dp"
android:layout_height="55dp"
android:text="Fill Colour"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.426"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
OUTPUT:

Ex.No:2 Develop an application that uses Layout Managers and event


listeners.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="163dp"
android:layout_height="48dp"
android:text="Bill"
android:textSize="35dp"
android:textStyle="bold"
android:textColor="#3d4de5"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.062" />

<CheckBox
android:id="@+id/checkBoxTea"
android:layout_width="263dp"
android:layout_height="67dp"
android:text="Tea"
android:textSize="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.228" />

<CheckBox
android:id="@+id/checkBoxCoffee"
android:layout_width="265dp"
android:layout_height="66dp"
android:text="Coffee"
android:textSize="25dp"
app:layout_constraintBottom_toBottomOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.506"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.337" />

<CheckBox
android:id="@+id/checkBoxBurger"
android:layout_width="265dp"
android:layout_height="62dp"
android:text="Burger"
android:textSize="25dp"
app:layout_constraintBottom_toBottomOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.513"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.434" />

<Button
android:id="@+id/button"
android:layout_width="169dp"
android:layout_height="65dp"
android:text="submit"
android:textSize="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.512"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.975" />

<TextView
android:id="@+id/billView"
android:layout_width="403dp"
android:layout_height="203dp"
android:text="TextView"
android:textSize="20dp"
android:padding="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.748" />
</androidx.constraintlayout.widget.ConstraintLayout>
Main_Activity.java
package com.example.billgenerator;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


TextView bill;
Button button;
CheckBox checkBoxTea,checkBoxCoffee,checkBoxBurger;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenOnButton();
}
public void addListenOnButton(){
bill = (TextView) findViewById(R.id.billView);
button = (Button) findViewById(R.id.button);
checkBoxTea =(CheckBox) findViewById(R.id.checkBoxTea);
checkBoxCoffee =(CheckBox) findViewById(R.id.checkBoxCoffee);
checkBoxBurger =(CheckBox) findViewById(R.id.checkBoxBurger);

button.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
int totalamount=0;
StringBuilder result = new StringBuilder();
result.append("Selected Items:");
if(checkBoxTea.isChecked()){
result.append("\nTea 20Rs");
totalamount+=20;
}
if(checkBoxCoffee.isChecked()){
result.append("\nCoffee 50Rs");
totalamount+=50;
}
if(checkBoxBurger.isChecked()){
result.append("\nBurger 120Rs");
totalamount+=120;
}
result.append("\nTotal: " +totalamount+"Rs");
bill.setText(result);
Toast.makeText(getApplicationContext(),result.toString(),
Toast.LENGTH_LONG).show();
}
});
}
}
Output:
Ex.No:3 Develop a native calculator application
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="195dp"
android:layout_height="42dp"
android:text="Calculator"
android:textAlignment="center"
android:textColor="#3F51B5"
android:textSize="35dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.042" />

<EditText
android:id="@+id/num1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter number"
android:inputType="number"
android:paddingLeft="5dp"
android:textSize="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.183" />

<EditText
android:id="@+id/num2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter number"
android:inputType="number"
android:paddingLeft="5dp"
android:textSize="25dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.33" />

<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="50dp"
android:paddingRight="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.609">

<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/add"
android:text="Add"
android:textSize="20dp" />

<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/sub"
android:text="Subtract"
android:textSize="20dp" />

<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/mul"
android:text="Multiply"
android:textSize="20dp" />

<RadioButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/div"
android:text="Divide"
android:textSize="20dp" />
</RadioGroup>
<EditText
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:textSize="25dp"
android:hint="Result"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.809" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:textSize="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.957" />
</androidx.constraintlayout.widget.ConstraintLayout>

mainActivity.java
package com.example.calcusingradio;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity {


private EditText num1,num2,result;
private RadioButton add,sub,mul,div;
private Button submit;
public int r=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton(){
num1 = (EditText) findViewById(R.id.num1);
num2 = (EditText) findViewById(R.id.num2);
add = (RadioButton) findViewById(R.id.add);
sub = (RadioButton) findViewById(R.id.sub);
mul = (RadioButton) findViewById(R.id.mul);
div = (RadioButton) findViewById(R.id.div);
result = (EditText) findViewById(R.id.result);
submit = (Button) findViewById(R.id.button);
submit.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
String value1 = num1.getText().toString();
String value2 = num2.getText().toString();
int a = Integer.parseInt(value1);
int b = Integer.parseInt(value2);

String operation = "";


if(add.isChecked()){
operation = "add";
}
if(sub.isChecked()){
operation = "sub";
}
if(mul.isChecked()){
operation = "mul";
}
if(div.isChecked()){
operation = "div";
}
switch(operation){
case "add":
r = a+b;
break;
case "sub":
r = a-b;
break;
case "mul":
r = a*b;
break;
case "div":
r = a/b;
break;
}
result.setText(String.valueOf(r));
}
});
}
}

Output
Ex.No:4 Write an application that draw the basic graphical primitives on the
screen.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity">

<ImageView
android:id="@+id/graphic"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Main_Activity.java
package com.example.exp_4;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {

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

Bitmap bg = Bitmap.createBitmap(720,1280,Bitmap.Config.ARGB_8888);
ImageView i = (ImageView) findViewById(R.id.graphic);
i.setBackgroundDrawable(new BitmapDrawable(bg));
Canvas canvas = new Canvas(bg);
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setTextSize(50);
canvas.drawText("Rectangle",420,150,paint);
canvas.drawRect(400,200,650,700,paint);
canvas.drawText("Circle",120,150,paint);
canvas.drawCircle(200, 350, 150, paint);
//To draw a Square
canvas.drawText("Square", 120, 800, paint);
canvas.drawRect(50, 850, 350, 1150, paint);
//To draw a Line
canvas.drawText("Line", 480, 800, paint);
canvas.drawLine(520, 850, 520, 1150, paint);
}
}
Output:

Ex.No:5 Write an application that make use of database.

Ex.No:10 Write an application that make use of Explicite and Implicite intent.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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=".MainActivity”>
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Activity1"
android:textAlignment="center"
android:textColor="#3F51B5"
android:textSize="35sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.089" />
<Button
android:id="@+id/activity1_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:paddingTop="20dp"
android:paddingRight="30dp"
android:paddingBottom="20dp"
android:text="Activity2"
android:textColor="@color/white"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.245"/>
<EditText
android:id="@+id/open_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter Url"
android:inputType="text"
android:padding="20dp"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="174dp"
android:layout_height="67dp"
android:text="Open Url"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.674" />
</androidx.constraintlayout.widget.ConstraintLayout>
Main_Activity.java
package com.example.toggledemo;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


private Button act2_btn,btn;
private EditText url_field;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

url_field = (EditText) findViewById(R.id.open_url);


btn = (Button) findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url = url_field.getText().toString();

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));


startActivity(intent);
}
});
act2_btn =(Button) findViewById(R.id.activity1_btn);
act2_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), intentDemo.class);
startActivity(intent);
}
});
}
}

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

<androidx.constraintlayout.widget.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=".intentDemo">

<TextView

android:id="@+id/textView"

android:layout_width="210dp"

android:layout_height="59dp"

android:text="Activity2"

android:textSize="35sp"

android:textStyle="bold"

android:textAlignment="center"

android:textColor="#3F51B5"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.447"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.041" />

<Button

android:id="@+id/activity2_btn"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/register_button"

android:paddingLeft="30dp"

android:paddingTop="20dp"

android:paddingRight="30dp"
android:paddingBottom="20dp"

android:text="Activity1"

android:textColor="@color/white"

android:textSize="20sp"

android:textStyle="bold"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.498"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.545"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Second_Activity.java

package com.example.toggledemo;

import androidx.appcompat.app.AppCompatActivity;

import androidx.appcompat.widget.AppCompatButton;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

public class intentDemo extends AppCompatActivity {

Button act1_btn;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_intent_demo);

act1_btn =(Button) findViewById(R.id.activity2_btn);

act1_btn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

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

startActivity(intent);

});

You might also like