practical code and outputs
practical code and outputs
i.activity_main.xml
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*"
android:padding="10dp">
<!-- Table Header -->
<TableRow>
<TextView
android:text="Roll No"
android:padding="8dp"
android:textStyle="bold"
android:background="#E0E0E0"/>
<TextView
android:text="Name"
android:textStyle="bold"
android:padding="8dp"
android:background="#E0E0E0"/>
<TextView
android:text="Grade"
android:textStyle="bold"
android:padding="8dp"
android:background="#E0E0E0"/>
</TableRow>
<TableRow>
<TextView android:text="2" android:padding="8dp"/>
<TextView android:text="Bob" android:padding="8dp"/>
<TextView android:text="B+" android:padding="8dp"/>
</TableRow>
<TableRow>
<TextView android:text="3" android:padding="8dp"/>
<TextView android:text="Charlie" android:padding="8dp"/>
<TextView android:text="A-" android:padding="8dp"/>
</TableRow>
<TableRow>
<TextView android:text="4" android:padding="8dp"/>
<TextView android:text="David" android:padding="8dp"/>
<TextView android:text="B" android:padding="8dp"/>
</TableRow>
<TableRow>
<TextView android:text="5" android:padding="8dp"/>
<TextView android:text="Emma" android:padding="8dp"/>
<TextView android:text="A+" android:padding="8dp"/>
</TableRow>
<TableRow>
<TextView android:text="6" android:padding="8dp"/>
<TextView android:text="Frank" android:padding="8dp"/>
<TextView android:text="B-" android:padding="8dp"/>
</TableRow>
<TableRow>
<TextView android:text="7" android:padding="8dp"/>
<TextView android:text="Grace" android:padding="8dp"/>
<TextView android:text="A" android:padding="8dp"/>
</TableRow>
<TableRow>
<TextView android:text="8" android:padding="8dp"/>
<TextView android:text="Hannah" android:padding="8dp"/>
<TextView android:text="B+" android:padding="8dp"/>
</TableRow>
<TableRow>
<TextView android:text="9" android:padding="8dp"/>
<TextView android:text="Ian" android:padding="8dp"/>
<TextView android:text="C+" android:padding="8dp"/>
</TableRow>
<TableRow>
<TextView android:text="10" android:padding="8dp"/>
<TextView android:text="Jack" android:padding="8dp"/>
<TextView android:text="A-" android:padding="8dp"/>
</TableRow>
</TableLayout>
MainActivity.java
package com.example.prl6_exe1;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
Output:
Prl6-exe2:
i.activity_main.xml
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data Types in OOP"
android:textStyle="bold"
android:textSize="20sp"
android:layout_gravity="top|center_horizontal"
android:paddingBottom="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Integer: 100"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Float: 10.5"
android:layout_gravity="center_horizontal"
android:layout_marginTop="90dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Character: A"
android:layout_gravity="center_horizontal"
android:layout_marginTop="130dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Boolean: true"
android:layout_gravity="center_horizontal"
android:layout_marginTop="170dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="String: Hello, OOP!"
android:layout_gravity="center_horizontal"
android:layout_marginTop="210dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Double: 99.99"
android:layout_gravity="center_horizontal"
android:layout_marginTop="250dp"/>
</FrameLayout>
MainActivity.java
package com.example.prl6_exe2;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
}
}
Output:
Prl7-exe1:
i.activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Username"
android:textSize="18dp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter username"
android:textSize="18dp"
android:inputType="textPersonName"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Password"
android:textSize="18dp"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter password"
android:textSize="18dp"
android:inputType="textPassword"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
/>
</LinearLayout>
ii.MainActivity.java
package com.example.prl7_exe1;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.activity_main);
}
}
Output:
Prl7-exe2
i.activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/t2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Age"
android:inputType="number" />
<EditText
android:id="@+id/t3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Roll No"
android:inputType="number" />
<TextView
android:id="@+id/dis_age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="@+id/dis_rollno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
Java file
package com.example.prl7_exe2;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Get the input data from EditTexts
String Name = name.getText().toString();
String Age = age.getText().toString();
String Rollno = rollno.getText().toString();
dis_age.setVisibility(View.VISIBLE);
dis_age.setText("Age: " + Age);
dis_rollno.setVisibility(View.VISIBLE);
dis_rollno.setText("Roll No: " + Rollno);
}
});
}
}
Output:
Prl9-exe1
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp"
android:gravity="center">
</LinearLayout>
Java code
package com.example.prl9_exe1;
import android.Manifest;
import android.bluetooth.BluetoothAdapter;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.ToggleButton;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize BluetoothAdapter
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// Initialize UI elements
toggleBluetooth = findViewById(R.id.toggleBluetooth);
statusText = findViewById(R.id.statusText);
if (bluetoothAdapter == null) {
statusText.setText("Bluetooth is not supported on this device.");
toggleBluetooth.setEnabled(false);
} else {
// Check Bluetooth state and set ToggleButton
updateBluetoothStatus(); // Ensure the message is set initially
toggleBluetooth.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
// Turn on Bluetooth
if (!bluetoothAdapter.isEnabled()) {
bluetoothAdapter.enable();
statusText.setText("Bluetooth is ON");
}
} else {
// Turn off Bluetooth
if (bluetoothAdapter.isEnabled()) {
bluetoothAdapter.disable();
statusText.setText("Bluetooth is OFF");
}
}
});
}
}
@Override
protected void onResume() {
super.onResume();
// Check Bluetooth state on resume and update the status text
if (bluetoothAdapter != null) {
updateBluetoothStatus(); // Update the status when the activity resumes
}
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[]
grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == PERMISSION_REQUEST_CODE) {
if (grantResults.length > 0) {
boolean bluetoothConnectPermissionGranted = grantResults[0] ==
PackageManager.PERMISSION_GRANTED;
boolean bluetoothScanPermissionGranted = grantResults[1] ==
PackageManager.PERMISSION_GRANTED;
Output:
Prl9-exe2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:gravity="center"
android:weightSum="5">
<Button
android:id="@+id/button1"
android:text="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/button2"
android:text="2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/button3"
android:text="3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/buttonAdd"
android:text="+"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<Button
android:id="@+id/button4"
android:text="4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/button5"
android:text="5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/button6"
android:text="6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/buttonSubtract"
android:text="-"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<Button
android:id="@+id/button8"
android:text="8"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/button9"
android:text="9"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/buttonMultiply"
android:text="*"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
<Button
android:id="@+id/button0"
android:text="0"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/buttonClear"
android:text="C"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/buttonEqual"
android:text="="
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/buttonDivide"
android:text="/"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
Javacode
package com.example.prl9_exe2;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
display = findViewById(R.id.display);
button1.setOnClickListener(numberClickListener);
button2.setOnClickListener(numberClickListener);
button3.setOnClickListener(numberClickListener);
button4.setOnClickListener(numberClickListener);
button5.setOnClickListener(numberClickListener);
button6.setOnClickListener(numberClickListener);
button7.setOnClickListener(numberClickListener);
button8.setOnClickListener(numberClickListener);
button9.setOnClickListener(numberClickListener);
button0.setOnClickListener(numberClickListener);
buttonSubtract.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
firstNumber = Double.parseDouble(input);
operator = "-";
input = "";
}
});
buttonMultiply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
firstNumber = Double.parseDouble(input);
operator = "*";
input = "";
}
});
buttonDivide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
firstNumber = Double.parseDouble(input);
operator = "/";
input = "";
}
});
switch (operator) {
case "+":
result = firstNumber + secondNumber;
break;
case "-":
result = firstNumber - secondNumber;
break;
case "*":
result = firstNumber * secondNumber;
break;
case "/":
if (secondNumber != 0) {
result = firstNumber / secondNumber;
} else {
display.setText("Error");
return;
}
break;
}
display.setText(String.valueOf(result));
input = String.valueOf(result);
}
});
Output:
prl10-exe1
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:gravity="center">
</LinearLayout>
Javacode
package com.example.prl10_exe1;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize views
usernameEditText = findViewById(R.id.username);
passwordEditText = findViewById(R.id.password);
loginButton = findViewById(R.id.loginButton);
// Simple validation
if (username.isEmpty()) {
usernameEditText.setError("Please enter a username");
return;
}
if (password.isEmpty()) {
passwordEditText.setError("Please enter a password");
return;
}
// Simulating login process (In a real-world scenario, you would check credentials
with a backend service)
if (username.equals("user123") && password.equals("password123")) {
// Successful login
Toast.makeText(MainActivity.this, "Login Successful",
Toast.LENGTH_SHORT).show();
// You can move to another screen (e.g., Home Screen)
} else {
// Failed login
Toast.makeText(MainActivity.this, "Invalid username or password",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
Output:
Prl10-exe2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
android:gravity="center">
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize views
usernameEditText = findViewById(R.id.username);
passwordEditText = findViewById(R.id.password);
loginButton = findViewById(R.id.loginButton);
}
}
Output:
prl11-exe1
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp"
android:gravity="center">
Javacode
package com.example.prl11_exe;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
Output:
prl12-exe
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<!-- First two Radio Buttons without RadioGroup -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Single Radio buttons"
android:textSize="18sp"
android:layout_marginBottom="10dp"
android:layout_gravity="center"/>
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio Button 1"
android:textSize="18sp"/>
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio Button 2"
android:textSize="18sp"
android:layout_marginTop="10dp"/>
<!-- Two Radio Buttons inside RadioGroup -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio Button Inside RadioGroup"
android:textSize="18sp"
android:layout_marginTop="30dp"
android:layout_marginBottom="10dp"
android:layout_gravity="center"/>
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:textSize="18sp"/>
<RadioButton
android:id="@+id/radioButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:textSize="18sp"
android:layout_marginTop="10dp"/>
</RadioGroup>
<!-- Button to Show the Selected Radio Button -->
<Button
android:id="@+id/showButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Selected"
android:layout_marginTop="20dp"
android:layout_gravity="center"/>
</LinearLayout>
Javacode
package com.example.prl12_exe;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize the views
radioButton1 = findViewById(R.id.radioButton1);
radioButton2 = findViewById(R.id.radioButton2);
radioButton3 = findViewById(R.id.radioButton3);
radioButton4 = findViewById(R.id.radioButton4);
radioGroup = findViewById(R.id.radioGroup);
showButton = findViewById(R.id.showButton);
Output:
prl13-exe1
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="20dp"
>
<!-- Circular ProgressBar -->
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
/>
<!-- Button to Start Progress -->
<Button
android:id="@+id/startButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Progress"
android:layout_marginTop="20dp"/>
</LinearLayout>
Javacode
package com.example.prl13_exe1;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
// Initialize views
progressBar = findViewById(R.id.progressBar);
startButton = findViewById(R.id.startButton);
Output:
prl13-exe2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="20dp">
<Button
android:id="@+id/btnDownload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DOWNLOAD FILE" />
</LinearLayout>
Javacode
package com.example.prl13_exe2;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Javacode:
package com.example.prl14_exe1;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Set up ArrayAdapter
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, programmingLanguages);
prl14-exe2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="20dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/image1"/>
<Button
android:id="@+id/btnChange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Image"
android:layout_marginTop="20dp"/>
</LinearLayout>
Javacode
package com.example.prl14_exe2;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
btnChange.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isImage1) {
imageView.setImageResource(R.drawable.image2);
} else {
imageView.setImageResource(R.drawable.image1);
}
isImage1 = !isImage1;
}
});
}
}
Output:
After click on button:
prl14-exe3
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<GridView
android:id="@+id/gridView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="3"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"/>
</LinearLayout>
Javacode
package com.example.prl14_exe3;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import androidx.appcompat.app.AppCompatActivity;
Javacode
package com.example.prl14_exe4;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="Hello World.Toast Example"
android:padding="10dp"/>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Toast"
android:textSize="18dp"
/>
</LinearLayout>
Javacode
package com.example.prl15_exe1;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
prl15-exe2
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<CheckBox
android:id="@+id/checkPizza"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pizza"/>
<CheckBox
android:id="@+id/checkCoffee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coffee"/>
<CheckBox
android:id="@+id/checkBurger"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Burger"/>
<Button
android:id="@+id/btnOrder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ORDER"
android:layout_marginTop="20dp"/>
Javacode
package com.example.prl15_exe2;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkPizza = findViewById(R.id.checkPizza);
checkCoffee = findViewById(R.id.checkCoffee);
checkBurger = findViewById(R.id.checkBurger);
btnOrder = findViewById(R.id.btnOrder);
orderSummary = findViewById(R.id.orderSummary);
btnOrder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
StringBuilder orderDetails = new StringBuilder("Selected Items:\n");
int total = 0;
if (checkPizza.isChecked()) {
orderDetails.append("Pizza - 150Rs\n");
total += 150;
}
if (checkCoffee.isChecked()) {
orderDetails.append("Coffee - 50Rs\n");
total += 50;
}
if (checkBurger.isChecked()) {
orderDetails.append("Burger - 120Rs\n");
total += 120;
}
if (total > 0) {
orderDetails.append("Total: ").append(total).append("Rs");
} else {
orderDetails.append("No items selected.");
}
Output:
prl16-exe1
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:timePickerMode="spinner"/>
<Button
android:id="@+id/btnGetTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Selected Time"
android:layout_marginTop="20dp"/>
<TextView
android:id="@+id/textTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Selected Time:"
android:textSize="18sp"
android:layout_marginTop="10dp"/>
</LinearLayout>
Javacode
package com.example.prl16_exe1;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
<TextView
android:id="@+id/textDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Selected Date: "
android:textSize="18sp"/>
<Button
android:id="@+id/btnSelectDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SELECT DATE"
android:layout_marginTop="10dp"/>
<TextView
android:id="@+id/textTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Selected Time: "
android:textSize="18sp"
android:layout_marginTop="20dp"/>
<Button
android:id="@+id/btnSelectTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SELECT TIME"
android:layout_marginTop="10dp"/>
</LinearLayout>
Javacode
package com.example.prl16_exe2;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Calendar;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textDate = findViewById(R.id.textDate);
textTime = findViewById(R.id.textTime);
btnSelectDate = findViewById(R.id.btnSelectDate);
btnSelectTime = findViewById(R.id.btnSelectTime);
calendar = Calendar.getInstance();
btnSelectDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
btnSelectTime.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);
Output:
prl17-exe
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, World!"
android:textSize="24sp"
android:textStyle="bold"/>
</LinearLayout>
Javacode
package com.example.prl17_exe1;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "onCreate: Activity Created");
}
@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart: Activity Started");
}
@Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume: Activity Resumed");
}
@Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause: Activity Paused");
}
@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop: Activity Stopped");
}
@Override
protected void onRestart() {
super.onRestart();
Log.d(TAG, "onRestart: Activity Restarted");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy: Activity Destroyed");
}
}
Output:
prl18-exe1
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:padding="20dp">
<Button
android:id="@+id/btnOpenURL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Navigates" />
</LinearLayout>
Javacode
package com.example.prl18_exe1;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
Javacode
package com.example.prl18_exe2;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
Output:
After click button:
prl18-exe3
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<EditText
android:id="@+id/inputNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter a number"
android:inputType="number" />
<Button
android:id="@+id/calculateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate Factorial" />
</LinearLayout>
MainActivity.java
package com.example.prl18_exe3;
EditText inputNumber;
Button calculateButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
inputNumber = findViewById(R.id.inputNumber);
calculateButton = findViewById(R.id.calculateButton);
calculateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String input = inputNumber.getText().toString().trim();
if (input.isEmpty()) {
Toast.makeText(MainActivity.this, "Please enter a number",
Toast.LENGTH_SHORT).show();
return;
}
<TextView
android:id="@+id/resultText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
SecondActivity.java
package com.example.prl18_exe3;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
TextView resultText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
resultText = findViewById(R.id.resultText);
if (number == -1) {
resultText.setText("Invalid input received.");
return;
}
Output:
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
SystemBroadcastReceiver.java
package com.example.prl21_exe;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import android.widget.Toast;
Output:
Prl22-exe1
Javacode:
package com.example.shakebackground;
import android.graphics.Color;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.RelativeLayout;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
long currentTime = System.currentTimeMillis();
if (currentTime - lastUpdate > 100) {
long diffTime = currentTime - lastUpdate;
lastUpdate = currentTime;
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// Not used in this example
}
@Override
protected void onPause() {
super.onPause();
// Unregister the sensor listener when the activity is paused
if (sensorManager != null) {
sensorManager.unregisterListener(this);
}
}
@Override
protected void onResume() {
super.onResume();
// Re-register the sensor listener when the activity is resumed
if (sensorManager != null && accelerometer != null) {
sensorManager.registerListener(this, accelerometer,
SensorManager.SENSOR_DELAY_UI);
}
}
}
Output:
Prl22-exe2
Javacode:
package com.example.sensordisplay;
import android.hardware.Sensor;
import android.hardware.SensorEventListener;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.List;
Output:
Practical 23-exe1
<ImageView
android:id="@+id/imageCamera"
android:layout_width="match_parent"
android:layout_height="400dp"
android:scaleType="fitXY"
android:layout_gravity="center"
android:layout_margin="20dp" />
<Button
android:id="@+id/capture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#000"
android:text="Capture"
android:textColor="#fff"
android:layout_margin="20dp"/>
</LinearLayout>
Javacode:
package com.example.camera;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.media.Image;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.imageCamera);
button = findViewById(R.id.capture);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent iCamera=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(iCamera,CAMERAREQUEST_CODE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==CAMERAREQUEST_CODE){
Bitmap photo=(Bitmap)data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
}
Output:
After click on the Capture Button:
practical N0-24
=====================XML================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bluetooth"
android:textSize="24sp"
android:textStyle="bold"/>
<Button
android:id="@+id/btnTurnOn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn On" />
<Button
android:id="@+id/btnGetVisible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Get Visible" />
<Button
android:id="@+id/btnListDevices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="List Devices" />
<Button
android:id="@+id/btnTurnOff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn Off" />
</LinearLayout>
=============================javafile================================
package com.example.bluetooth;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Set;
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// Turn ON Bluetooth
btnTurnOn.setOnClickListener(v -> {
if (bluetoothAdapter == null) {
Toast.makeText(this, "Bluetooth Not Supported", Toast.LENGTH_SHORT).show();
} else {
if (!bluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(enableBtIntent);
} else {
Toast.makeText(this, "Bluetooth Already On", Toast.LENGTH_SHORT).show();
}
}
});
// Make Device Visible
btnGetVisible.setOnClickListener(v -> {
Intent discoverableIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300);
startActivity(discoverableIntent);
});
// List Paired Devices
btnListDevices.setOnClickListener(v -> {
if (bluetoothAdapter.isEnabled()) {
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
StringBuilder devicesList = new StringBuilder();
for (BluetoothDevice device : pairedDevices) {
devicesList.append(device.getName()).append(" -
").append(device.getAddress()).append("\n");
}
Toast.makeText(this, devicesList.toString(), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Turn on Bluetooth first", Toast.LENGTH_SHORT).show();
}
});
// Turn OFF Bluetooth
btnTurnOff.setOnClickListener(v -> {
if (bluetoothAdapter.isEnabled()) {
bluetoothAdapter.disable();
Toast.makeText(this, "Bluetooth Turned Off", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Bluetooth Already Off", Toast.LENGTH_SHORT).show();
}
});
}
=============================mainfestxml============================
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<uses-feature android:name="android.hardware.bluetooth" android:required="true" />
Output:
Practical 27-Exe
<TextView
android:id="@+id/loginStatusTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please log in"
android:textSize="18sp"
android:layout_gravity="center"
android:paddingBottom="24dp"/>
<EditText
android:id="@+id/usernameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:inputType="text"
android:padding="12dp"
android:layout_marginBottom="16dp"/>
<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:padding="12dp"
android:layout_marginBottom="32dp"/>
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:padding="12dp"/>
</LinearLayout>
Javacode:
package com.example.login;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initializing views
usernameEditText = findViewById(R.id.usernameEditText);
passwordEditText = findViewById(R.id.passwordEditText);
loginStatusTextView = findViewById(R.id.loginStatusTextView);
loginButton = findViewById(R.id.loginButton);
// Checking credentials
if (enteredUsername.equals("admin") && enteredPassword.equals("admin123")) {
// Login successful
loginStatusTextView.setText("Login Successful");
} else {
// Login failed
Toast.makeText(MainActivity.this, "Login Fail",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
Output:
Practical 28
Javacode:
package com.example.login;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize views
usernameEditText = findViewById(R.id.usernameEditText);
passwordEditText = findViewById(R.id.passwordEditText);
loginButton = findViewById(R.id.loginButton);
@Override
public void beforeTextChanged(CharSequence charSequence, int start, int count, int
after) {}
@Override
public void onTextChanged(CharSequence charSequence, int start, int before, int count)
{
// Check if both fields are not empty
String username = usernameEditText.getText().toString().trim();
String password = passwordEditText.getText().toString().trim();
// Enable the login button if username and password are valid (non-empty)
if (!username.isEmpty() && !password.isEmpty()) {
loginButton.setEnabled(true);
} else {
loginButton.setEnabled(false);
}
}
@Override
public void afterTextChanged(Editable editable) {}
};
Output:
Practical 29-Exe:
========================xmlfile========================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<!-- EditText for phone number -->
<EditText
android:id="@+id/phoneNumberEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Phone Number"
android:inputType="phone" />
<!-- EditText for message -->
<EditText
android:id="@+id/messageEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Message"
android:inputType="text" />
<!-- Button to send SMS -->
<Button
android:id="@+id/sendSmsButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send SMS" />
</LinearLayout>
=====================javafile===========================
package com.example.login;
import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.content.pm.PackageManager;
import androidx.core.content.ContextCompat;
sendSmsButton = findViewById(R.id.sendSmsButton);
phoneNumberEditText = findViewById(R.id.phoneNumberEditText);
messageEditText = findViewById(R.id.messageEditText);
sendSmsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sendSMS();
}
});
}
if (requestCode == REQUEST_SMS_PERMISSION) {
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
// Permissions granted
Toast.makeText(this, "SMS permissions granted",
Toast.LENGTH_SHORT).show();
} else {
// Permissions denied
Toast.makeText(this, "SMS permissions denied", Toast.LENGTH_SHORT).show();
}
}
}
// BroadcastReceiver to handle incoming SMS
public class SMSReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
Object[] pdus = (Object[]) intent.getExtras().get("pdus");
SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
}
// Extract sender and message content
String sender = messages[0].getOriginatingAddress();
String messageBody = messages[0].getMessageBody();
// Show a toast with sender and message
Toast.makeText(context, "SMS from: " + sender + "\nMessage: " + messageBody,
Toast.LENGTH_LONG).show();
}
}
}
}
======================mainfest.xml=============================
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
Output:
Practical 30-exe:
Javacode:
package com.example.pr_30;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
eTo = findViewById(R.id.txtTo);
eSubject = findViewById(R.id.txtSub);
eMsg = findViewById(R.id.txtMsg);
btn = findViewById(R.id.btnSend);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL, new String[]{eTo.getText().toString()});
it.putExtra(Intent.EXTRA_SUBJECT, eSubject.getText().toString());
it.putExtra(Intent.EXTRA_TEXT, eMsg.getText());
it.setType("message/rfc822");
startActivity(Intent.createChooser(it, "Choose Mail App"));
}
});
}
}
Output: