0% found this document useful (0 votes)
14 views40 pages

SUMMER 2023 PROGRAMS

The document outlines various Android application programs including a GridView demonstration, TextToSpeech conversion, Time and Date picker, and a current location display for a user's car. It also describes an employee registration form, a student feedback form with database connectivity, and geocoding functionalities. Additionally, it includes a program for listing paired Bluetooth devices, showcasing XML and Java code for each application.

Uploaded by

pranjaliingawa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views40 pages

SUMMER 2023 PROGRAMS

The document outlines various Android application programs including a GridView demonstration, TextToSpeech conversion, Time and Date picker, and a current location display for a user's car. It also describes an employee registration form, a student feedback form with database connectivity, and geocoding functionalities. Additionally, it includes a program for listing paired Bluetooth devices, showcasing XML and Java code for each application.

Uploaded by

pranjaliingawa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 40

SUMMER 2023 PROGRAMS

Q3.b) Program to demonstrate GridView.


XML CODE:

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


<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"
tools:context=".MainActivity"
android:orientation="vertical">

<GridView
android:id="@+id/gridview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="20dp"
android:horizontalSpacing="10dp"
android:layout_gravity="center"/>

</LinearLayout>

JAVA CODE:

package com.example.pranu1;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


GridView gd;
String[]arr = {"Item 1", "Item 2", "Item 3", "Item 4","Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10"};

@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gd = findViewById(R.id.gridview);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, arr);
gd.setAdapter(adapter);
gd.setOnItemClickListener((parent, view, position, id) -> {
String msg = arr[position]+" is selected";
Toast.makeText(MainActivity.this,msg,Toast.LENGTH_LONG).show();
});
}
}
c) TextToSpeech conversion program.
XML CODE:-

<?xml version="1.0" encoding="utf-8"?> android:layout_gravity="center_horizontal"


<LinearLayout android:paddingTop="100dp"
xmlns:android="http://schemas.android.com/apk/res/ android:textSize="20dp"
android" android:hint="Enter Text you want to Read out
xmlns:tools="http://schemas.android.com/tools" loud"/>
android:layout_width="match_parent"
android:layout_height="match_parent" <Button
tools:context=".MainActivity" android:layout_width="wrap_content"
android:orientation="vertical"> android:layout_height="wrap_content"
android:id="@+id/BT"
<EditText android:text="Submit"
android:layout_width="wrap_content" android:layout_gravity="center_horizontal"/>
android:layout_height="wrap_content" </LinearLayout>
android:id="@+id/ET"

JAVA CODE:-

package com.example.pranu1;
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 MainActivity extends AppCompatActivity {


EditText et;
Button btn;
TextToSpeech tt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et = findViewById(R.id.ET);
btn = findViewById(R.id.BT);

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


@Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR){
tt.setLanguage(Locale.UK);
}
}
});

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tt.speak(et.getText().toString(),TextToSpeech.QUEUE_FLUSH,null);
}
});
}
}
Q4.b) Time picker and Date picker Program.
XML CODE:-
<?xml version="1.0" encoding="utf-8"?> android:layout_height="wrap_content"
<LinearLayout android:layout_gravity="center_horizontal"
xmlns:android="http://schemas.android.com/apk/res/ android:text="Set Date" />
android"
xmlns:tools="http://schemas.android.com/tools" <TimePicker
android:layout_width="match_parent" android:id="@+id/timepcker"
android:layout_height="match_parent" android:layout_width="match_parent"
tools:context=".MainActivity" android:layout_height="wrap_content"
android:orientation="vertical"> android:timePickerMode="spinner"/>

<DatePicker <TextView
android:id="@+id/dtpcker" android:id="@+id/tvTime"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:datePickerMode="spinner"/> android:layout_gravity="center_horizontal"
android:textSize="20dp"
<TextView android:textStyle="bold" />
android:id="@+id/tvDate"
android:layout_width="wrap_content" <Button
android:layout_height="wrap_content" android:id="@+id/btnTime"
android:layout_gravity="center_horizontal" android:layout_width="wrap_content"
android:textSize="20dp" android:layout_height="wrap_content"
android:textStyle="bold" /> android:layout_gravity="center_horizontal"
android:text="Set Time"/>
<Button
android:id="@+id/btnDate" </LinearLayout>
android:layout_width="wrap_content"

JAVA CODE:

