Moj Lo BC
Moj Lo BC
NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB SUBJECT CODE : PBC 501
Problem Statement 01: Create an android application to step-by-step create a
package com.example.databaseapp;
import
android.database.Cursor;
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);
saveButton.setOnClickListener(new
View.OnClickListener() { @Override
public void onClick(View v) {
String name = nameInput.getText().toString();
int age =
Integer.parseInt(ageInput.getText().toString());
boolean isInserted = dbHelper.insertData(name,
age); if (isInserted) {
1
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB Toast.makeText(MainActivity.this, "Data Saved", SUBJECT CODE : PBC 501
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Error Saving Data",
Toast.LENGTH_SHORT).show();
}
}
});
showButton.setOnClickListener(new View.OnClickListener() {
2
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB @Override SUBJECT CODE : PBC 501
public void onClick(View v) {
Cursor cursor = dbHelper.getAllData();
StringBuilder stringBuilder = new
StringBuilder();
if (cursor.getCount() == 0)
{ displayData.setText("No Data
Found"); return;
}
while (cursor.moveToNext()) {
stringBuilder.append("ID: ").append(cursor.getInt(0)).append("\n");
stringBuilder.append("Name: ").append(cursor.getString(1)).append("\n");
stringBuilder.append("Age: ").append(cursor.getInt(2)).append("\n\n");
}
displayData.setText(stringBuilder.toString());
}
});
}
}
DATABASEHELPER CODE :
package com.example.databaseapp;
import
android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import
android.database.sqlite.SǪLiteDatabase;
import
android.database.sqlite.SǪLiteOpenHelper;
3
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB
@Override SUBJECT CODE : PBC 501
public void onCreate(SǪLiteDatabase db) {
String createTableǪuery = "CREATE TABLE " + TABLE_NAME
+ "(" + COLUMN_ID + " INTEGER PRIMARY KEY
AUTOINCREMENT, " + COLUMN_NAME + " TEXT, " +
4
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB COLUMN_AGE + " INTEGER)"; SUBJECT CODE : PBC 501
db.execSǪL(createTableǪuery);
}
@Override
public void onUpgrade(SǪLiteDatabase db, int oldVersion, int newVersion) {
db.execSǪL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
XML CODE :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/and
roid" android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/nameInput"
android:layout_width="match_pa
rent"
android:layout_height="wrap_con
tent" android:hint="Enter Name"
/>
<EditText
android:id="@+id/ageInp
ut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Age"
android:inputType="number" />
5
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB
<Button SUBJECT CODE : PBC 501
android:id="@+id/saveButton"
android:layout_width="match_parent"
6
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB android:layout_height="wrap_con SUBJECT CODE : PBC 501
tent" android:text="Save Data"
/>
<Button
android:id="@+id/showButton"
android:layout_width="match_pa
rent"
android:layout_height="wrap_con
tent" android:text="Show Data"
/>
<TextView
android:id="@+id/displayData"
android:layout_width="match_pare
nt"
android:layout_height="wrap_conte
nt" android:padding="16dp"
android:textSize="16sp" />
</LinearLayout>
7
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB
Problem Statement 02: Create android application to perform SUBJECT
crud CODE : in
operation PBC 501
the
database.
JAVA CODE :
package com.example.crudapp;
import
android.database.Cursor;
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);
addButton.setOnClickListener(v -> {
String name = nameInput.getText().toString();
int age =
Integer.parseInt(ageInput.getText().toString());
boolean isInserted =
dbHelper.insertData(name, age);
8
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB showToast(isInserted, "Record Added"); SUBJECT CODE : PBC 501
});
updateButton.setOnClickListener(v -> {
int id =
Integer.parseInt(idInput.getText().toString());
String name =
nameInput.getText().toString();
int age =
Integer.parseInt(ageInput.getText().toString()); boolean
isUpdated = dbHelper.updateData(id, name, age);
showToast(isUpdated, "Record Updated");
});
9
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB SUBJECT CODE : PBC 501
deleteButton.setOnClickListener(v -> {
int id =
Integer.parseInt(idInput.getText().toString());
boolean isDeleted =
dbHelper.deleteData(id);
showToast(isDeleted, "Record Deleted");
});
viewButton.setOnClickListener(v -
> { Cursor cursor =
dbHelper.getAllData();
StringBuilder stringBuilder = new StringBuilder();
if (cursor.getCount() == 0)
{ displayData.setText("No Data
Found"); return;
}
while (cursor.moveToNext()) {
stringBuilder.append("ID: ").append(cursor.getInt(0)).append("\n");
stringBuilder.append("Name: ").append(cursor.getString(1)).append("\n");
stringBuilder.append("Age: ").append(cursor.getInt(2)).append("\n\n");
}
displayData.setText(stringBuilder.toString());
});
}
import
android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import
android.database.sqlite.SǪLiteDatabase;
import
android.database.sqlite.SǪLiteOpenHelper;
10
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB
public class DatabaseHelper extends SUBJECT CODE : PBC 501
SǪLiteOpenHelper { private static final String
DATABASE_NAME = "StudentDB"; private static final
int DATABASE_VERSION = 1;
11
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB
private static final String COLUMN_ID
= "ID"; SUBJECT CODE : PBC 501
private static final String COLUMN_NAME =
"Name"; private static final String
COLUMN_AGE = "Age";
@Override
public void onCreate(SǪLiteDatabase db) {
String createTableǪuery = "CREATE TABLE " + TABLE_NAME
+ " (" + COLUMN_ID + " INTEGER PRIMARY KEY
AUTOINCREMENT, " + COLUMN_NAME + " TEXT, " +
COLUMN_AGE + " INTEGER)";
db.execSǪL(createTableǪuery);
}
@Override
public void onUpgrade(SǪLiteDatabase db, int oldVersion, int newVersion) {
db.execSǪL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
// Create
public boolean insertData(String name, int
age) { SǪLiteDatabase db =
this.getWritableDatabase(); ContentValues
values = new ContentValues();
values.put(COLUMN_NAME, name);
values.put(COLUMN_AGE, age);
long result = db.insert(TABLE_NAME, null,
values); return result != -1;
}
// Read
public Cursor getAllData() {
SǪLiteDatabase db = this.getReadableDatabase();
return db.rawǪuery("SELECT * FROM " + TABLE_NAME, null);
}
// Update
public boolean updateData(int id, String name,
int age) { SǪLiteDatabase db =
this.getWritableDatabase(); ContentValues
values = new ContentValues();
values.put(COLUMN_NAME, name);
values.put(COLUMN_AGE, age);
int rowsAffected = db.update(TABLE_NAME, values, COLUMN_ID + "=?", new
String[]{String.valueOf(id)});
return rowsAffected > 0;
12
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB
} SUBJECT CODE : PBC 501
13
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB SUBJECT CODE : PBC 501
// Delete
public boolean deleteData(int id) {
SǪLiteDatabase db = this.getWritableDatabase();
int rowsDeleted = db.delete(TABLE_NAME, COLUMN_ID + "=?", new String[]
{String.valueOf(id)}); return rowsDeleted > 0;
}
}
XML CODE :
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/and
roid" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/idInp
ut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter ID"
android:inputType="number" />
<EditText
android:id="@+id/nameInput"
android:layout_width="match_pa
rent"
android:layout_height="wrap_con
tent" android:hint="Enter Name"
/>
<EditText
android:id="@+id/ageInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Age"
android:inputType="number" />
<Button
android:id="@+id/addButton
"
android:layout_width="match_pa
rent"
android:layout_height="wrap_con
tent" android:text="Add Record"
14
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB /> SUBJECT CODE : PBC 501
<Button
android:id="@+id/updateButt
on"
15
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB android:layout_width="match_pa SUBJECT CODE : PBC 501
rent"
android:layout_height="wrap_con
tent" android:text="Update
Record" />
<Button
android:id="@+id/deleteButton"
android:layout_width="match_pa
rent"
android:layout_height="wrap_con
tent" android:text="Delete
Record" />
<Button
android:id="@+id/viewButton
"
android:layout_width="match_pa
rent"
android:layout_height="wrap_con
tent" android:text="View All
Records" />
<TextView
android:id="@+id/displayData"
android:layout_width="match_pa
rent"
android:layout_height="wrap_con
tent"
android:text="Data will be displayed
here" android:padding="16dp"
android:textSize="16sp" />
</LinearLayout>
</ScrollView>
16
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB
Problem Statement 03: Create android application to load SUBJECT CODE : PBC 501
package com.example.googlemapsapp;
import
androidx.fragment.app.FragmentActivity;
import android.os.Bundle;
import
com.google.android.gms.maps.CameraUpdateFactory
; import com.google.android.gms.maps.GoogleMap;
import
com.google.android.gms.maps.OnMapReadyCallback;
import
com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
@Override
protected void onCreate(Bundle
savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Obtain the SupportMapFragment and get notified when the map is ready to be
used. SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.ma
p); if (mapFragment != null) {
mapFragment.getMapAsync(this);
}
}
@Override
public void onMapReady(GoogleMap
googleMap) { mMap = googleMap;
18
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB
xmlns:tools="http://schemas.android.com/tools"> SUBJECT CODE : PBC 501
<application
android:allowBackup="tr
ue"
android:dataExtractionRules="@xml/
data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.GoogleMapsApp"
tools:targetApi="31">
<meta-data
android:name="com.google.android.geo.API
_KEY"
android:value="AIzaSyDYSaLIFOhVhL1rNhJV--r0OEǪ3q6lsqR4" />
<activity
android:name=".MainActi
vity"
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</
manifest>
XML
CODE :
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragme
nt" android:layout_width="match_parent"
android:layout_height="match_parent" />
19
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB
</RelativeLayout> SUBJECT CODE : PBC 501
20
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB SUBJECT CODE : PBC 501
Problem Statement 04: Create an application to show EMEI number access the
package com.example.showimei;
import android.Manifest;
import
android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import
android.telephony.TelephonyManager;
import android.widget.Button;
import
android.widget.TextView;
import
android.widget.Toast;
import androidx.annotation.NonNull;
import
androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
@Override
protected void onCreate(Bundle
savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imeiText = findViewById(R.id.imeiText);
Button getIMEIButton = findViewById(R.id.getIMEIButton);
getIMEIButton.setOnClickListener(v -> {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
==
PackageManager.PERMISSION_GRANTED) {
getIMEI();
} else {
requestPhoneStatePermission(
);
}
});
}
21
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB
private void getIMEI() SUBJECT CODE : PBC 501
{ try {
TelephonyManager telephonyManager = (TelephonyManager)
getSystemService(TELEPHONY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Ǫ) {
imeiText.setText("IMEI access is restricted on Android 10+");
} else if (telephonyManager != null) {
22
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB String imei = SUBJECT CODE : PBC 501
telephonyManager.getDeviceId();
imeiText.setText("IMEI: " + imei);
} else {
imeiText.setText("Unable to fetch IMEI");
}
} catch (SecurityException e) {
Toast.makeText(this, "Permission not granted!", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[]
permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions,
grantResults); if (requestCode == PERMISSION_REǪUEST_CODE) {
if (grantResults.length > 0 CC grantResults[0] ==
PackageManager.PERMISSION_GRANTED) { getIMEI();
} else {
Toast.makeText(this, "Permission Denied", Toast.LENGTH_SHORT).show();
}
}
}
}
MANIFEST.XML CODE :
<uses-permission
android:name="android.permission.READ_PRIVILEGED_PHONE_STATE"
tools:ignore="ProtectedPermissions" />
<application
android:allowBackup="tr
ue"
android:dataExtractionRules="@xml/
data_extraction_rules"
23
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB android:fullBackupContent="@xml/backup_rules" SUBJECT CODE : PBC 501
android:icon="@mipmap/ic_launcher"
24
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB android:label="@string/app_name" SUBJECT CODE : PBC 501
android:roundIcon="@mipmap/ic_launcher_ro
und" android:supportsRtl="true"
android:theme="@style/Theme.ShowIMEI"
tools:targetApi="31">
<activity
android:name=".MainActi
vity"
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</
manifest>
XML
CODE :
<TextView
android:id="@+id/imeiTe
xt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="IMEI will appear here"
android:textSize="18sp"
android:textStyle="bold"
android:padding="8dp"
android:gravity="center" />
<Button
android:id="@+id/getIMEIButton
"
android:layout_width="wrap_con
tent"
25
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB android:layout_height="wrap_cont SUBJECT CODE : PBC 501
ent" android:text="Get IMEI"
android:layout_gravity="center" /
>
</LinearLayout>
26
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB
Problem Statement 05: Create an android application to show SUBJECT
OTP CODE : PBC 501
based
package com.example.otpautnetication;
import android.os.Bundle;
import android.view.View;
import
android.widget.Button;
import
android.widget.EditText;
import
android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import
com.google.firebase.FirebaseException;
import
com.google.firebase.auth.FirebaseAuth;
import
com.google.firebase.auth.PhoneAuthCredential;
import
com.google.firebase.auth.PhoneAuthProvider;
@Override
protected void onCreate(Bundle
savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
EditText phoneInput =
findViewById(R.id.phoneInput); EditText otpInput =
findViewById(R.id.otpInput);
Button sendOtpButton =
findViewById(R.id.sendOtpButton); Button
verifyOtpButton = findViewById(R.id.verifyOtpButton);
sendOtpButton.setOnClickListener(v -> {
String phoneNumber = phoneInput.getText().toString();
if (phoneNumber.isEmpty() || phoneNumber.length() < 10) {
Toast.makeText(MainActivity.this, "Enter a valid phone number",
27
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB
Toast.LENGTH_SHORT).show(); SUBJECT CODE : PBC 501
return;
}
sendVerificationCode(phoneNumber);
otpInput.setVisibility(View.VISIBLE);
verifyOtpButton.setVisibility(View.VISIBLE);
});
28
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB verifyOtpButton.setOnClickListener(v SUBJECT CODE : PBC 501
-> { String otp =
otpInput.getText().toString(); if
(otp.isEmpty() || otp.length() < 6) {
Toast.makeText(MainActivity.this, "Enter valid OTP",
Toast.LENGTH_SHORT).show(); return;
}
verifyCode(otp);
});
}
@Override
public void onVerificationFailed(@NonNull FirebaseException e) {
@Override
public void onCodeSent(String verificationId,
token) PhoneAuthProvider.ForceResendingToken
{
MainActivity.this.verificationId = verificationId;
Toast.makeText(MainActivity.this, "OTP Sent",
Toast.LENGTH_SHORT).show();
}
});
}
30
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB Toast.makeText(MainActivity.this, SUBJECT CODE : PBC 501
task.getException().getMessage(),
Toast.LENGTH_LONG).show();
}
});
}
}
XML CODE :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/and
roid" android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/phoneInput"
android:layout_width="match_pa
rent"
android:layout_height="wrap_content"
android:hint="Enter Phone Number"
android:inputType="phone" />
<Button
android:id="@+id/sendOtpButton"
android:layout_width="match_pare
nt"
android:layout_height="wrap_conte
nt" android:text="Send OTP" />
<EditText
android:id="@+id/otpInp
ut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter OTP"
android:inputType="number"
android:visibility="gone" />
<Button
android:id="@+id/verifyOtpButton
"
android:layout_width="match_pare
nt"
android:layout_height="wrap_conte
nt" android:text="Verify OTP"
android:visibility="gone" />
</LinearLayout>
31
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB SUBJECT CODE : PBC 501
32
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB SUBJECT CODE : PBC 501
Problem Statement 05: Create an application to
package com.example.loginapp;
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;
AppCompatActivity {
@Override
protected void onCreate(Bundle
savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnLogin.setOnClickListener(new
View.OnClickListener() { @Override
public void onClick(View v) {
String email = etEmail.getText().toString();
String password = etPassword.getText().toString();
if (email.equals("[email protected]") CC password.equals("password123")) {
Toast.makeText(MainActivity.this, "Login Successful!",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Invalid Email or Password",
Toast.LENGTH_SHORT).show();
}
}
});
}
33
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB
} SUBJECT CODE : PBC 501
XML CODE :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/and
roid" android:layout_width="match_parent"
34
NAME : SHIVAM NEGI UNIVERSITY ROLL.NO :
COURSE : BCA C1 2221967 CLASS ROLL.NO :
SUBJECT : ANDROID PROGRAMMING 58
LAB
android:layout_height="match_parent" SUBJECT CODE : PBC 501
android:orientation="vertical"
android:padding="16dp"
android:gravity="center">
<EditText
android:id="@+id/etEmai
l"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/etPassword"
android:layout_width="match_pa
rent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:layout_marginTop="8dp" />
<Button
android:id="@+id/btnLo
gin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:layout_marginTop="16dp" />
</LinearLayout>
35