0% found this document useful (0 votes)
23 views58 pages

Lab Report 22bce10410

Uploaded by

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

Lab Report 22bce10410

Uploaded by

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

Mobile Application Development

Course Code: CSE3012


Lab Report
Submitted by

NAME –

Mukul

Choudhari
REGNO –22BCE10410

Submitted to

Dr. Swagat Kumar Samantaray

VIT Bhopal University


Bhopal, MadhyaPradhesh

October, 2024
Registration no: 22BCE10410

Table of Contents

SL.NO Name of the experiment DATE:


1. 7 October 2024
Study of Android Studio IDE

2. Displaying “NAME”, REG.No: and a 7 October 2024


Welcome Message on the screen
3. Activity life cycle through log message 14 October 2024
4. Use two toggle button and show the status through 16 October 2024
Toast Message
5. Working with Linear and Constraint Layout 21 October 2024
6. Design an option Menu Bar 4 November 2024
7. To create and implement a context menu in an 18 November 2024
Android application that displays toast
messages for selected menu items upon long-
clicking a TextView.
8. Navigation using image and back button 20 November 2024
9. Android application with four buttons: "Email," 22 November 2024
"VIT Bhopal Website," "Google MAP," and "My
Camera,"
10. Proximity Sensor 27 November 2024
11. To implement and install the SQLite 11 December 2024
database in an Android application collecting
user details as the data.

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

Date: 7th Oct 2024 Title

Exp. No: 01 Study of Android Studio IDE

AIM: To study and understand the features, tools, and functionalities of the Android Studio
Integrated Development Environment (IDE) for developing Android applications.

PROCEDURE: 1. Install Android Studio:


 Download the latest version of Android Studio from the official website.
 Follow the installation instructions based on the operating system (Windows, macOS, or
Linux).

2. Setup Android Studio:


 Open Android Studio and configure the initial settings.
 Download necessary SDKs and system images for Android development.
 Set up a new virtual device for running the application.

3. Create a New Project:


 Click on "Start a new Android Studio project."
 Select a project template (e.g., "Empty Activity").
 Set the project name, package name, and save location.
 Choose the target device SDK (e.g., API level 23 or above).

4. Explore the Android Studio Interface:


 Understand the project structure (Java/Kotlin files, XML layouts, resources, etc.).
 Get familiar with the different panels such as "Project," "Logcat," "Terminal," and "Design
Editor."

5. Write a Simple Application:


 Create a basic "Hello World" Android application.
 Modify the activity_main.xml layout file to add UI components like TextView, Button, etc.
 Implement click listeners in the Java/Kotlin activity file to handle user interaction.

6. Run and Debug the Application:


 Use the "Run" button to build and deploy the application on an emulator or physical device.
 Debug the application using breakpoints, watch variables, and the Logcat tool.

7. Analyse the Project:


 Check the generated files and resources.
 Explore the build files like build.gradle and understand their role in the project.

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

CODE: 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">

<TextView
android:id="@+id/helloText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, World!"
android:textSize="24sp"
android:layout_gravity="center"/>

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
android:layout_gravity="center"
android:marginTop="20dp"/>
</LinearLayout>

MainActivity.java:
package com.example.helloworld;

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

public class MainActivity extends AppCompatActivity {


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

final TextView helloText = findViewById(R.id.helloText);


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

// Set OnClickListener for the button


button.setOnClickListener(new View.OnClickListener() {
Name/Signature: Mukul Choudhari
Registration no: 22BCE10410

@Override
public void onClick(View v) {
helloText.setText("Button Clicked!");
}
});
}
}

DESCRIPTION: Android Studio is the official IDE for Android development provided by
Google. It includes tools for developing and testing Android applications, such as a code editor,
layout editor, emulators, and various debugging tools. It supports multiple programming
languages, including Java, Kotlin, and C++. This experiment involves exploring the Android
Studio IDE, creating a basic application, and understanding its project structure.

RESULT: The experiment results in the creation of a simple "Hello World" application in
Android Studio, which includes a TextView and a Button. When the button is clicked, the text in
the TextView changes to "Button Clicked!" This demonstrates the use of layout components and
event handling in Android.

OBSERVATION: 1. The Android Studio IDE provides a robust and user-friendly environment
for Android application development.
2. The IDE offers various tools like Logcat for debugging, layout editor for designing UI, and
code editor with IntelliSense for code completion.
3. The project structure is well-organized, and the build system (Gradle) simplifies project
management.