package com.example.pranu1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
public class MainActivity extends AppCompatActivity {
TextView tvDate, tvTime;
DatePicker dtpcker;
TimePicker timepcker;
Button b1, b2;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvDate = findViewById(R.id.tvDate);
tvTime = findViewById(R.id.tvTime);
b1 = findViewById(R.id.btnDate);
b2 = findViewById(R.id.btnTime);
dtpcker = findViewById(R.id.dtpcker);
timepcker = findViewById(R.id.timepcker);

b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvDate.setText("Date: "+dtpcker.getDayOfMonth()+"/"+dtpcker.getMonth()+"/"+dtpcker.getYear());
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tvTime.setText(timepcker.getHour()+":"+timepcker.getMinute());
}
});
}
}

Q4.e) Develop an android application to show current location of an user's


car.
activity_maps.xml
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.com.mapexample.MapsActivity" />

AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
Q5.a) Design an employee registration form using UI component.
XML CODE:-

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


<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"
tools:context=".MainActivity"
android:orientation="vertical">

<TextView <EditText
android:layout_width="wrap_content" android:layout_width="268dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/T1" android:id="@+id/Et4"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:text="Employee Regestration Form" android:paddingTop="20dp"
android:textSize="24dp" android:hint="Enter you Address"/>
android:textStyle="bold"
android:paddingTop="40dp" <EditText
android:paddingBottom="40dp"/> android:layout_width="268dp"
android:layout_height="wrap_content"
<EditText android:id="@+id/Et5"
android:id="@+id/Et1" android:layout_gravity="center_horizontal"
android:layout_width="268dp" android:paddingTop="20dp"
android:layout_height="wrap_content" android:hint="Enter you pin code"
android:layout_gravity="center_horizontal" android:paddingBottom="20dp"/>
android:hint="Enter your Id " />
<Button
<EditText android:layout_width="wrap_content"
android:layout_width="268dp" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:id="@+id/Btn"
android:id="@+id/Et2" android:layout_gravity="center_horizontal"
android:layout_gravity="center_horizontal" android:text="Submit"/>
android:paddingTop="20dp"
android:hint="Enter your name"/> </LinearLayout>

<EditText
android:layout_width="268dp"
android:layout_height="wrap_content"
android:id="@+id/Et3"
android:layout_gravity="center_horizontal"
android:paddingTop="20dp"
android:hint="Enter your mobile no."/>
Q5.b) Develop an android application for taking student feedback with
database connectivity.
XML CODE:-

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


<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"
tools:context=".MainActivity"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="STUDENT FEEDBACK FORM"
android:textAlignment="center"
android:textSize="24dp"
android:textStyle="bold"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:id="@+id/et1"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Roll no"
android:id="@+id/et2"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Class"
android:id="@+id/et3"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your Feedback"
android:id="@+id/et4"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:id="@+id/btn"
android:text="Submit"/>

</LinearLayout>
JAVA CODE:-
package com.example.pranu1;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.database.sqlite.SQLiteDatabase;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


SQLiteDatabase dbobj;
Button btn;
EditText name, roll, clas, feed;
String sname, sroll, sclass, sfeed, query;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = findViewById(R.id.btn);
name = findViewById(R.id.et1);
roll = findViewById(R.id.et2);
clas = findViewById(R.id.et3);
feed = findViewById(R.id.et4);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dbobj = openOrCreateDatabase("FEEDBACK DATABASE",
Context.MODE_PRIVATE,null);
dbobj.execSQL("Create Table if not exists Student(id integer PRIMARY KEY
AUTOINCREMENT, Name varchar, Rollno varchar, Class varchar, Feedback varchar);");
sname = name.getText().toString();
sroll = roll.getText().toString();
sclass = clas.getText().toString();
sfeed = feed.getText().toString();
query = "INSERT INTO Student(Name, Rollno, class,Feedback) VALUES
('''+sname+''', '''+sroll+''', '''+sclas+''', '''+sfeed+''',)";
Toast.makeText(getApplicationContext(),"Feedback submitted Successfully",
Toast.LENGTH_LONG).show();
}
});
}
}

Q5.c) Geocoding and Reverse Geocoding.


Activity_maps.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.com.mapexample.MapsActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<EditText
android:layout_width="248dp"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:hint="Search Location" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="searchLocation"
android:text="Search" />

</LinearLayout>

</fragment>

AndroidManifest.xml

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


<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
Q6.a) Design an android application to show the list of paired devices by
Bluetooth.
XML CODE:-

