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

Android

The document is a record of practical work done by students in the Computer Applications department at St. George's College. It contains an index listing 12 programs completed by students, including programs to change text in a TextView on button click, read input from an EditText and display it on button click, and design login and registration screens. For each program, the document provides the aim, program code, and output.

Uploaded by

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

Android

The document is a record of practical work done by students in the Computer Applications department at St. George's College. It contains an index listing 12 programs completed by students, including programs to change text in a TextView on button click, read input from an EditText and display it on button click, and design login and registration screens. For each program, the document provides the aim, program code, and output.

Uploaded by

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

ST.

GEORGE’S COLLEGE
ARUVITHURA

RECORD OF PRACTICAL WORK


DEPARTMENT OF COMPUTER APPLICATIONS

Course/Subject: ………………………………………………
Semester: …………………………………………………….
Certified that this is a bonafide record of practical work done by

Name: ………………………………………………………….
Reg. No.: ………………….…...................................................
Class: …………………… Batch: ……………………..........
Roll No.: ……………..…… Year: …………………………..

Head of the department Lecturer in-Charge

Date……………… Internal Examiner External Examiner


INDEX
Sl. Date PROGRAM Pg. Remarks
No No.
1 Change the text in TextView on click. 2

2 Change text in TextView on clicking two 5


buttons.
3 Read input from EditTextBox and display in text 9
view on button click.
4 Design a login page in nested linear layout. 13

5 Create a screen that has input boxes for User 16


Name,Password, Address, Gender(radio
buttons for male and female), Age (numeric),
Date of Birth (DatePicker), State (Spinner) and
a Submit button. On clicking the submit button,
print all the data below the Submit Button (use
any layout).

6 Design an android application to create a page 26


using intent, one button and one EditText. Pass
the values from one activity to second activity.
7 Design an android app to play audio. 30

8 Design an Android app to convert text to 40


speech.
9 Create a user registration application that 44
stores the user details in a database table.
10 Create sample application with login module 51
(check username and password). On
successful login, change TextView “Login
successful”, on login fail, alert user using Toast
“Login failed”.
11 Develop a program to: a) Send SMS b) 55
Receive SMS.
12 Deploy a map-based application. 58

1
PROGRAM 1

AIM

Change the text in TextView on click (using event handling).

PROGRAM

<?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/txt"

android:layout_width="85dp"

android:layout_height="51dp"

android:text="Hello"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

<Button

android:id="@+id/sub"

2
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.454"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.313" />

</androidx.constraintlayout.widget.ConstraintLayout>

package com.example.clickme;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.*;

import android.view.View;

public class MainActivity extends AppCompatActivity {

TextView txt;

Button sub;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

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

3
txt=findViewById(R.id.txt);

sub.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view){

txt.setText("Text Changed");

});

OUTPUT

Before button click After button click

4
PROGRAM 2

AIM

Change text in TextView on clicking two buttons.

PROGRAM

<?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/txt"

android:layout_width="169dp"

android:layout_height="34dp"

android:text="Hello"

android:textSize="24sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.702"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.139" />

5
<Button

android:id="@+id/sub"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Submit"

android:textSize="20sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.542"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.284" />

<Button

android:id="@+id/upd"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Update"

android:textSize="20sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

6
package com.example.twobutton;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.*;

import android.view.View;

public class MainActivity extends AppCompatActivity {

TextView txt;

Button sub;

Button upd;

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

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

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

txt = findViewById(R.id.txt);

sub.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

txt.setText("android");

});

upd.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

7
txt.setText("Java");

});

OUTPUT

8
PROGRAM 3

AIM

Read input from EditTextBox and display in text view on button click.

PROGRAM

<?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/nam"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:ems="10"

android:inputType="textPersonName"

android:text="Name"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.736"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.291" />

9
<TextView

android:id="@+id/txt"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Enter Text"

android:textSize="20sp"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintHorizontal_bias="0.104"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent"

app:layout_constraintVertical_bias="0.294" />

<Button

android:id="@+id/change"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="change"

android:textSize="20sp"

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.392" />