CONCLUSION : The study of Android Studio IDE provided a comprehensive understanding of


its functionalities and tools. The experiment helped in getting hands-on experience in creating and
deploying a basic Android application. Mastering Android Studio is essential for efficient Android
development as it integrates all necessary tools in one place.

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

Date: 7th Oct 2024 Title

Exp. No: 02 Android app displaying name, reg.no and welcome message on screen

AIM: To design and implement a simple Android application that displays a user’s name,
registration number, and a welcome message using TextViews and basic layout elements.

PROCEDURE: 1. Set Up the Android Studio Project:


 Open Android Studio and select "Start a new Android Studio project."
 Choose "Empty Activity" as the project template.
 Set the project name (e.g., "DisplayInfoApp") and specify the package name.
 Select the save location and click on "Finish" to create the project.

2. Create the UI Layout:


 Open the activity_main.xml layout file located under the res/layout directory.
 Use a LinearLayout or RelativeLayout to arrange the components vertically.
 Add three TextView elements in the layout file to display:
o The user’s name (e.g., "Mukul")
o The registration number (e.g., "22BCE10410")
o A welcome message (e.g., "Welcome to Android Development")

3. Modify the MainActivity.java File:


 Open the MainActivity.java file located under the java directory.
 Initialize the TextView components and set their text values programmatically (if needed).

4. Run and Test the Application:


 Connect a physical Android device or start an emulator using AVD (Android Virtual
Device).
 Click on the "Run" button to build and deploy the application.
 Verify that the name, registration number, and welcome message are displayed correctly on
the screen.

CODE: 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"
android:gravity="center"
android:background="@android:color/holo_blue_light">

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

<TextView
android:id="@+id/nameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: Mukul"
android:textSize="24sp"
android:textColor="@android:color/white"
android:layout_marginBottom="16dp"/>

<TextView
android:id="@+id/registrationText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Registration No: 22BCE10410"
android:textSize="24sp"
android:textColor="@android:color/white"
android:layout_marginBottom="16dp"/>

<TextView
android:id="@+id/welcomeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to Android Development"
android:textSize="24sp"
android:textColor="@android:color/white"/>

</LinearLayout>

MainActivity.java:
package com.example.displayinfoapp;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

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

// TextViews are already set up in XML, no need to programmatically change the text.
// Additional logic can be added here if needed in the future.
}
}

DESCRIPTION: This experiment involves creating a basic Android application that displays a
user’s name, registration number, and a welcome message using the Android Studio IDE. The app
consists of a single activity (MainActivity) and a corresponding layout file (activity_main.xml)
that defines the UI components. The user interface uses a LinearLayout to vertically arrange three
Name/Signature: Mukul Choudhari
Registration no: 22BCE10410

TextView elements for displaying the desired information.

RESULT: The Android application successfully displays the following information on the screen:
 Name: Mukul
 Registration Number: 22BCE10410
 Message: Welcome to Android Development

OBSERVATION: 1. The Android Studio IDE provides an intuitive way to design the UI using
XML layout files.
2. TextView components can be customized using various attributes like textSize, textColor, and
layout_margin.
3. The layout and structure of the application are easy to understand and modify based on
requirements.

CONCLUSION : The experiment was successful in creating a basic Android application to


display static text information using TextView elements. It demonstrated the use of Android
Studio’s layout editor and the simplicity of creating UI components. This forms the foundation for
more complex applications in Android development.

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

Date: 14th Oct 2024 Title

Exp. No: 03 Activity life cycle through log message

AIM: To study and demonstrate the activity lifecycle of an Android app by displaying messages
through the Log.d() method in the Logcat console and showing Toast messages during lifecycle
events.

PROCEDURE: 1. Create a New Project in Android Studio:


 Open Android Studio and create a new project by selecting "Empty Activity".
 Name the project (e.g., "LifecycleDemo") and click Finish.
2. Modify the MainActivity.java File:
 Override lifecycle methods: onCreate(), onStart(), onResume(), onPause(), onStop(),
onRestart(), and onDestroy() in the MainActivity class.
 Inside each lifecycle method, use Log.d() to print log messages in the Logcat console and use
Toast messages to display messages on the screen.
3. Run the App on an Emulator/Device:
 Open the Logcat console in Android Studio to monitor log messages.
 Use various scenarios (like opening, closing, minimizing, and switching the app) to trigger