<LinearLayout android:layout_width="wrap_content"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="match_parent" android:id="@+id/tv"
tools:context=".MainActivity" android:text="Paired devices"
android:orientation="vertical"> android:layout_gravity="center_horizontal"
android:textSize="25dp"
<Button android:textStyle="bold"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content" <ListView
android:layout_gravity="center_horizontal" android:layout_width="wrap_content"
android:id="@+id/btn" android:layout_height="wrap_content"
android:text="List all paired Devices" android:id="@+id/Lv"/>
android:onClick="list"/>
</LinearLayout>
<TextView

JAVA CODE:-
package com.example.pranu1;
import androidx.appcompat.app.AppCompatActivity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Set;

public class MainActivity extends AppCompatActivity {

Button btn;
ListView lv;
BluetoothAdapter ba;
Set<BluetoothDevice> pairedDevice;
ArrayList<String> list = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = findViewById(R.id.Lv);
btn = findViewById(R.id.btn);
ba = BluetoothAdapter.getDefaultAdapter();
}
public void list(){
pairedDevice = ba.getBondedDevices();
for(BluetoothDevice bt: pairedDevice)list.add(bt.getName());
Toast.makeText(getApplicationContext(),"Showing Paired Devices",Toast.LENGTH_LONG).show();
ArrayAdapter<String>ad = new ArrayAdapter(this, android.R.layout.simple_list_item_1,list);
lv.setAdapter(ad);
}
}
Q6.b) Sending SMS
Manifest file permissions:

<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
<uses-permission android:name="android.permission.SEND_SMS"/>

XML FILE:-

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


<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"
tools:context=".MainActivity"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To,"
android:textSize="24dp"/>

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter Recievers Number"
android:textSize="24dp"
android:id="@+id/et1"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter the Message below"
android:textSize="24dp"/>

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter message here"
android:textSize="24dp"
android:id="@+id/et2"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn"
android:text="SEND"
android:layout_gravity="center_horizontal"/>

</LinearLayout>
JAVA CODE:-

package com.example.pranu1;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


private EditText etno;
private EditText etmsg;
private Button btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etno = findViewById(R.id.et1);
etmsg = findViewById(R.id.et2);
btn = findViewById(R.id.btn);
if(ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.SEND_SMS)!
=PackageManaer.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(MainActivity.this,new String[]{Manifest.permission.SEND_SMS},100);
}

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
SmsManager smsgr = SmsManager.getDefault();
smsgr.sendTextMessage(etno.getText().toString(), null, etmsg.getText().toString(), null, null);
Toast.makeText(MainActivity.this, "SMS sent successfully", Toast.LENGTH_LONG).show();
}catch(Exception e){
Toast.makeText(MainActivity.this,"SMS failed, try again later", Toast.LENGTH_LONG).show();
}
}
});
}
}
SUMMER 2022 PROGRAMS
Q2.d) Describe with example, how to create a simple database in SQLite
(Assume suitable data).
(Already present in S23 Q5.b, here u can use only 1 button to show how to create
database).

Q4.a) Absolute Layout. (UI )


XML CODE:-

<AbsoluteLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<TextView
android:layout_x="80dp"
android:layout_y="80dp"
android:text="User Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_x="80dp"
android:layout_y="100dp"
android:width="100px" />

<TextView
android:layout_x="80dp"
android:layout_y="180dp"
android:text="Password"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_x="80dp"
android:layout_y="200dp"
android:width="100px" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="150dp"
android:layout_y="300dp"
android:text="Log In" />

</AbsoluteLayout>
Q4.b) Date and Time Picker.
(Already did in S23 Q4.b)

Q4.e) SMS message SEND.


(Already did in S23 Q6.b)

Q5.a) Write a program to convert temperature from Celsius to Fahrenheit


and vice versa using Toggle button. (Design UI as per your choice. Write
XML and java file).
XML CODE:-

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:orientation="vertical">

<EditText
android:id="@+id/et1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter the temperature"
android:inputType="numberDecimal"/>

<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tb"
android:textOff="F to C"
android:textOn="C to F" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toogle button"
android:id="@+id/bt"/>

</LinearLayout>
JAVA CODE:-

package com.example.pranu1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.ToggleButton;