<TextView

10
android:id="@+id/tx"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="hello"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

package com.example.inputtextdisplay;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.*;

import android.view.*;

public class MainActivity extends AppCompatActivity {

EditText nam;

TextView t;

Button change;

String a;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

nam=(EditText) findViewById(R.id.nam);

t=(TextView)findViewById(R.id.tx) ;

11
change=(Button)findViewById(R.id.change);

change.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

a = (nam.getText().toString());

t.setText(a);

Toast.makeText(getApplicationContext(), "Text is:" +a,Toast.LENGTH_SHORT).show();

});

OUTPUT

12
PROGRAM 4

AIM

Design a login page in nested linear layout.

PROGRAM

<LinearLayout

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

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

<TextView

android:id="@+id/usrnam"

android:layout_width="179dp"

android:layout_height="36dp"

android:text="User name"

android:textSize="24sp" />

/>

<EditText

android:id="@+id/nam"

13
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:ems="10"

android:inputType="textPersonName"

android:text="Name" />

<TextView

android:id="@+id/pswrd"

android:layout_width="139dp"

android:layout_height="wrap_content"

android:layout_below="@+id/usrnam"

android:text="Password"

android:textSize="24sp" />

<EditText

android:id="@+id/psswrd"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/nam"

android:ems="10"

android:inputType="textPersonName"

android:text="password" />

<Button

android:id="@+id/login"

14
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="LOGIN" />

</LinearLayout>

</LinearLayout>

OUTPUT

15
PROGRAM 5

AIM

Create a screen that has input boxes for username, password, address, gender (radio buttons for male
and female), age (numeric), date of birth (DatePicker), state (Spinner) and a submit button. On
clicking the submit button, print all the data below the submit button (use any layout).

PROGRAM

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

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

android:layout_width="match_parent"

android:layout_height="match_parent">

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

android:padding="20dp">

<EditText

android:id="@+id/firstname_edittext"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"

android:hint="firstname"/>

<EditText

android:id="@+id/lastname_edittext"
16
android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"

android:hint="lastname"/>

<EditText

android:id="@+id/email_edittext"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"

android:inputType="textEmailAddress"

android:hint="email"/>

<EditText

android:id="@+id/password_edittext"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"

android:inputType="textPassword"

android:hint="password"/>

<EditText

android:id="@+id/password_again_edittext"

android:layout_width="match_parent"

android:layout_height="wrap_content"

17
android:layout_marginTop="20dp"

android:inputType="textPassword"

android:hint="password_again"/>

<EditText

android:id="@+id/birthday_edittext"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:focusable="false"

android:layout_marginTop="20dp"

android:hint="birthday"/>

<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:layout_marginTop="20dp"

android:gravity="center_vertical">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="gender"/>

<RadioGroup

18
android:id="@+id/gender_radiogroup"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="horizontal">

<RadioButton

android:id="@+id/male"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="male"/>

<RadioButton

android:id="@+id/female"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="female"/>

</RadioGroup>

</LinearLayout>

<Button

android:id="@+id/register_button"

android:layout_width="match_parent"

android:layout_height="wrap_content"

19
android:paddingTop="10dp"

android:paddingBottom="10dp"

android:layout_marginTop="20dp"

android:gravity="center"

android:text="register"/>

<TextView

android:id="@+id/text_display"

android:layout_width="370dp"

android:layout_height="168dp" />

</LinearLayout>

</ScrollView>

package com.example.reglayout;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;

import android.app.DatePickerDialog;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.DatePicker;

import android.widget.EditText;

import android.widget.RadioButton;

import android.widget.RadioGroup;

20
import android.widget.TextView;

import android.widget.Toast;

import android.os.Bundle;

import java.util.Calendar;

public class MainActivity extends AppCompatActivity implements View.OnClickListener

private EditText firstnameEdittext, lastnameEdittext, emailEdittext, passEdittext,


passAgainEdittext, birthdayEdittext;

private RadioGroup genderRadioGroup;

private Button registerButton;

private DatePickerDialog datePickerDialog;

private TextView textView;