lifecycle events and observe the corresponding log and toast messages.

CODE: MainActivity.java
package com.example.lifecycleDemo;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private static final String TAG = "LifecycleDemo";

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

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

Log.d(TAG, "onCreate() called");


Toast.makeText(this, "onCreate() called", Toast.LENGTH_SHORT).show();
}

@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart() called");
Toast.makeText(this, "onStart() called", Toast.LENGTH_SHORT).show();
}

@Override
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume() called");
Toast.makeText(this, "onResume() called", Toast.LENGTH_SHORT).show();
}

@Override
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause() called");
Toast.makeText(this, "onPause() called", Toast.LENGTH_SHORT).show();
}

@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop() called");
Toast.makeText(this, "onStop() called", Toast.LENGTH_SHORT).show();
}

@Override
protected void onRestart() {
super.onRestart();
Log.d(TAG, "onRestart() called");
Toast.makeText(this, "onRestart() called", Toast.LENGTH_SHORT).show();
}

@Override
protected void onDestroy() {
super.onDestroy();
Log.d(TAG, "onDestroy() called");
Toast.makeText(this, "onDestroy() called", Toast.LENGTH_SHORT).show();
}
}

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

DESCRIPTION: Android applications go through several states as they are opened, minimized,
resumed, or closed. These states are defined by the activity lifecycle methods:
 onCreate(): Called when the activity is created.
 onStart(): Called when the activity becomes visible to the user.
 onResume(): Called when the activity is ready to interact with the user.
 onPause(): Called when the activity is partially obscured (e.g., user switches apps).
 onStop(): Called when the activity is no longer visible.
 onRestart(): Called when the activity is restarted after being stopped.
 onDestroy(): Called before the activity is destroyed.
This experiment demonstrates the transitions between these states through log and toast messages,
making it easier to track and understand the lifecycle flow.

RESULT: 1. Log messages for each lifecycle event are visible in the Logcat console with the tag
"LifecycleDemo".
2. Toast messages appear on the screen during each lifecycle event.
3. The flow of messages corresponds to the lifecycle transitions, such as:
 When the app starts: onCreate() -> onStart() -> onResume().
 When the app is minimized: onPause() -> onStop().
 When the app is reopened: onRestart() -> onStart() -> onResume().
 When the app is closed: onPause() -> onStop() -> onDestroy().

OBSERVATION: 1. Each lifecycle event is correctly triggered based on user interactions with
the app.
2. The Log.d() method prints messages in the Logcat console, helping with debugging and
monitoring.
3. Toast messages provide a visible confirmation of lifecycle events on the device/emulator.
4. The order of lifecycle callbacks can vary slightly based on whether the activity is being paused,
restarted, or destroyed.

CONCLUSION : This experiment successfully demonstrates the activity lifecycle in Android.


Monitoring the activity lifecycle using Logcat logs and Toast messages provides insights into how
Android apps transition through different states. Understanding these transitions is crucial for
developers to manage resources effectively and ensure smooth user experiences.

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

Date: 16th Oct 2024 Title

Exp. No: 04 Use two toggle button and show the staus through Toaste Message

AIM: To develop an Android application that demonstrates the use of Toggle Buttons and shows
their status through Toast messages.

PROCEDURE: 1. Set up Android Studio:


 Open Android Studio and create a new project.
 Select Empty Activity template and click Next.
 Set the name of the project (e.g., ToggleButtonDemo) and click Finish.
2. Design the Layout (XML):
 Open activity_main.xml and add two ToggleButtons.
 Add a Button to display the status of the Toggle Buttons through Toast messages.
3. Write the Logic (Java/Kotlin):
 Open MainActivity.java or MainActivity.kt.
 Implement onClickListeners for the toggle buttons and the display button.
 Use Toast to display the current state (ON/OFF) of each Toggle Button.
4. Run the Application:
 Connect an Android device or emulator.
 Click Run to see the application in action.

CODE:

XML Layout (activity_main.xml):


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">

<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="Toggle 1 OFF"
android:textOn="Toggle 1 ON"
android:layout_centerHorizontal="true"
Name/Signature: Mukul Choudhari
Registration no: 22BCE10410

android:layout_marginTop="50dp" />

<ToggleButton
android:id="@+id/toggleButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="Toggle 2 OFF"
android:textOn="Toggle 2 ON"
android:layout_below="@id/toggleButton1"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp" />