public class MainActivity extends AppCompatActivity {


ToggleButton tb;
EditText temp;
Button btn;
double a, b;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tb = findViewById(R.id.tb);
temp = findViewById(R.id.et1);
btn = findViewById(R.id.bt);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a = Double.parseDouble(String.valueOf(temp.getText()));
if(tb.isChecked()){
b = a*9/5+32;
String r = String.valueOf(b);
Toast.makeText(MainActivity.this,r+" F",Toast.LENGTH_LONG).show();
}else{
b = a - 32;
b = b*5/9;
String r = String.valueOf(b);
Toast.makeText(MainActivity.this,r+" C",Toast.LENGTH_LONG).show();
}
}
});
}
}
Q5.b) Write a program to capture an image using camera and display it.
XML CODE:-

<LinearLayout android:layout_height="500dp"
xmlns:android="http://schemas.android.com/apk/res/ android:id="@+id/iv"/>
android"
android:layout_width="match_parent" <Button
android:layout_height="match_parent" android:layout_width="wrap_content"
xmlns:tools="http://schemas.android.com/tools" android:layout_height="wrap_content"
tools:context=".MainActivity" android:text="Take Photo"
android:orientation="vertical"> android:id="@+id/btn"
android:layout_gravity="center_horizontal"/>
<ImageView
android:layout_width="match_parent" </LinearLayout>

JAVA CODE:-

package com.example.pranu1;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

Button btn;
ImageView iv;
private static final int cr = 123;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = findViewById(R.id.iv);
btn = findViewById(R.id.btn);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i,cr);
}
});
}

public void onActivityResult(int reqC, int resC, Intent data){


super.onActivityResult(reqC, resC, data);
if(resC == cr){
Bitmap img = (Bitmap)data.getExtras().get("data");
iv.setImageBitmap(img);
}
}
}
Q5.c) Develop and application to send and receive SMS.
Manifest file:-

<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>

<receiver
android:name=".SmsReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>

XML CODE:-

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:orientation="vertical">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="To (Enter recievers phone number)"
android:id="@+id/et1"
android:textSize="24dp"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Text message here"
android:id="@+id/et2"
android:textSize="24dp"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:id="@+id/btn"
android:layout_gravity="center_horizontal"/>

</LinearLayout>
MainActivity.java

package com.example.pranu1;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


SmsReceiver sms = new SmsReceiver();
EditText t1, t2;
Button btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1 = findViewById(R.id.et1);
t2 = findViewById(R.id.et2);
btn = findViewById(R.id.btn);
if(ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.SEND_SMS)!=
PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(MainActivity.this,new String[]
{Manifest.permission.SEND_SMS},100);
}

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
SmsManager smsgr = SmsManager.getDefault();
smsgr.sendTextMessage(t1.getText().toString(), null, t2.getText().toString(), null, null);
Toast.makeText(MainActivity.this, "SMS sent successfully", Toast.LENGTH_LONG).show();
}catch(Exception e){
Toast.makeText(MainActivity.this,"SMS failed, try again later", Toast.LENGTH_LONG).show();
}
}
});
}
@Override
protected void onStart() {
super.onStart();
IntentFilter filter=new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(sms,filter);
}
@Override
protected void onStop() {
super.onStop();
unregisterReceiver(sms); } }
SmsReciever.java

package com.example.pranu1;
import static android.telephony.SmsMessage.createFromPdu;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class SmsReceiver extends BroadcastReceiver{
SmsReceiver(){}
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
// Retrieve the SMS Messages received
Object[] sms = (Object[]) bundle.get("pdus");
// For every SMS message received
for (int i=0; i < sms.length; i++) {
// Convert Object array
SmsMessage smsMessage = createFromPdu((byte[]) sms[i]);
String phone = smsMessage.getOriginatingAddress();
String message = smsMessage.getMessageBody().toString();
Toast.makeText(context, "Recieved From "+phone+" : "+message,Toast.LENGTH_SHORT).show();
}
}
}
}
Q6.a) Android lifecycle methods using Toast message.
package com.example.pranu1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

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

Toast.makeText(getApplicationContext(),"Activity Created",Toast.LENGTH_LONG).show();
}

@Override
protected void onStart(){
super.onStart();
Toast.makeText(getApplicationContext(),"Activity Started",Toast.LENGTH_LONG).show();
}

@Override
protected void onStop(){
super.onStop();
Toast.makeText(getApplicationContext(),"Activity Stopped",Toast.LENGTH_LONG).show();
}

protected void onRestart() {


super.onRestart();
Toast.makeText(getApplicationContext(),"Activity Restarted",Toast.LENGTH_LONG).show();
}