@Override

protected void onCreate(Bundle savedInstanceState)

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

//Bind views with their ids

bindViews();

//Set listeners of views

setViewActions();

//Create DatePickerDialog to show a calendar to user to select birthdate

prepareDatePickerDialog();

21
private void bindViews()

firstnameEdittext=(EditText)findViewById(R.id.firstname_edittext);

lastnameEdittext=(EditText)findViewById(R.id.lastname_edittext);

emailEdittext=(EditText)findViewById(R.id.email_edittext);

passEdittext=(EditText)findViewById(R.id.password_edittext);

passAgainEdittext=(EditText)findViewById(R.id.password_again_edittext);

birthdayEdittext=(EditText)findViewById(R.id.birthday_edittext);

genderRadioGroup=(RadioGroup)findViewById(R.id.gender_radiogroup);

registerButton=(Button)findViewById(R.id.register_button);

textView = (TextView)findViewById(R.id.text_display);

private void setViewActions()

birthdayEdittext.setOnClickListener((View.OnClickListener) this);

registerButton.setOnClickListener((View.OnClickListener) this);

private void prepareDatePickerDialog()

//Get current date

Calendar calendar=Calendar.getInstance();

//Create datePickerDialog with initial date which is current and decide what happens when a
date is selected.

datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {

@Override

public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {

22
//When a date is selected, it comes here.

//Change birthdayEdittext's text and dismiss dialog.

birthdayEdittext.setText(dayOfMonth+"/"+monthOfYear+"/"+year);

datePickerDialog.dismiss();

},
calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_M
ONTH));

private void showToastWithFormValues()

//Get edittexts values

String firstname=firstnameEdittext.getText().toString();

String lastname=lastnameEdittext.getText().toString();

String email=emailEdittext.getText().toString();

String pass=passEdittext.getText().toString();

String passAgain=passAgainEdittext.getText().toString();

String birthday=birthdayEdittext.getText().toString();

//Get gender

RadioButton selectedRadioButton =

(RadioButton)findViewById(genderRadioGroup.getCheckedRadioButtonId());

String gender=selectedRadioButton==null ? "":selectedRadioButton.getText().toString();

//Check all fields