<Button
android:id="@+id/statusButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Status"
android:layout_below="@id/toggleButton2"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" />
</RelativeLayout>

Java Code (MainActivity.java):


package com.example.togglebuttondemo;

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

public class MainActivity extends AppCompatActivity {

ToggleButton toggleButton1, toggleButton2;


Button statusButton;

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

toggleButton1 = findViewById(R.id.toggleButton1);
Name/Signature: Mukul Choudhari
Registration no: 22BCE10410

toggleButton2 = findViewById(R.id.toggleButton2);
statusButton = findViewById(R.id.statusButton);

statusButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String status1 = toggleButton1.isChecked() ? "ON" : "OFF";
String status2 = toggleButton2.isChecked() ? "ON" : "OFF";

String message = "Toggle 1: " + status1 + "\nToggle 2: " + status2;


Toast.makeText(MainActivity.this, message,
Toast.LENGTH_SHORT).show();
}
});
}
}
DESCRIPTION: This Android app contains two Toggle Buttons labeled as "Toggle 1" and "Toggle
2". When the user toggles these buttons ON or OFF, the state of each button can be checked using a
Button labeled "Show Status". On clicking the "Show Status" button, Toast messages will appear
indicating the current state (ON/OFF) of the two toggle buttons.

RESULT: When the user clicks the "Show Status" button, a Toast message appears, showing
whether Toggle 1 and Toggle 2 are ON or OFF.

OBSERVATION: 1. The Toggle Buttons successfully switch between ON and OFF states.
2. The Toast messages correctly display the current state of both toggle buttons.

CONCLUSION : This Android application effectively demonstrates the use of Toggle Buttons
to switch between two states (ON/OFF) and shows their current status through Toast messages.
This project helps in understanding the implementation of interactive UI elements in Android
applications.

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

Date: 21st Oct 2024 Title

Exp. No: 05 Working with Linear and Constraint Layout

AIM: To design a simple login page using both ConstraintLayout and LinearLayout in Android,
and to compare their usability and appearance.

PROCEDURE: 1. Setup the Android Environment:


 Open Android Studio and create a new project.
 Choose "Empty Activity" and name it appropriately (e.g., "LoginPage").
 Select Kotlin or Java as the programming language.
2. Implement the Layout Using ConstraintLayout:
 Open the activity_main.xml file.
 Use ConstraintLayout to create the login interface with username and password fields.
3. Run the Application:
 Observe how the components align and behave in ConstraintLayout.
4. Modify the Layout to Use LinearLayout:
 Replace the ConstraintLayout code with LinearLayout code in the same XML file.
 Ensure components are aligned vertically.
5. Run the Application Again:
 Observe how the components align and behave in LinearLayout.
6. Set Predefined Values:
 Set the username to "Mukul" and the password to "22BCE10410".

CODE:
1. Using ConstraintLayout:
<!-- activity_main.xml -->
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<EditText
android:id="@+id/username"
android:layout_width="0dp"
android:layout_height="wrap_content"
Name/Signature: Mukul Choudhari
Registration no: 22BCE10410

android:hint="Username"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="100dp" />

<EditText
android:id="@+id/password"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="Password"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/username"
android:layout_marginTop="20dp" />

<Button
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/password"
android:layout_marginTop="30dp" />

</androidx.constraintlayout.widget.ConstraintLayout>

// MainActivity.java
package com.example.loginpage;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private EditText usernameEditText;


private EditText passwordEditText;
private Button loginButton;

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

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

// Initialize UI components
usernameEditText = findViewById(R.id.username);
passwordEditText = findViewById(R.id.password);
loginButton = findViewById(R.id.login_button);

// Set predefined values


usernameEditText.setText("Mukul");
passwordEditText.setText("22BCE10410");

// Set click listener for login button


loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Handle login button click here (e.g., validation)
}
});
}
}

2. Using LinearLayout:
<!-- activity_main.xml -->
<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="16dp">

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

<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:layout_marginTop="20dp" />

<Button
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_marginTop="30dp" />

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

</LinearLayout>
<!-- activity_main.xml (LinearLayout version) -->
<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="16dp">

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

<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:layout_marginTop="20dp" />

<Button
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_marginTop="30dp" />

</LinearLayout>

DESCRIPTION: 1. ConstraintLayout: This layout allows for flexible positioning of views based on
constraints relative to each other. It helps create a responsive UI that adapts well to different screen sizes.
2. LinearLayout: This layout arranges child views either vertically or horizontally. In this case, we use
vertical orientation to stack the username and password fields on top of each other, providing a simple and
straightforward layout.

RESULT: When the application is run:


 With ConstraintLayout: The elements are positioned according to constraints, creating a
more flexible and scalable UI.
 With LinearLayout: The elements stack neatly in a vertical line, which can be easier to
manage for simple forms.

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

OBSERVATION: 1. The ConstraintLayout provides more flexibility for complex layouts,


allowing better use of available screen space.
2. The LinearLayout is simpler and more intuitive for straightforward designs, but it can become
cumbersome for more complex UIs.
CONCLUSION : 1. Use ConstraintLayout when building more complex and responsive
interfaces.
3. Use LinearLayout for simpler interfaces where elements are stacked or lined up.

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

Date: 4th Nov 2024 Title

Exp. No: 06 Design an option Menu Bar

AIM: To design and implement an option Menu Bar in an Android application, where each menu
item displays a toast message upon selection. The menu should contain items for the user's name,
registration number, branch, and a semester option with sub-items for subjects.

PROCEDURE: 1. Set Up the Project:


 Open Android Studio and create a new project.
 Configure the main activity and set up the required XML files.
2. Design the Menu Bar in XML:
 In the res/menu directory, create a new XML file menu_main.xml.
 Define menu items for "Name," "Registration Number," "Branch," and "Semester" with sub-items for
each subject.
3. Implement Java Code for Toast Messages:
 In MainActivity.java, override the onCreateOptionsMenu method to inflate the menu XML.
 Override the onOptionsItemSelected method to handle menu item clicks.
 For each menu item, implement a toast message that displays a specific message when that item is
selected.
4. Run and Test the Application:
 Deploy the application on an emulator or physical Android device.
 Verify that selecting each menu item displays the appropriate toast message.
 Test sub-items under "Semester" to ensure they also display specific toast messages when selected.

CODE:
1. Create a new menu XML file (e.g., menu_main.xml) in the res/menu folder.
<!-- res/menu/menu_main.xml -->
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- First item: Name -->
<item
android:id="@+id/menu_name"
android:title="Your Name"/>

<!-- Second item: Registration Number -->


<item
android:id="@+id/menu_reg_no"
android:title="Your Registration Number"/>

<!-- Third item: Branch -->


<item
android:id="@+id/menu_branch"
Name/Signature: Mukul Choudhari
Registration no: 22BCE10410

android:title="Your Branch"/>

<!-- Fourth item: Semester with sub-items for each subject -->
<item
android:id="@+id/menu_semester"
android:title="Semester">
<menu>
<item
android:id="@+id/menu_subject1"
android:title="Subject 1"/>
<item
android:id="@+id/menu_subject2"
android:title="Subject 2"/>
<item
android:id="@+id/menu_subject3"
android:title="Subject 3"/>
<!-- Add more subjects as needed -->
</menu>
</item>
</menu>

2. MainActivity.java, override the onCreateOptionsMenu and onOptionsItemSelected methods