protected void onDestroy(){


super.onDestroy();
Toast.makeText(getApplicationContext(),"Activity Destroyed",Toast.LENGTH_LONG).show();
}

protected void onPause(){


super.onPause();
Toast.makeText(getApplicationContext(),"Activity Paused",Toast.LENGTH_LONG).show();
}

protected void onResume(){


super.onResume();
Toast.makeText(getApplicationContext(),"Activity Resumed",Toast.LENGTH_LONG).show();
}
}
Q6.b) Develop an application to display Google map with user's current
location.
(Already did in S23 Q4.e)

Q6.c) Design UI using table layout to display buttons with 0 9 numbers on it.
Even display submit and clear button. When user clicks on particular buttons
and later when clicks on submit button, it should display the numbers clicked.
XML CODE:-

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">

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

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

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

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

</TableRow>

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

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

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

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

</TableRow>

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

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

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

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

</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">

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

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

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/clear"
android:text="CLEAR"/>
</TableRow>

</TableLayout>

JAVA CODE:-

package com.example.pranu1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {


Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,sub,clr;
String a=null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = findViewById(R.id.bt1);
b2 = findViewById(R.id.bt2);
b3 = findViewById(R.id.bt3);
b4 = findViewById(R.id.bt4);
b5 = findViewById(R.id.bt5);
b6 = findViewById(R.id.bt6);
b7 = findViewById(R.id.bt7);
b8 = findViewById(R.id.bt8);
b9 = findViewById(R.id.bt9);
b10 = findViewById(R.id.bt10);
sub = findViewById(R.id.submit);
clr = findViewById(R.id.clear);

b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a= b1.getText().toString();
}
});

b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a= b2.getText().toString();
}
});

b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a= b3.getText().toString();
}
});

b4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a= b4.getText().toString();
}
});

b5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a= b5.getText().toString();
}
});

b6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a= b6.getText().toString();
}
});

b7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a= b7.getText().toString();
}
});

b8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a= b8.getText().toString();
}
});

b9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a= b9.getText().toString();
}
});

b10.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
a= b10.getText().toString();
}
});

sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),a,Toast.LENGTH_LONG).show();
}
});
}
}
WINTER 2023 PROGRAMS
Q3.c) Write an XML file to create login page using Table Layout.
XML CODE:
<TableLayout android:layout_width="281dp"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="match_parent" android:hint="Enter username" />
tools:context=".MainActivity"> </TableRow>

<TableRow <TableRow>
android:gravity="center_horizontal"> <TextView
android:layout_height="wrap_content"
<TextView android:layout_width="wrap_content"
android:id="@+id/t1" android:text="Password:"
android:layout_width="wrap_content" android:textSize="20sp"/>
android:layout_height="wrap_content"
android:text="LOGIN FORM" <EditText
android:textSize="24sp" android:layout_height="wrap_content"
android:textStyle="bold"/> android:layout_width="wrap_content"
android:id="@+id/et2"
</TableRow> android:hint="Enter Password"/>
</TableRow>
<TableRow>
<TextView <TableRow
android:layout_width="wrap_content" android:gravity="center_horizontal">
android:layout_height="wrap_content" <Button
android:id="@+id/t2" android:id="@+id/btn"
android:text="Username:" android:text="LOGIN" />
android:textSize="20sp" /> </TableRow>

<EditText </TableLayout>
android:id="@+id/et1"
Q3.d) Develop an application to display analog Time Picker. Also display the
selected time.
(Already present in S23 Q4.b)

Q4.c) Develop an android application using Radio Button.


XML CODE:-

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:id="@+id/rb1"/>

<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:id="@+id/rb2"/>
</RadioGroup>

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

</LinearLayout>

JAVA CODE:-

package com.example.p2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


RadioButton r1, r2;
Button btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
r1 = findViewById(R.id.rb1);
r2 = findViewById(R.id.rb2);
btn = findViewById(R.id.btn);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(r1.isChecked()){
Toast.makeText(MainActivity.this,"Male is Selected",Toast.LENGTH_LONG).show();
}else{
Toast.makeText(MainActivity.this,"Female is Selected",Toast.LENGTH_LONG).show();

}
}
});
}
}

Q4.d) Develop an application to send and receive SMS. (Write only Java and
permission tag in manifest file)
(Already did in S22 Q5.c)
Q5.a) Develop a program to perform addition, subtraction, division,
multiplication of two numbers and display the result. (Use appropriate UI
controls).
XML CODE:-

<LinearLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:text="Subtraction"
android:layout_height="match_parent" android:id="@+id/bt2"
android:orientation="vertical"
tools:context=".MainActivity"> android:layout_gravity="center_horizontal"/>

<EditText <Button
android:id="@+id/et1" android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:text="Muliplication"
android:hint="Enter Number 1" android:id="@+id/bt3"

android:layout_gravity="center_horizontal"/> android:layout_gravity="center_horizontal"/>

<EditText <Button
android:id="@+id/et2" android:id="@+id/bt4"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="Enter number 2" android:text="Divison"

android:layout_gravity="center_horizontal"/> android:layout_gravity="center_horizontal"/>

<Button <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Addition" android:layout_marginTop="35dp"
android:id="@+id/bt1" android:textSize="30dp"
android:id="@+id/tv"
android:layout_gravity="center_horizontal"/>
android:layout_gravity="center_horizontal"/>
<Button
android:layout_width="wrap_content" </LinearLayout>

JAVA CODE:-

package com.example.p2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView tv;
Button ad, sb, ml, dv;
EditText et1, et2;
double result;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = findViewById(R.id.tv);
et1 = findViewById(R.id.et1);
et2 = findViewById(R.id.et2);
ad = findViewById(R.id.bt1);
sb = findViewById(R.id.bt2);
ml = findViewById(R.id.bt3);
dv = findViewById(R.id.bt4);

ad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double num1 = Double.parseDouble(et1.getText().toString());
double num2 = Double.parseDouble(et2.getText().toString());
result = num1 + num2;
tv.setText(Double.toString(result));
}
});

sb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double num1 = Double.parseDouble(et1.getText().toString());
double num2 = Double.parseDouble(et2.getText().toString());
result = num1 - num2;
tv.setText(Double.toString(result));
}
});

ml.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double num1 = Double.parseDouble(et1.getText().toString());
double num2 = Double.parseDouble(et2.getText().toString());
result = num1 * num2;
tv.setText(Double.toString(result));
}
});

dv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double num1 = Double.parseDouble(et1.getText().toString());
double num2 = Double.parseDouble(et2.getText().toString());
result = num1/num2;
tv.setText(Double.toString(result));
}
});
}
}

Q5.b) Develop an application to display a Google Map. (Write JAVA &


Manifest file)

Q5.c) Text to Speech


(S23 Q3.c)

Q6.a) Database Program to store manage and retrieve.

Q6.c) Develop a program to TURN ON and OFF Bluetooth.


WINTER 2022 PROGRAMS

Q4.b) WAP to display a rectangular progress bar.


XML CODE:-

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:id="@+id/pg"
android:min="0"
android:max="100"
style="@android:style/Widget.ProgressBar.Horizontal"
android:progress="2"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv"
android:layout_marginTop="20dp"
android:textSize="30dp"
android:textStyle="bold"/>

</LinearLayout>

JAVA CODE:-

package com.example.p2;
import android.os.Bundle;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.os.Handler;
import android.os.Looper;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


private ProgressBar p;
private int pgStatus = 0;
private TextView tv;

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

p = findViewById(R.id.pg);
tv = findViewById(R.id.tv);

new Thread(new Runnable() {


public void run() {
while (pgStatus < 100) {
pgStatus += 1;
new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
p.setProgress(pgStatus);
tv.setText(pgStatus + "/" + p.getMax());
}
});
try {
// Sleep for 200 milliseconds.
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
}

Q4.e) Develop an application to send and receive SMS (Write only Java and
permission tag in manifest file).
(Already did in S22 Q5.c)
Q5.a) To send and receive an email.
XML CODE:-

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Recievers Email"
android:id="@+id/et1"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Subject of email"
android:id="@+id/et2"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/et3"
android:hint="Enter your emails body"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Send"
android:id="@+id/btn"/>

</LinearLayout>

JAVA CODE:-

*Sending part

package com.example.p2;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {


Button b1;
EditText et1, et2, et3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = findViewById(R.id.btn);
et1 = findViewById(R.id.et1);
et2 = findViewById(R.id.et2);
et3 = findViewById(R.id.et3);

b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{et1.getText().toString()});
intent.putExtra(Intent.EXTRA_SUBJECT, new String[]{et2.getText().toString()});
intent.putExtra(Intent.EXTRA_TEXT, new String[]{et2.getText().toString()});
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent,"Choose mail app"));
}
});
}
}