if (!firstname.equals("") && !lastname.equals("") && !email.equals("") && !pass.equals("")

&& !passAgain.equals("") && !birthday.equals("") && !gender.equals("")) {

23
//Check if pass and passAgain are the same

if(pass.equals(passAgain)){

String message = "\nFirstname: "+firstname+"\nLastname: "+lastname+"\nEmail:

"+email+"\nDate of Birth: "+birthday+"\nGender: "+gender;

TextView textView = (TextView)findViewById(R.id.text_display);

textView.setText(message);

else

Toast.makeText(this,"passwords_must_be_the_same",Toast.LENGTH_SHORT).show();

else

Toast.makeText(this,"no_field_can_be_empty",Toast.LENGTH_SHORT).show();

@Override

public void onClick(View v) {

switch (v.getId()){

case R.id.birthday_edittext:

datePickerDialog.show();

break;

case R.id.register_button:

showToastWithFormValues();

break;

24
OUTPUT

25
PROGRAM 6

AIM

Design an android application to create page using Intent and one Button , one edittext and pass the
Values from one Activity to second Activity.

PROGRAM

<?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"

tools:context=".MainActivity">

<EditText

android:id="@+id/send_text_id"

android:layout_width="300dp"

android:layout_height="wrap_content"

android:layout_marginLeft="40dp"

android:layout_marginTop="20dp"

android:hint="Input"

android:textSize="25dp"

android:textStyle="bold" />

<Button

android:id="@+id/send_button_id"

android:layout_width="wrap_content"

android:layout_height="40dp"

android:layout_marginLeft="150dp"

26
android:layout_marginTop="150dp"

android:text="send"

android:textStyle="bold" />

</RelativeLayout>

package com.example.intentsactivity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;

import android.os.Bundle;

import android.widget.*;

public class MainActivity extends AppCompatActivity {

EditText send_text;

Button send_button;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

send_button = findViewById(R.id.send_button_id);

send_text = findViewById(R.id.send_text_id);

send_button.setOnClickListener(v ->{

String str= send_text.getText().toString();

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

intent.putExtra("message_key", str);

startActivity(intent);

});

27
}

<?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"

tools:context="org.geeksforgeeks.navedmalik.sendthedata.Second_activity">

<TextView

android:id="@+id/received_value_id"

android:layout_width="300dp"

android:layout_height="50dp"

android:layout_marginLeft="40dp"

android:layout_marginTop="20dp"

android:textSize="40sp"

android:textStyle="bold"

android:layout_marginStart="40dp" />

</RelativeLayout>

package com.example.intentsactivity;

import androidx.appcompat.app.AppCompatActivity;

import android.widget.*;

import android.os.Bundle;

import android.content.Intent;

28
public class second_activity extends AppCompatActivity {

TextView receiver_msg;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_second);

receiver_msg = findViewById(R.id.received_value_id);

Intent intent = getIntent();

String str=intent.getStringExtra("message_key");

receiver_msg.setText(str);

OUTPUT

29
PROGRAM 7

AIM

Design an android app to play audio.

PROGRAM

<?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:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<TextView

android:id="@+id/textview"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:text="Music Player"

android:textSize="35dp" />

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

30
android:id="@+id/imageView"

android:layout_below="@+id/textView"

android:layout_centerHorizontal="true"

/>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/forward"

android:id="@+id/button"

android:layout_alignParentBottom="true"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/pause"

android:id="@+id/button2"

android:layout_alignParentBottom="true"

android:layout_alignLeft="@+id/imageView"

android:layout_alignStart="@+id/imageView" />

<Button

android:layout_width="wrap_content"

31
android:layout_height="wrap_content"

android:text="@string/back"

android:id="@+id/button3"

android:layout_alignTop="@+id/button2"

android:layout_toRightOf="@+id/button2"

android:layout_toEndOf="@+id/button2" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/rewind"

android:id="@+id/button4"

android:layout_alignTop="@+id/button3"

android:layout_toRightOf="@+id/button3"

android:layout_toEndOf="@+id/button3" />

<SeekBar

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/seekBar"

android:layout_alignLeft="@+id/textview"

android:layout_alignStart="@+id/textview"

android:layout_alignRight="@+id/textview"

android:layout_alignEnd="@+id/textview"

android:layout_above="@+id/button" />

32
<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceSmall"

android:text="Small Text"

android:id="@+id/textView2"

android:layout_above="@+id/seekBar"

android:layout_toLeftOf="@+id/textView"

android:layout_toStartOf="@+id/textView" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceSmall"

android:text="Small Text"

android:id="@+id/textView3"

android:layout_above="@+id/seekBar"

android:layout_alignRight="@+id/button4"

android:layout_alignEnd="@+id/button4" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceMedium"

33
android:text="Medium Text"

android:id="@+id/textView4"

android:layout_alignBaseline="@+id/textView2"

android:layout_alignBottom="@+id/textView2"

android:layout_centerHorizontal="true" />

</RelativeLayout>

package com.example.multimedia;

import androidx.appcompat.app.AppCompatActivity;

import android.media.MediaPlayer;

import android.os.Bundle;

import android.os.Handler;

import android.view.View;

import android.widget.Button;

import android.widget.ImageView;

import android.widget.SeekBar;

import android.widget.TextView;

import android.widget.Toast;

import java.util.concurrent.TimeUnit;

public class MainActivity extends AppCompatActivity {

private Button b1,b2,b3,b4;

private ImageView iv;

private MediaPlayer mediaPlayer;

34
private double startTime = 0;

private double finalTime = 0;

private Handler myHandler = new Handler();;

private int forwardTime = 5000;

private int backwardTime = 5000;

private SeekBar seekbar;

private TextView tx1,tx2,tx3;

public static int oneTimeOnly = 0;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

b1 = (Button) findViewById(R.id.button);

b2 = (Button) findViewById(R.id.button2);

b3 = (Button)findViewById(R.id.button3);

b4 = (Button)findViewById(R.id.button4);

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

tx1 = (TextView)findViewById(R.id.textView2);

tx2 = (TextView)findViewById(R.id.textView3);

tx3 = (TextView)findViewById(R.id.textView4);

tx3.setText("song.mp3");

mediaPlayer = MediaPlayer.create(this, R.raw.song);

seekbar = (SeekBar)findViewById(R.id.seekBar);

seekbar.setClickable(false);

b2.setEnabled(false);

35
b3.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(getApplicationContext(), "Playing
sound",Toast.LENGTH_SHORT).show();

mediaPlayer.start();

finalTime = mediaPlayer.getDuration();

startTime = mediaPlayer.getCurrentPosition();

if (oneTimeOnly == 0) {

seekbar.setMax((int) finalTime);

oneTimeOnly = 1;

tx2.setText(String.format("%d min, %d sec",

TimeUnit.MILLISECONDS.toMinutes((long) finalTime),

TimeUnit.MILLISECONDS.toSeconds((long) finalTime) -

TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long)

finalTime)))

);

tx1.setText(String.format("%d min, %d sec",

TimeUnit.MILLISECONDS.toMinutes((long) startTime),

TimeUnit.MILLISECONDS.toSeconds((long) startTime) -

TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long)

startTime)))

);

seekbar.setProgress((int)startTime);

myHandler.postDelayed(UpdateSongTime,100);

36
b2.setEnabled(true);

b3.setEnabled(false);

});