to display the toast message when an item is selected.
// MainActivity.java
package com.example.menutoastapp;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, menu);
return true;
}

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_name:
Toast.makeText(this, "Your Name Selected", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_reg_no:
Toast.makeText(this, "Registration Number Selected",
Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_branch:
Toast.makeText(this, "Branch Selected", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_subject1:
Toast.makeText(this, "Subject 1 Selected", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_subject2:
Toast.makeText(this, "Subject 2 Selected", Toast.LENGTH_SHORT).show();
return true;
case R.id.menu_subject3:
Toast.makeText(this, "Subject 3 Selected", Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
DESCRIPTION: The application successfully displays a Menu Bar in the main activity with the
following items:
 Name: Displays a toast saying "Your Name Selected."
 Registration Number: Displays a toast saying "Registration Number Selected."
 Branch: Displays a toast saying "Branch Selected."
 Semester: Contains sub-items for different subjects, each displaying a corresponding toast (e.g.,
"Subject 1 Selected").

RESULT: The experiment resulted in a functional Menu Bar in the Android application. Each item and
sub-item displayed an appropriate toast message upon selection, confirming the successful implementation
of menu handling in Android.

OBSERVATION: 1. The Menu Bar was successfully displayed in the app, and each menu item
triggered its respective toast message.
2. Sub-items under the "Semester" menu were nested correctly and displayed specific toast
messages when selected.

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

3. The toast messages appeared briefly at the bottom of the screen, providing visual feedback to
the user on item selection.
CONCLUSION : The experiment demonstrates the creation of a dynamic Menu Bar in an
Android application and the implementation of toast messages to provide user feedback on menu
selections. This process illustrates the basics of handling menu item clicks in Android, essential
for creating interactive and responsive applications. The menu and toast feature adds to the user
experience by providing clear feedback on actions taken in the app.

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

Date: Title

Exp. No: 07 To create and implement a context menu in an Android application


that displays toast messages for selected menu items upon long-
clicking a TextView.

AIM:

To create and implement a Context menu for Car info that includes information
like color,price,fuel type,mileage,model etc..
PROCEDURE:

Design the Layout:

● Create a simple layout with a TextView which will represent a car and will trigger the
context menu when long-clicked.

Register for Context Menu:

● In the activity's Java code, register the TextView for a context menu by calling
registerForContextMenu().

Create the Context Menu:

● Override the onCreateContextMenu() method to add the menu options for car details like
model, price, fuel type, color, and mileage.
● Assign each option a unique ID.

Handle Menu Item Selection:

● Override the onContextItemSelected() method to capture the selection of the menu item
and display a toast message with the relevant car information based on the selected menu
option.

Test the Application:

● Build and run the app, and test that the context menu works as expected, showing the
appropriate toast messages when each menu item is selected.

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

CODE:

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

DESCRIPTION:

In this implementation, the app consists of a simple user interface with a single TextView
element that represents the car. The core of the app lies in the creation and handling of a context
menu which appears when the user long-clicks on the TextView. The context menu provides
several options to view details about the car, such as:

● Model
● Price
● Fuel Type
● Color
● Mileage

When the user selects one of these options, a Toast message is displayed with the respective
information for the selected car detail. This creates an interactive experience for the user,
allowing them to learn more about the car without navigating away from the current screen.

RESULT:

After implementing and running the app:

● A user will be able to long-click on the TextView that represents the car.
● The context menu will appear with the available options: Model, Price, Fuel Type,
Color, and Mileage.
● Upon selecting any of the menu items, a toast message will appear, displaying the
corresponding information.

OBSERVATION:

The context menu appears correctly when the TextView is long-clicked.The menu
options display as expected and are clear to the user.The toast messages provide
the expected information when a menu item is selected.The context menu works as
a quick and intuitive way to access additional details without navigating through
other UI elements.
CONCLUSION :

The implementation of the context menu for displaying car information was
successful. By using the context menu in combination with toast messages, we
were able to create an easy-to- use interface where users can quickly access car
details such as model, price, fuel type, color, and mileage. This functionality
Name/Signature: Mukul Choudhari
Registration no: 22BCE10410

enhances the user experience by providing immediate feedback through the toast
messages and simplifies the interface by using the context menu.

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

Date: 20th Nov 2024 Title

Exp. No: 08 Navigation using image and back button

AIM: To design and implement a simple mobile application with multiple pages, demonstrating
the concept of navigation between pages using a clickable image and a back button.

PROCEDURE: Procedure:
1. Set up the Development Environment:
o Create a new project and design the basic layout for the first page.
2. Design the First Page:
o Add a placeholder for the image on the first page.
o Set up an event listener for the image to trigger navigation to the second page when
clicked.
3. Design the Second Page:
o Add text views to display the name and registration number.
o Add a button to navigate back to the first page.
4. Implement Navigation Logic:
o Use appropriate navigation techniques (e.g., Intent in Android, NavigationController
in iOS) to switch between pages.
o Handle the back button press to return to the previous page.
5. Test and Debug:
o Run the app on a device or emulator to test the navigation functionality.
o Debug any issues and refine the user experience.

CODE:

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410

1. RESULT: Main Page:


o Contains a clickable image of the user.
2. Second Page:
o Displays the user's name and registration number.
o Includes a back button to return to the main page.
The navigation between these pages works as expected. Clicking the image on the main page
transitions to the second page, and clicking the back button returns to the main page.

DESCRIPTION:
The experiment involved the following steps:
1. Project Setup:
o A new mobile app project was created using a suitable development environment
(e.g., Android Studio, Xcode).
o The basic layout for both pages was designed.
2. Image Integration:
o The user's photo was added to the project resources.
o The image was displayed on the main page using an appropriate UI component (e.g.,
ImageView).
3. Navigation Implementation:
o An event listener was attached to the image to trigger navigation when clicked.
o An intent (Android) or navigation controller (iOS) was used to switch between the
Name/Signature: Mukul Choudhari
Registration no: 22BCE10410

two activities or view controllers.


o A back button was added to the second page to allow users to return to the main page.
4. Testing and Debugging:
o The app was tested on a device or emulator to ensure smooth navigation and correct
display of information.
o Any issues or bugs were identified and fixed.

OBSERVATION:
 Clicking the image on the first page successfully navigates to the second page.
 The second page displays the name and registration number.
 Clicking the back button returns to the first page.

CONCLUSION : This experiment demonstrated the implementation of multi-page navigation in


a mobile application. By understanding the concepts of activities, intents, and layout design, we
can create more complex and interactive user interfaces for mobile apps.

Name/Signature: Mukul Choudhari


Registration no: 22BCE10410
0

Date: 22th Nov 2024 Title

Exp. No: 09 Android application with four buttons: "Email," "VIT Bhopal Website,"
"Google MAP," and "My Camera,"

AIM: To create an Android application with four buttons: "Email," "VIT Bhopal Website,"
"Google MAP," and "My Camera," showcasing the use of explicit intents to navigate between
activities and open external apps.

PROCEDURE:
1. Set Up the Environment:
 Install Android Studio and set up a new Android project.
2. Design the Layout:
 Create four buttons in the main activity to handle the functionalities.
3. Handle Explicit Intents:
 Email: Navigate to a new activity with a form to send an email.
 VIT Bhopal Website: Open the website using an Intent with a browser URL.
 Google MAP: Open Google Maps using an Intent.
 My Camera: Launch the camera app using an Intent.
4. Test Functionality:
 Run the app on an emulator or a physical device to ensure all buttons and intents work as
expected.

CODE:

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Name: Mukul Choudhari


Registration no: 22BCE10410
0

OBSERVATION:
1. Clicking the "Email" button navigates to an email form, and the form sends an email
successfully.
2. Clicking the "VIT Bhopal Website" button opens the VIT Bhopal website in the default
browser.
3. Clicking the "Google MAP" button launches Google Maps centered on VIT Bhopal.
4. Clicking the "My Camera" button opens the device's camera app.

CONCLUSION : The experiment successfully demonstrates the use of explicit intents in


Android to navigate between activities and launch external apps like a browser, Google Maps,
and the camera application. This functionality is vital for building interactive and user-friendly
Android applications.

Name: Mukul Choudhari


Registration no: 22BCE10410
0
Date: 27th Nov 2024 Title

Exp. No: 10 Proximity Sensor

AIM: To develop an Android application that utilizes the proximity sensor to measure and display the
distance of an object from the sensor. The application will also provide tactile feedback (vibration) when
an object is in close proximity and display relevant data on the screen, including the sensor value, the
developer's name, and registration number.

1. PROCEDURE: Setup Development Environment: Install Android Studio and set up the necessary
SDK tools.
2. Create a New Project: Create a new Android project with an empty activity.
3. Configure Permissions: Add vibration permissions in the AndroidManifest.xml.
4. Setup UI:
o Use TextView to display sensor values and user details.
o Add a toast message when an object is close to the proximity sensor.
5. Access Proximity Sensor:
o Use the Android SensorManager to access the device’s proximity sensor.
o Implement a SensorEventListener to handle sensor value changes.
6. Implement Vibration:
o Trigger the vibration feedback using the Vibrator class when the sensor value indicates
close proximity.
7. Build and Run: Compile the application and test it on a physical Android device.

CODE

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Name: Mukul Choudhari


Registration no: 22BCE10410
0

OUTPUT : Name: Mukul Choudhari


Registration no: 22BCE10410
0

 OBSERVATION: The sensor value decreases as an object comes closer to the proximity sensor.
 The application effectively provides vibration feedback when an object is near.
 The toast message ensures real-time feedback for the user.
CONCLUSION : The application successfully utilizes the proximity sensor to measure the distance of
an object, display the sensor value, and provide tactile feedback when an object is close. This
demonstrates the integration of hardware sensors and user interface elements in Android development.

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Date: 11 Dec 2024 Title

Exp. No: 11 To implement and install the SQLite database in an Android


application collecting user details as the data.

AIM:
To implement and install the SQLite database in an Android application collecting user details as
the data.
1. Create a new empty file named dbcode.
2. Importing all the required libraries and bundles.
3. Create another java class for methods update, delete, insert,
View named as dbhelper.
4. Run the code.

PROCEDURE:
1.Create Database Helper Class (DatabaseHelper.java):

 Create a new Java class called DatabaseHelper that extends SQLiteOpenHelper.


 Define the SQL commands to insert, update, delete, and retrieve data.
2.Create Activity Layout (activity_main.xml):

-Design the UI layout that includes:


 EditText fields for collecting user data (name, regno, branch).
 Buttons for each CRUD operation (Insert, Update, Delete, View).
3.Write Logic in MainActivity.java:

 In MainActivity.java, instantiate the DatabaseHelper class.


 Implement the button click listeners for each operation (Insert, Update, Delete, View).
4.Run and Test the Application:

 Build and run the app on an Android emulator or physical device.


 Test each button (Insert, Update, Delete, View) and verify that the SQLite
database is correctly performing each operation.

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Code:

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Description:

This project involves the creation of an Android application that interacts with an SQLite
database to perform basic CRUD (Create, Read, Update, Delete) operations for managing user
details. The application collects the following user information:

 Name
 Registration Number
 Branch

The application provides the following features:

1. Insert: Allows the user to enter their name, registration number, and branch and save
them in the database.
2. Update: Allows the user to modify an existing user's data in the database.
3. Delete: Allows the user to delete a specific user from the database.
4. View: Displays all the users stored in the SQLite database.

Result:
Insert Operation:

 Upon entering user details (name, regno, branch) and clicking the Insert
button, the data was successfully inserted into the SQLite database.
 A Toast message saying "User Inserted" appeared to confirm the successful
insertion.
 After pressing the View button, the newly inserted user data was displayed
correctly in
 the TextView.

Update Operation:

 After entering new details (name, regno, branch) and pressing the Update button, the
data for the user with the hardcoded ID (ID = 1) was successfully updated.
 A Toast message saying "User Updated" appeared to confirm the successful update.
 Clicking the View button displayed the updated user data in the TextView.

Delete Operation:

 After pressing the Delete button, the user with the specified ID (hardcoded
ID = 1) was deleted from the database.
 A Toast message saying "User Deleted" appeared to confirm the successful
deletion.
Name: Mukul Choudhari
Registration no: 22BCE10410
0

 After clicking the View button, the deleted user data no longer appeared in the
Text View, confirming the deletion.

View Operation:

 Upon clicking the View button, all the stored user data was retrieved and
displayed in the Text View.
 If the database was empty, the message "No data available" was displayed.
 When users were available, their data (ID, Name, Reg No, Branch) was
displayed correctly, formatted as expected.

Observation:

Insert Operation:

 The insert operation worked as expected, successfully adding user data to the
SQLite database.
 The app correctly displayed a confirmation Toast message ("User Inserted") and
updated the View button's display to show the inserted data.

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Update Operation:

 The update operation correctly modified the existing user's data in the database.
 The app updated the user information in the database, and after clicking View,
the updated data was shown as expected.
 The "User Updated" Toast message appeared after the operation was complete.

Delete Operation:

 The delete operation successfully removed the user with the specified ID from
the database.
 After clicking View, the deleted user no longer appeared in the list, indicating the
deletion was successful.
 The confirmation Toast message ("User Deleted") was displayed as expected.

View Operation:

 The View button accurately displayed all user data stored in the SQLite database.
 When the database was empty, the message "No data available" appeared,
ensuring the user was informed about the empty database state.
 The Text View displayed user data in the correct format, confirming
the correct functioning of the SELECT SQL query.

Conclusion:

This project demonstrates how to integrate an SQLite database with an Android application to
manage user details. By implementing basic CRUD operations (Insert, Update, Delete, View),
we learned the following:

1. SQLite Database Operations: SQLite provides a lightweight, persistent storage solution


for Android apps. We can perform various database operations directly from the app
using SQLite Open Helper and SQL commands (INSERT, UPDATE, DELETE, SELECT).
2. Android Database Handling: Understanding how to interact with SQLite databases in
Android and perform operations like inserting, updating, and deleting records is crucial
for any data-driven Android application.
3. App Development: This project provided hands-on experience with Android
development, database management, and user interaction.

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Name: Mukul Choudhari


Registration no: 22BCE10410
0

Name: Mukul Choudhari

You might also like