Index: SR No. Name of The Program
Index: SR No. Name of The Program
Windows
macOS
Linux
If everything is set up correctly, Java is now installed and ready to use on your system.
Experiment 2: System Requirement for
Android Studio
Windows
macOS
Linux
Locate the (.exe file) in your Downloads folder in pc and then double click on the file to
begin the installation of Android Studio.
For Windows:
1. Run the installer (.exe file) and click on “Next” to precede the installation.
2. Select components:
o In the setup wizard, select components to install. By default, Android Studio,
the Android SDK, the Android Virtual Device (AVD), and the Android Emulator
are
selected.
3. Choose SDK installation location:
o Choose where to install the SDK and Android Studio (you can use the
default location).
4. Install:
o Click “Next” to complete the installation and wait for the process to finish.
For macOS:
For Linux:
After the SDK components are downloaded you can see the Android Studio Home page. You
first have to create a Virtual Device to for your New project or app to Run.
o So now on Android Studio Home page you can click on the More Actions and then click
on the Virtual Device Manager
o Now in the Virtual device manager you have to create a virtual device so click on
“Create a Virtual Device”.
o After clicking on it you have to select the Hardware and which device (Phone, tablet,
Wear OS etc.) You like and then if you has selected Phone and selected the Phone
model also, then click on “Next”.
o After this you have to select an System Image, You can go for the Recommended
System Image and as their name is showing below you can chose recommended (API
35) and then click on it to begin the downloading after the download is complete then
click on finish (if already downloaded then click on Finish),
o You can also change your AVD name if you want to then, click on finish. Your
Virtual Device has been created.
o Go to File > New Project and follow the steps to create a simple “Hello
World” app.
2. Run the app:
o Click the Run button, select your emulator or physical device (if connected),
and ensure that the app runs successfully.
Step 7: (Optional) Install Device Drivers for Physical Testing (Windows only)
1. Click "Create Virtual Device": In the AVD Manager window, click the
"Create Virtual Device" button.
2. Choose Hardware:
o You'll see a list of available device profiles (e.g., Pixel 4, Nexus 5X,
Tablet). Choose the device profile that matches the type of device you
want to emulate. Click "Next" after selecting the device.
1. AVD Configuration:
o Here, you can customize the AVD's settings, such as the device name,
orientation, and startup size (portrait or landscape).
o You can also manage advanced settings like the amount of RAM, VM heap, and
internal storage.
o If you want to enable Hardware Accelerated Performance, ensure
that "Emulated Performance" is set to "Hardware - GLES 2.0".
3. Click "Finish": Once you're satisfied with the configuration, click "Finish" to create the
AVD.
1. Run Applications:
o You can now run your Android applications on this virtual device
directly from Android Studio.
o Select the virtual device from the "Select Deployment Target"
dialog when you run your app.
Experiment 5: Creating a new project in
Android Studio
Creating a new Android project is straightforward using Android Studio, the official Integrated
Development Environment (IDE) for Android development. Here's a step-by-step guide:
If you haven't already installed Android Studio, download it from the [official Android Studio
website](https://developer.android.com/studio) and follow the installation instructions for
your operating system.
Open Android Studio: After installation, launch Android Studio. The first time you open it, you
may need to complete some initial setup, such as installing necessary components and setting
up an Android SDK.
o Android Studio offers various templates to start your project, such as "Empty Activity",
"Basic Activity," "Bottom Navigation Activity," etc.
o For a simple starting point, select "Empty Activity" and click "Next".
Choose the programming language you want to use: as recommended “Java” or “Kotlin”.
3. Minimum SDK:
o Select the Minimum API level your app will support. This determines the lowest version
of Android that your app can run on.
o A lower API level means your app will run on more devices, but you may have to do
more work to support older Android versions. Click "Finish" to create the project .
Connect an Android device to your computer via USB, or set up an Android Emulator within
Android Studio to run your app virtually.
Click the “Run” ▷ button (green triangle) in the toolbar, or press Shift + F10.Choose your
connected device or emulator from the list.
Android Studio will build your project, install the app on the selected device or emulator, and
launch it.
Add More Activities: You can add more activities, fragments, and features as your app grows.
Test Your App: Use the built-in testing tools in Android Studio to ensure your app works as
expected across different devices and scenarios.
Deploy: When your app is ready, you can prepare it for release and upload it to the Google Play
Store
Experiment 6: To change icon image of
Android application
To change the app icon in an Android app using a vector image, you can do this through
Android Studio’s Image Asset tool, which handles vector images (SVG or XML format). This will
automatically generate the necessary draw able files from the vector image and place them in
the right locations.
1. Icon Type: Select Launcher Icons (Adaptive and Legacy) from the dropdown menu.
2. Asset Type:
o Select Clip Art if you want to use Android Studio's built-in vector assets.
o If you have your own vector image (SVG or XML), select Local file (SVG, PSD).
3. Path:
o For custom vector images, click on Browse and select the SVG/XML vector
image from your file system.
1. Background Layer:
o Set up the background color or choose none if you want a
transparent background for your icon.
2. Foreground Layer:
o Customize the foreground scale or position of the vector image if needed
1. Preview: In the Image Asset tool, preview how the icon will look in different sizes (MDPI,
HDPI, etc.).
2. Destination Directory: Ensure the destination is set to the mipmap directory (this is
where app launcher icons are stored).
3. Click Next and then Finish to generate the icons for all densities.
Step 5: Build and Run the App
o Using an Emulator:
o Go to Tools > AVD Manager.
o If you don’t have an emulator, click Create Virtual Device and follow the steps
to configure it (choose a device type, system image, etc.).
o Once set up, click the Play button (▶) to start the emulator.
o Using a Physical Device:
o Connect your Android device to your computer via USB.
o Enable USB Debugging on your device:
Go to Settings > About Phone > tap on Build Number 7 times to enable
Developer Options.
Go back to Settings > Developer Options and enable USB Debugging.
o In the top toolbar, locate the Run configuration dropdown (next to the green
Play button).
o Ensure that your app module is selected (e.g., app).
o While your app is running, look at the Run window at the bottom of Android Studio.
o Click the Stop button (■) in the toolbar of the Run window. This will terminate the
app on the emulator or device.
Emulator:
Physical Device:
While the application is running, you can view logs to help with debugging:
o Open the Logcat window by going to View > Tool Windows > Logcat.
o You can filter logs based on tags, levels, or search specific messages.
Experiment 8: To design an Application using
Constraint Layout
A ConstraintLayout is a ViewGroup that allows you to position and size widgets in a flexible way.
ConstraintLayout allows you to create large and complex layouts with a flat view hierarchy (no
nested view groups).
1. After creating your project, navigate to the res/layout folder in the project view.
2. Open the activity_main.xml file. By default, you’ll have a ConstraintLayout if
you selected an empty activity. If not, change the root layout to ConstraintLayout.
1. <androidx.constraintlayout.widget.ConstraintLayout
2. xmlns:android="http://schemas.android.com/apk/res/android"
3. xmlns:app="http://schemas.android.com/apk/res-auto"
4. android:layout_width="match_parent"
5. android:layout_height="match_parent">
6.
7. <!-- Add widgets here -->
8.
9. </androidx.constraintlayout.widget.ConstraintLayout>
Step 3: Add a Button
1. <Button
2. android:id="@+id/button"
3. android:layout_width="wrap_content"
4. android:layout_height="wrap_content"
5. android:text="Click Me"
6. app:layout_constraintTop_toTopOf="parent"
7. app:layout_constraintStart_toStartOf="parent"/>
2. This code places the button at the top-left corner of the parent layout.
1. <TextView android:id="@+id/textView"
2. android:layout_width="wrap_content"
3. android:layout_height="wrap_content" android:text="Hello World!"
4. app:layout_constraintTop_toBottomOf="@id/button"
5. app:layout_constraintStart_toStartOf="parent" />
1. Open the Design tab at the bottom of your layout XML file.
2. Drag and drop a new widget (such as a Button, TextView, or ImageView) from the
Palette onto the ConstraintLayout.
3. Use the Constraint Handles (circular dots on the widget) to create constraints to other
widgets or the parent layout.
o Drag from one handle to another widget or edge to form a constraint.
1. If you want to centre a widget horizontally or vertically within its parent, you can use
bias or match constraints.
1. <Button android:id="@+id/centerButton"
2. android:layout_width="wrap_content"
3. android:layout_height="wrap_content"
4. android:layout_width= "148dp"
5. android:layout_height="73d"
6. android:text="Centered"
7. app:layout_constraintTop_toTopOf="parent"
8. app:layout_constraintBottom_toBottomOf="parent"
9. app:layout_constraintStart_toStartOf="parent"
10. app:layout_constraintEnd_toEndOf="parent"
11. app:layout_constraintEnd_toEndOf="parent"
12. app:layout_constraintStart_toStartOf="parent"
13. app:layout_constraintEnd_toEndOf="parent"
14. app:layout_constraintHorizontal_bias="0.5"
15. app:layout_constraintVertical_bias="0.5"/>
1. Once your layout is ready, click Run (green play button) to compile and deploy your app
onto a virtual device or physical Android device.
2. You will see the app with your designed UI using ConstraintLayout.
Experiment 9: To design an Application using
Linear Layout
LinearLayout is the most basic layout in android studio, that aligns all the children
sequentially either in a horizontal manner or a vertical manner by specifying
the android:orientation attribute. If one applies android:orientation=”vertical” then
elements will be arranged one after another in a vertical manner and If you
apply android:orientation=”horizontal” then elements will be arranged one after another in a
horizontal manner.
1. After creating your project, navigate to the res/layout folder in the project view.
2. Open the activity_main.xml file. By default, you’ll have a ConstraintLayout if
you selected an empty activity. If not, change the root layout to ConstraintLayout.
1. <LinearLayout
2. xmlns:android="http://schemas.android.com/apk/res/android"
3. android:layout_width="match_parent"
4. android:layout_height="match_parent"
5. android:orientation="vertical"
6.
7. < !-- Add your widgets here -->
8.
9. </LinearLayout>
1. <Button
2. android:layout_width="wrap_content"
3. android:layout_height="wrap_content"
4. android:text="Click Me"/>
Add a ImageView right after the Button. In a vertical LinearLayout, this will be positioned
below the button.
1. <ImageView
2. android:id="@+id/imageView"
3. android:layout_width="148dp"
4. android:layout_height="131dp"
5. android:layout_marginStart="10dp"
6. android:layout_marginTop="180dp"
7. android:layout_marginEnd="10dp"
8. app:srcCompat="@android:drawable/btn_star_big_on" />
o The widgets will be stacked one below the other in vertical orientation.
o If horizontal orientation is used, they will appear side by side.
o You can add Margin for the Image from(Start,End,Top,Bottom)etc.
Use the android:gravity attribute to align the content inside the views (e.g., center-align
the text within a TextView):
1. <TextView
2. android:layout_width="wrap_content"
3. android:layout_height="wrap_content"
4. android:gravity="center"
5. android:text="Centered Text" />
Step 7: For Horizontal Orientation and Use Weight for Flexible Spacing
1. Once the design is complete, click Run (green play button) to deploy the app to an
Android Virtual Device (AVD) or a physical device.
2. You should now see your designed UI, with widgets laid out in a LinearLayout.
3. You will see your designed layout with the LinearLayout in action.
Experiment 10: To design an Application
using Relative Layout
A Relative Layout is a ViewGroup in Android that allows you to position and size child views in
relation to each other or to the parent container. Unlike other layouts such as LinearLayout,
which arranges elements sequentially (either vertically or horizontally), RelativeLayout lets you
position UI elements based on their relative positioning (above, below, to the left of, etc.) with
respect to other views or the container.
1. Positioning Views Relative to Each Other: Views can be aligned or positioned relative to
other views (e.g., above, below, to the left, or to the right).
2. Positioning Views Relative to the Parent: Views can be aligned to the parent container's
edges (e.g., align with the parent’s top, bottom, left, or right side).
3. Z-Index Control: Child views can overlap each other, and you can control the layering
by using XML attributes.
1. <RelativeLayout
2. xmlns:android="http://schemas.android.com/apk/res/android"
3. android:layout_width="match_parent"
4. android:layout_height="match_parent">
6. </RelativeLayout>
Step 3: Add UI Elements and Define Relative Positioning
For example:
1. <RelativeLayout
2. android:layout_width="match_parent"
3. android:layout_height="match_parent">
4.
5. <!-- A TextView aligned at the top of the parent -->
6.
7. <TextView android:id="@+id/textView1"
8. android:layout_width="wrap_content"
9. android:layout_height="wrap_content"
10. android:text="Welcome"
11. android:layout_alignParentTop="true"
12. android:layout_centerHorizontal="true"/>
13.
14. <!-- A Button placed below the TextView -->
15.
16. <Button android:id="@+id/button1"
17. android:layout_width="wrap_content"
18. android:layout_height="wrap_content"
19. android:text="Click Me"
20. android:layout_below="@id/textView1"
21. android:layout_centerHorizontal="true"
22. android:layout_marginTop="20dp"/>
23. </RelativeLayout>
Step 4: Preview and Adjust Layout
After adding elements, use the Design tab in Android Studio to visually adjust the layout
if needed.
Check how views are positioned and make any adjustments in the XML if necessary.
Adjust margins, padding, and alignment as needed to fine-tune the layout for your
app's design. Use additional attributes like layout_margin, layout_centerInParent,
layout_alignParentBottom, etc.
1. <RelativeLayout
2. xmlns:android="http://schemas.android.com/apk/res/android"
3. android:layout_width="match_parent"
4. android:layout_height="match_parent">
32. </RelativeLayout>
Running an Android Java app on a physical device (your phone) requires a few simple steps to
set up your development environment and prepare your phone for testing. This can be done
with the help of USB debugging and Wireless Debugging. Below are the detailed steps:
Step 1: Prerequisites
o Android Studio: Ensure that Android Studio is installed on your computer. If you
haven't installed it yet.
o USB Cable: You will need a USB cable to connect your phone to your computer.
o Android Device: Any Android phone that you want to use for testing your app.
o Android device must support android 11+ to pair wireless or wi-fi debugging.
Before you can run your app on a physical device, you need to enable Developer Options and
USB Debugging on your phone.
You may need to enter your device's PIN or password to enable Developer Mode.
Now that your phone is ready, it’s time to set up Android Studio.
o In Android Studio, click on the device selector dropdown at the top of the screen
(next to the Run/Debug buttons).
It may take a few seconds for Android Studio to detect your device.
o Once your phone is detected, it will show up in the list of available devices. Select
your phone from the list.
Android Studio will now compile the project and install the app on your device.
You can also run the app on your device wirelessly if both the computer and phone are on the
same Wi-Fi network:
To set up the wireless connection for the first time, you must connect your phone to your
computer via USB.
Now that your device is connected via USB, you can enable Wireless Debugging on your device.
o Click on the device selector dropdown at the top of the screen (next to the
Run/Debug buttons).
o Click on Pair Devices using wi-fi.
o Select pair via QR code or Pairing code.
Once the pairing is successful, you can now disconnect the USB cable. The device will remain
connected over Wi-Fi for debugging purposes.
o In Android Studio, ensure your physical device is selected in the device dropdown
(you should see your device’s name listed under Wi-Fi debugging).
o Click the green "Run" button or press Shift + F10 to build and run the app.
The app will now be installed and launched on your phone, all over Wi-
Fi, without the need for a USB connection.
Experiment 12: To illustrate various android
activities.
An activity in Android is a specific combination of XML files and JAVA files. It is basically a
container that contains the design as well as coding stuff. XML files provide the design of the
screen and JAVA files deal with all coding stuff like handles, what is happening, design files, etc.
In Android development, activities are fundamental components that represent a single
screen with a user interface in an Android app. Each activity is like a page of an app where users
interact with different elements like buttons, text fields, etc. Activities manage the app's UI and
handle user interactions.
These activities are different templates or predefined setups for Android development in
Android Studio. When starting a new project, Android Studio offers these templates to help
developers quickly create common types of activities. Here’s an explanation of each one, its
uses, importance, and key functionalities:
1. No Activity
o Use: As the name suggests, it’s an empty project without any predefined layout or
components. It’s useful when you want complete control over the setup and wish
to create everything from scratch.
o Importance: This is the most basic option, suitable for experienced developers
who prefer starting with a clean slate.
o Functionalities: You will need to manually create the MainActivity and design the
user interface, adding required components like buttons, text fields, etc.
2. Basic Activity
o Use: It creates an app with a single activity and a floating action button (FAB). It
also includes support for the Android AppBar (Toolbar) at the top.
o Importance: This is a good starting point for simple apps and serves as a foundation
for adding more functionalities.
o Functionalities:
o Use: This template includes a layout with a bottom navigation bar, which is
commonly used in modern apps to navigate between three or more top-
level destinations.
o Importance: Ideal for apps that need to switch between different fragments or
activities, like a social media app where you navigate between Home, Search, and
Profile screens.
o Functionalities:
4. Empty Activity
o Use: Similar to the "No Activity" option, but it provides a basic activity class and
layout file. This is useful when you want to start simple and add more complexity as
needed.
o Importance: It gives a bare-bones structure that still includes an Activity class
and XML layout, useful for small-scale apps or demos.
o Functionalities:
5. Full-Screen Activity
o Use: This activity provides a layout that takes up the entire screen, hiding the status
and navigation bars. It’s used for immersive apps, like media players or games.
o Use: This template integrates Google Maps into your app, allowing users to interact
with maps, view their location, and more.
o Importance: It’s essential for apps that involve location-based services, like
navigation, tracking, or local business searches.
o Functionalities:
7. Login Activity
o Use: It provides a pre-built login screen with user input fields (username, password)
and buttons (sign-in, sign-up).
o Importance: Many apps need authentication, so this template is valuable for
adding secure login functionality quickly.
o Functionalities:
8. Scrolling Activity
o Use: This template creates an activity with a scrollable layout. It is helpful for apps
that need to display a long list of content or a page that exceeds the screen height.
o Importance: Scrolling activity is crucial for content-heavy apps like blogs, news apps,
or documentation.
o Functionalities:
o Use: It provides a layout with tabs at the top, allowing users to switch between
different views or fragments.
o Importance: It is commonly used in apps that need to categorize content into
different sections, like a messaging app with "Chats," "Calls," and "Contacts" tabs.
o Functionalities:
o Use: This template allows you to write part of your app in C++ for high-
performance tasks. It is used in applications where native performance is critical,
such as games, multimedia processing, or apps with heavy computational tasks.
o Importance: Useful when you need to integrate native code for better performance
or when interacting with pre-existing C++ libraries.
o Functionalities:
A basic activity that interacts with C++ code via the Android NDK
(Native Development Kit).
C++ source files (.cpp) for writing native code.
Pre-configured CMake build script for compiling C++ code.
Experiment 13: To design an android
application to show your own name.
To make an application to print own name on an android application, we use Empty Views
Activity. Here we can also customize the appearance of the text by modifying other attributes
such as android:textSize, android:textColor, android:textStyle, etc.
These are the some steps below to show your name on your application in Android
Studio:
You can also change the background color and font color of the android:text