b2.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Toast.makeText(getApplicationContext(), "Pausing
sound",Toast.LENGTH_SHORT).show();

mediaPlayer.pause();

b2.setEnabled(false);

b3.setEnabled(true);

});

b1.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

int temp = (int)startTime;

if((temp+forwardTime)<=finalTime){

startTime = startTime + forwardTime;

mediaPlayer.seekTo((int) startTime);

Toast.makeText(getApplicationContext(),"You have Jumped forward 5


seconds",Toast.LENGTH_SHORT).show();

}else{

Toast.makeText(getApplicationContext(),"Cannot jump forward 5


seconds",Toast.LENGTH_SHORT).show();

37
}

});

b4.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

int temp = (int)startTime;

if((temp-backwardTime)>0){

startTime = startTime - backwardTime;

mediaPlayer.seekTo((int) startTime);

Toast.makeText(getApplicationContext(),"You have Jumped backward 5


seconds",Toast.LENGTH_SHORT).show();

}else{

Toast.makeText(getApplicationContext(),"Cannot jump backward 5


seconds",Toast.LENGTH_SHORT).show();

});

private Runnable UpdateSongTime = new Runnable() {

public void run() {

startTime = mediaPlayer.getCurrentPosition();

tx1.setText(String.format("%d min, %d sec",

TimeUnit.MILLISECONDS.toMinutes((long) startTime),

TimeUnit.MILLISECONDS.toSeconds((long) startTime) -

38
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.

toMinutes((long) startTime)))

);

seekbar.setProgress((int)startTime);

myHandler.postDelayed(this, 100);

};

OUTPUT

39
PROGRAM 8

AIM

Design an Android app to convert text to speech

PROGRAM

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

<LinearLayout 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="wrap_content"

android:orientation="vertical"

android:layout_gravity="center"

tools:context=".Program8">

<EditText

android:id="@+id/editText"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_weight="1"

android:ems="10"

android:layout_marginBottom="30dp"

android:inputType="textPersonName"

android:text="Name" />

40
<Button

android:id="@+id/button"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="Convert to Speech" />

</LinearLayout>

package com.example.androidlabrecord;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.speech.tts.TextToSpeech;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import java.util.Locale;

public class Program8 extends AppCompatActivity {

TextToSpeech tts;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

41
setContentView(R.layout.activity_program8);

EditText editText = findViewById(R.id.editText);

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

button.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String text = editText.getText().toString();

tts=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {

@Override

public void onInit(int i) {

if(i!=TextToSpeech.ERROR){

tts.setLanguage(Locale.US);

tts.speak(text,TextToSpeech.QUEUE_FLUSH,null);

});

});

42
OUTPUT

43
PROGRAM 9

AIM

Create a user registration application that stores the user details in a database table.

PROGRAM

<?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:layout_width="match_parent"

android:layout_height="match_parent"

android:padding="10dp"

tools:context=".MainActivity">

<TextView

android:id="@+id/txttitle"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Enter the Details"

android:textSize="24dp"

android:layout_marginTop="20dp" />

<EditText

android:id="@+id/name"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Name"

android:textSize="24dp"

44
android:layout_below="@+id/txttitle"

android:inputType="textPersonName"/>

<EditText

android:id="@+id/contact"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="contact"

android:textSize="24dp"

android:layout_below="@+id/name"

android:inputType="number"/>

<EditText

android:id="@+id/dobs"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Date of birth"

android:textSize="24dp"

android:layout_below="@+id/contact"

android:inputType="date"/>

<Button

android:id="@+id/inserts"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="INSERT"

android:textSize="24dp"

android:layout_marginTop="30dp"

45
android:layout_below="@+id/dobs"/>

<Button

android:id="@+id/view"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="VIEW"

android:textSize="24dp"

android:layout_marginTop="30dp"

android:layout_below="@+id/inserts"/>

</RelativeLayout>

package com.example.sqlliteapplication;

import androidx.appcompat.app.AlertDialog;

import androidx.appcompat.app.AppCompatActivity;

import android.database.Cursor;

import android.os.Bundle;

import android.view.View;

import android.widget.*;

import java.lang.*;

import java.util.Date;

public class MainActivity extends AppCompatActivity {

EditText name,contact,dobs;

Button insert,view;

@Override

protected void onCreate(Bundle savedInstanceState) {

46
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

name = findViewById(R.id.name);

contact = findViewById(R.id.contact);

dobs = findViewById(R.id.dobs);

insert = findViewById(R.id.inserts);

view = findViewById(R.id.view);

DBHelper DB = new DBHelper(this);

insert.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

String nameTXT = name.getText().toString();

String contactTXT = contact.getText().toString();

String dobTXT = dobs.getText().toString();

Boolean checkinsertdata;

checkinsertdata = DB.insertData(nameTXT,contactTXT, dobTXT);

if (checkinsertdata){

Toast.makeText(MainActivity.this, "New Data inserted",


Toast.LENGTH_SHORT).show();

else{

Toast.makeText(MainActivity.this, "Not Inserted ", Toast.LENGTH_SHORT).show();

});

view.setOnClickListener(new View.OnClickListener() {

47
@Override

public void onClick(View view) {

Cursor res;

res = DB.getData();

if(res.getCount()==0){

Toast.makeText(MainActivity.this, "No Entry", Toast.LENGTH_SHORT).show();

return;

else{

StringBuffer buffer = new StringBuffer();

while(res.moveToNext()){

StringBuffer append;

buffer.append("Name: ".concat(res.getString(0))+"\n");

buffer.append("Contact: ".concat(res.getString(1)+"\n"));

buffer.append("DOB :".concat(res.getString(2)+"\n\n"));

AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

builder.setCancelable(true);

builder.setTitle("User Entries");

builder.setMessage(buffer.toString());

builder.show();

});

48
}

package com.example.sqlliteapplication;

import android.content.ContentValues;

import android.content.Context;

import android.database.Cursor;

import android.database.sqlite.SQLiteDatabase;

import android.database.sqlite.SQLiteOpenHelper;

import java.util.Date;

public class DBHelper extends SQLiteOpenHelper {

public DBHelper(Context context) {

super(context, "Userdata.db", null, 1);

@Override

public void onCreate(SQLiteDatabase DB) {

DB.execSQL("create Table Userdetails(name VARCHAR ,contact VARCHAR , dob date)");

@Override

public void onUpgrade(SQLiteDatabase DB, int i, int i1) {

DB.execSQL("drop table if exists Userdetails");

public Boolean insertData(String name, String contact, String dob){

SQLiteDatabase DB = this.getWritableDatabase();

ContentValues contentValues = new ContentValues();

contentValues.put("name", name);

contentValues.put("contact", contact);

49
contentValues.put("dob", String.valueOf(dob));

long results= DB.insert("Userdetails", null, contentValues);

if(results == -1)

return false;

else

return true;

public Cursor getData(){

SQLiteDatabase DB = this.getWritableDatabase();

Cursor cursor = DB.rawQuery("select * from Userdetails", null);

return cursor;

OUTPUT

50
PROGRAM 10

AIM

Create sample application with login module (check username and password). On successful login,
change TextView “Login successful”, on login fail, alert user using Toast “Login failed”..

PROGRAM

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

<LinearLayout 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="wrap_content"

android:layout_gravity="center"

android:orientation="vertical"

tools:context=".Program9">

<EditText

android:id="@+id/usernameEditText"

android:layout_width="match_parent"

android:layout_height="60dp"

android:ems="10"

android:inputType="textPersonName"

android:hint="Username" />

<EditText

android:id="@+id/passwordEditText"

51
android:layout_width="match_parent"

android:layout_height="60dp"

android:ems="10"

android:inputType="textPassword"

android:hint="Password" />

<Button

android:id="@+id/loginButton"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Login" />

<TextView

android:id="@+id/statusTextView"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textSize="25sp"

android:text="Status" />

</LinearLayout>

package com.example.androidlabrecord;

import androidx.appcompat.app.AppCompatActivity;

52
import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Toast;

public class Program9 extends AppCompatActivity {

String myUsername="labrecord";

String myPass="labrecord";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_program9);

EditText usernameEditText = findViewById(R.id.usernameEditText);

EditText passwordEditText = findViewById(R.id.passwordEditText);

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

TextView statusTextView = findViewById(R.id.statusTextView);

loginButton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String username = usernameEditText.getText().toString();

String password = passwordEditText.getText().toString();

53
if (username.equals(myUsername) && password.equals(myPass)) {

statusTextView.setText("Login successful");

} else {

Toast.makeText(getApplicationContext(), "Login failed",


Toast.LENGTH_SHORT).show();

});

OUTPUT

54
PROGRAM 11

AIM

Develop a program to: a) Send SMS b) Receive SMS.

PROGRAM

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

<LinearLayout 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"

android:orientation="vertical"

android:layout_gravity="center"

tools:context=".program11">

<EditText

android:id="@+id/ph"

android:layout_width="match_parent"

android:layout_height="60dp"

android:ems="10"

android:inputType="textPersonName"

android:hint="Enter Phone Number" />

<EditText

android:id="@+id/msg"

android:layout_width="match_parent"

55
android:layout_height="60dp"

android:ems="10"

android:inputType="textPersonName"

android:hint="Enter message" />

<Button

android:id="@+id/button"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Send Message" />

</LinearLayout>

package com.example.androidlabrecord;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.telephony.SmsManager;

import android.widget.EditText;

public class program11 extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_program11);

56
EditText ph=findViewById(R.id.ph);

EditText msg=findViewById(R.id.msg);

String phoneNumber = ph.getText().toString();

String message = msg.getText().toString();

SmsManager smsManager = SmsManager.getDefault();

smsManager.sendTextMessage(phoneNumber, null, message, null, null);

OUTPUT

57
PROGRAM 12

AIM

Deploy a map-based application.


PROGRAM

<?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=".Program12">

<fragment

android:id="@+id/map"

android:name="com.google.android.gms.maps.SupportMapFragment"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

package com.example.androidlabrecord;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.google.android.gms.maps.GoogleMap;
58
import com.google.android.gms.maps.OnMapReadyCallback;

import com.google.android.gms.maps.SupportMapFragment;

public class Program12 extends AppCompatActivity {

private GoogleMap mMap;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_program12);

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()

.findFragmentById(R.id.map);

mapFragment.getMapAsync(new OnMapReadyCallback() {

@Override

public void onMapReady(GoogleMap googleMap) {

mMap = googleMap;

});

59
OUTPUT

60

You might also like