*Receiving part

package com.example.p2;
import android.content.IntentFilter;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


GmailReciever gml;
IntentFilter inf;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gml = new GmailReciever();
inf = new IntentFilter("android.intent.action.VIEW");
}

@Override
protected void onResume(){
super.onResume();
registerReceiver(gml,inf);
}
@Override
protected void onDestroy(){
super.onDestroy();
unregisterReceiver(gml);
}
}
*GmailReciever.java

package com.example.p2;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class GmailReciever extends BroadcastReceiver {


@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"Email Recieved!!",Toast.LENGTH_LONG).show();
}
}

MANIFEST FILE (ONLY IMPT PART)

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.gm.permission.READ_GMAIL"/>

<receiver android:name="GmailReceiver"
android:exported="false"
tools:ignore="WrongManifestParent">
<intent-filter>
<action android:name="android.intent.action.PROVIDER_CHANGED"
android:priority="-10"/>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="content" android:host="gmail-ls"
android:pathPattern="/unread/.*"/>
</intent-filter>
</receiver>

Q5.b) Develop a program for providing Bluetooth connectivity.


(Already did in S23 Q6.c)
Q5.c) Develop a program to implement the following.
i) ListView of 5 items.
ii) GridView of 4x4 items.
iii) Image View.
XML CODE:-

<LinearLayout android:layout_height="300dp"
android:layout_width="match_parent" android:id="@+id/gv"
android:layout_height="match_parent" android:numColumns="4"
android:orientation="vertical" android:gravity="center"/>
tools:context=".MainActivity">
<ImageView
<ListView android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="300dp" android:id="@+id/iv"
android:id="@+id/lv"/> android:src="@drawable/img_4"/>

<GridView </LinearLayout>
android:layout_width="match_parent"

JAVA CODE:-

package com.example.p2;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


ListView lv;
GridView gd;
ImageView iv;
String[] alpha = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L","M","N","O","P"};
String [] arr = {"Apple", "Mango", "Banana", "Litchi", "Papaya", "Ice Apple"};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = findViewById(R.id.lv);
gd = findViewById(R.id.gv);
iv = findViewById(R.id.iv);

ArrayAdapter<String> ap = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,arr);


lv.setAdapter(ap);

ArrayAdapter<String> ap1 = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,alpha);


gd.setAdapter(ap1);
}
}

Q6.a) Develop an application to store customer's details like, customer-id,


customer-name, mobile number, address, pin-code and retrieve customer
information using customer-id in SQLite databases.
XML CODE:-

<LinearLayout android:id="@+id/et5"/>
android:layout_width="match_parent"
android:layout_height="match_parent" <Button
android:orientation="vertical" android:layout_width="wrap_content"
tools:context=".MainActivity"> android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
<EditText android:id="@+id/btn1"
android:layout_width="match_parent" android:text="Submit"/>
android:layout_height="wrap_content"
android:hint="ID" <TextView
android:id="@+id/et1"/> android:layout_width="wrap_content"
<EditText android:layout_height="wrap_content"
android:layout_width="match_parent" android:text="RETRIEVE INFORMATION"
android:layout_height="wrap_content" android:textSize="30dp"/>
android:hint="Name"
android:id="@+id/et2"/> <EditText
<EditText android:layout_width="wrap_content"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:id="@+id/et6"
android:hint="Mobile Number" android:hint="Enter Customer id" />
android:id="@+id/et3"/>
<EditText <Button
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="Address" android:id="@+id/btn2"
android:id="@+id/et4"/> android:text="Find"
<EditText android:layout_gravity="center_horizontal"/>
android:layout_width="match_parent"
android:layout_height="wrap_content" </LinearLayout>
android:hint="Pin Code"

JAVA CODE:-

package com.example.p2;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
SQLiteDatabase dbobj;
EditText e1, e2, e3, e4, e5, e6;
Button b1, b2;
String cid, cname, cno, cadd, cPin, sid, sql;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1 = findViewById(R.id.et1);
e2 = findViewById(R.id.et2);
e3 = findViewById(R.id.et3);
e4 = findViewById(R.id.et4);
e5 = findViewById(R.id.et5);
e6 = findViewById(R.id.et6);
b1 = findViewById(R.id.btn1);
b2 = findViewById(R.id.btn2);

b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dbobj = openOrCreateDatabase("AndroidJSonDataBase", Context.MODE_PRIVATE,null);
dbobj.execSQL("Create Table if Not Exists CustomerDb(id Integer Primary Key
Autoincrement Not Null, name Varchar, number Varchar, address Varchar, pincode Varchar);");
cid = e1.getText().toString();
cname = e2.getText().toString();
cno = e3.getText().toString();
cadd = e4.getText().toString();
cPin = e5.getText().toString();
sql = "INSERT into CustomerDb(id, name, address, number, pincode) VALUES
('''+cid+''','''+cname+''','''+cno+''','''+cadd+''','''+cPin+''');";
dbobj.execSQL(sql);
Toast.makeText(getApplicationContext(),"Data Inserted Successfully",
Toast.LENGTH_LONG).show();
}
});

b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sid = e6.getText().toString();
Cursor cursor = dbobj.rawQuery("select * from CustomerDb where cid="+sid+" ",null);
StringBuffer bf = new StringBuffer();
while(cursor.moveToNext()){
String cid = cursor.getString(1);
String cname = cursor.getString(2);
String cmob = cursor.getString(3);
String caddr = cursor.getString(4);
String cP = cursor.getString(5);
bf.append(cid+" "+cname+" "+cmob+" "+caddr+" "+cP+" \n");
Toast.makeText(getApplicationContext(),bf,Toast.LENGTH_LONG).show();
}
}
});
}
}
Q6.c) Develop a simple calculator using Relative Layout.
XML CODE:-

<RelativeLayout
android:layout_width="match_parent" <Button
android:layout_height="match_parent" android:id="@+id/bt3"
tools:context=".MainActivity"> android:layout_width="wrap_content"
android:layout_height="wrap_content"
<TextView android:layout_marginTop="300dp"
android:layout_width="wrap_content" android:layout_centerHorizontal="true"
android:layout_height="wrap_content" android:text="-" />
android:layout_gravity="center_horizontal"
android:text="SIMPLE CALCULAOR" <Button
android:layout_centerHorizontal="true" android:layout_width="wrap_content"
android:textSize="30dp"/> android:layout_height="wrap_content"
android:id="@+id/bt4"
<EditText android:text="x"
android:layout_width="wrap_content" android:layout_centerHorizontal="true"
android:layout_height="wrap_content" android:layout_marginTop="350dp"/>
android:id="@+id/et1"
android:hint="Enter number 1" <Button
android:layout_marginTop="100dp"/> android:layout_width="wrap_content"
android:layout_height="wrap_content"
<EditText android:id="@+id/bt5"
android:layout_width="wrap_content" android:text="÷"
android:layout_height="wrap_content" android:layout_centerHorizontal="true"
android:id="@+id/et2" android:layout_marginTop="400dp"/>
android:hint="Enter number 2"
android:layout_marginTop="150dp"/> <TextView
android:layout_width="wrap_content"
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="@+id/tv"
android:layout_height="wrap_content" android:layout_marginTop="500dp"
android:id="@+id/bt2" android:layout_centerHorizontal="true" />
android:text="+"
android:layout_centerHorizontal="true" </RelativeLayout>
android:layout_marginTop="250dp"/>
JAVA CODE:-

package com.example.p2;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


EditText num1, num2;
double res;
Button add, sub, mul, div;
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
num1 = findViewById(R.id.et1);
num2 = findViewById(R.id.et2);
add = findViewById(R.id.bt2);
sub = findViewById(R.id.bt3);
mul = findViewById(R.id.bt4);
div = findViewById(R.id.bt5);
tv = findViewById(R.id.tv);

add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double n1 = Double.parseDouble(num1.getText().toString());
double n2 = Double.parseDouble(num2.getText().toString());
res = n1+n2;
tv.setText(Double.toString(res));
}
});

sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double n1 = Double.parseDouble(num1.getText().toString());
double n2 = Double.parseDouble(num2.getText().toString());
res = n1-n2;
tv.setText(Double.toString(res));
}
});

mul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double n1 = Double.parseDouble(num1.getText().toString());
double n2 = Double.parseDouble(num2.getText().toString());
res = n1*n2;
tv.setText(Double.toString(res));
}
});

div.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double n1 = Double.parseDouble(num1.getText().toString());
double n2 = Double.parseDouble(num2.getText().toString());
res = n1/n2;
tv.setText(Double.toString(res));
}
});
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy