practical-file-for-android-programming
practical-file-for-android-programming
PRACTICAL FILE OF
ANDROID PROGRAMMING
SUBECT CODE :- UGCA 1944
INDEX
S No. Practical Name Page No. Remarks
Page 2
Practical – 1
Installation of JAVA, android Framework.
Android Studio, Java JDK & SDK is part of Android Development for building Android Apps. In
this post, we’re going to learn “How to install & Setup Android Studio Java JDK & SDK“.
We’ll also see, how to download the Android Studio and Java JDK, as well as the SDK (Software
Development Kit) setup.
The Java Development Kit (JDK), officially called “Java SE”, is needed for writing Java programs.
The JDK is freely available from Sun Micro-systems, now it is part of Oracle. check
it– http://www.oracle.com/technetwork/java/javase/overview/index.html.
Page 3
Click the Search button and Type “cmd” ⇒ Choose “Command Prompt”, or Right-
click “Start” button ⇒ run ⇒ enter “cmd”.
the following commands to verify that JDK/JRE is properly installed and display their version.
Note: You can copy the SDK from your friends or any other computer with the same OS because
the download size is 3GB of zip data and expand to 5 GB of disk data.
Page 4
4. Click Apply. Android Studio starts installing your selected packages. After completing the
installation, the Status of the installed packages and tools changes from Not
Installed to Installed.
5. Click OK.
Page 5
Practical -2
Android SDK is a collection of libraries and Software Development tools that are essential for
Developing Android Applications. Whenever Google releases a new version or update of
Android Software, a corresponding SDK also releases with it. In the updated or new version of
SDK, some more features are included which are not present in the previous version. Android
SDK consists of some tools which are very essential for the development of Android
Application. These tools provide a smooth flow of the development process from developing
and debugging. Android SDK is compatible with all operating systems such as Windows, Linux,
macOS, etc.
Page 6
Android SDK Components play a major role in the Development of Android applications. Below
are the important components:
1. Android SDK Tools:- Android SDK tool is an important component of Android SDK. It
consists of a complete set of development and debugging tools. Below are the SDK developer
tools:
Android SDK Build tool.
Android Emulator.
Android SDK Platform-tools.
Android SDK Tools.
These are shown below :
2. Android SDK Build-Tools:- Android SDK build tools are used for building actual binaries
of Android App. The main functions of Android SDK Build tools are built, debug, run and test
Android applications. The latest version of the Android SDK Build tool is 30.0.3. While
downloading or updating Android in our System, one must ensure that its latest version is
download in SDK Components.
Page 7
Thus, it simply means that without needing any physical device Android SDK component
“Android Emulator” provides a virtual device on the System where we run our Application. The
emulator’s come with the configuration for Various android phones, tablets, Wear OS, and
Android TV devices.
4. Android SDK Platform-tools:- Android SDK Platform-tools is helpful when we are working
on Project and they will show the error messages at the same time. It is specifically used for
testing. It includes:
Android Debug Bridge (ADB), is a command-line tool that helps to communicate with the
device. It allows us to perform an action such as Installing App and Debugging App etc.
Fastboot allows you to flash a device with a new system image.
Systrace tools help to collect and inspect timing information. It is very crucial for App
Debugging.
5. Android SDK Tools:- Android SDK tool is a component of SDK tool. It consists of a set of
tools which and other Utilities which are crucial for the development of Android Application. It
contains the complete set of Debugging and Development tools for android.
6. SDK Platforms:- For Each Android Software, one SDK platform is available as shown
below:
7. SDK Update Sites:-In SDK Update Sites, some sites are embedded in it which will check for
Android SDK Updates Tools. In this, one must ensure we don’t unclick the button below because
these are checked by default which will check for updates if we will unclick it then it doesn’t
check updates for those.
Page 8
Page 9
Practical -3
Programs based on the overriding, constructor, classes in java.
Overriding in JAVA:-
class Animal {
public void move() {
System.out.println("Animals can move");
}
}
class Dog extends Animal {
public void move() {
System.out.println("Dogs can walk and run");
}
}
public class TestDog {
public static void main(String args[]) {
Animal a = new Animal(); // Animal reference and object
Animal b = new Dog(); // Animal reference but Dog object
a.move(); // runs the method in Animal class
b.move(); // runs the method in Dog class
}
}
Output:
Animals can move
Dogs can walk and run
Constructor in JAVA :
class Main {
Page 10
Output:
Constructor Called:
The name is Programiz
Page 11
Practical-4
Program based on static keyword in JAVA.
The static keyword in Java is used for memory management mainly. We can apply static
keyword with variables, methods, blocks and nested classes. The static keyword belongs to the
class than an instance of the class.
The static can be:
Variable (also known as a class variable)
Method (also known as a class method)
Block
Nested class
Page 12
Practical-5
Directory Structure of an Android project.
Android Directory Structure :-Generally we have three kinds of android projects such as:
Android Projects:- An Android project is the container for our application's source code,
resource files, and files such as the Ant build and Android Manifest file. An application
project is the main type of project and the contents are eventually built into an .apk file
that you install on a device.
Test Projects:- These projects contain code to test our application projects and are built into
applications that run on a device.
Library Projects:- These projects contain shareable Android source code and resources that we
can reference in Android projects. This is useful when we have common code that we want to
reuse. Library projects cannot be installed onto a device, however, they are pulled into the .apk file
at build time.
The main objective of an android project is to build an .apk file from it. And for this when we start
with an android project then some directories creates by default and some needs few customization
to enhance android applications. So let’s understand the directory structure in android project to
develop an android application.
/src – This is the most common folder in any android project. It contains our java source code for
android application. Under this folder we can see our java source files in which we write logic for
android applications.
Page 13
/gen – In most IDE(such as Eclipse) this folder is created by IDE for configuration purpose. Under
this folder we can find two java files such as BuildConfig.java and R.java. Both files are auto
generated by IDE which helps android project to work smoothly.
/Android(version name) – Under this folder we can see some android.jar file which relates to
android sdk platform. We should not modify this file for smooth functioning of our project.
/assets – By default this folder is empty, but we can store raw asset files such as music file,data
file etc in this folder. The files retains its original name and structure when compiled into
an .apk file.
/res – This folder contains lots of required sub folders for the project. Let’s understand these
folders one by one.
a) /drawable – Under this folder we store images(PNG,JPEG,GIF) for our project. Generally this
folder comes with five types of sub folders which ensures rendering of images on mobile devices
according to its screen resolution. There are five sub folders with different names such as:
drawable-hdpi,drawable-ldpi,drawable-mdpi,drawable-xhdpi,drawable-xxhdpi (where dpi refers
to dot per inch). Normally Google prefers .PNG format for images.
b) /layout – Under this folder we store UI layouts file for our android project, which is written
in xml format. we can store as many activity file under this folder. In other words this folder relates
to our application UI layouts.
d) /values – In this folder we place predefined application values in the form of XML files that
define the variable names and their value that will be later referenced in our java source code. In
simple words, it holds all our constant values for our application in one place. In this way we can
customize our applications at one place as per our requirements. Within this folder we can find
three xml files such as:
i) dimens.xml: This XML file defines the dimension values such as font sizes and standard heights
for our UI.
ii) strings.xml: In this file we define text strings which is used in the application. for example: if
we wish to change the title of an application, then we can simply change in this file instead of
doing any hard coding in application.
Page 14
iii) styles.xml: This XML file defines styles which is used in the application. Generally we apply
these styles to our UI elements. With the help of style we can separate the look of our application
from the layout and functionality.
/project.properties: This file contains project settings, such as the build target. We can edit
project properties in eclipse(IDE).
Practical -6
Application based on text box and button.
Creating a Button
For creating a button we can use Button tag
Just go inside the layout and type <Button
You will get a dropdown now press enter. Now you can set the width and height for you button.
You see the xml code for a button below.
<Button
android:id="@+id/button"
Page 15
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a button" />
android:id=”@+id/button”: This is the id for your button after @+id/ i.e. here the id for your
button is “button” (without quotes). This id will be used to handle the button in java
coding. Whenever we put @+id in android:id tag of any view a respective hex value is stored
in a variable named with the id you have given here in R.java file. Now these things are done
automatically so you do not need to bother much about this. Basically what you need to know is
this is the id that will be used for handling this button.
Now we will create an Edit Text. For creating Edit Text we have the tag <EditText
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
So the code for the final layout that we have created yet is.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a button" />
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Page 16
</LinearLayout>
Now if you will switch to the design view you will see something like this:-
Page 17
Practical -7
Application based on Radio Button.
RadioButton is a two states button which is either checked or unchecked. If a single radio button
is unchecked, we can click it to make checked radio button. Once a radio button is checked, it
cannot be marked as unchecked by user. RadioButton is generally used with RadioGroup.
RadioGroup contains several radio buttons, marking one radio button as checked makes all other
radio buttons as unchecked.
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="center_horizontal"
Page 18
android:textSize="22dp"
android:text="Single Radio Buttons" />
Page 19
android:layout_marginTop="30dp"
android:gravity="center_horizontal"
android:textSize="22dp"
android:text="Radio button inside RadioGroup" />
Page 20
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Selected"
android:id="@+id/button"
android:onClick="onclickbuttonMethod"
android:layout_gravity="center_horizontal" />
</LinearLayout>
Output:
Page 21
Practical-8
Application based on Intents and Intents Filters.
An Intent is a messaging object you can use to request an action from another app component.
Although intents facilitate communication between components in several ways, there are three
fundamental use cases:
Starting an activity
An Activity represents a single screen in an app. You can start a new instance of an Activity by
passing an Intent to startActivity(). The Intent describes the activity to start and carries any
necessary data.
If you want to receive a result from the activity when it finishes, call startActivityForResult(). Your
activity receives the result as a separate Intent object in your activity's onActivityResult() callback.
For more information, see the Activities guide.
Starting a service
A Service is a component that performs operations in the background without a user interface.
With Android 5.0 (API level 21) and later, you can start a service with JobScheduler. For more
information about JobScheduler, see its API-reference documentation.
For versions earlier than Android 5.0 (API level 21), you can start a service by using methods of
the Service class. You can start a service to perform a one-time operation (such as downloading a
file) by passing an Intent to startService(). The Intent describes the service to start and carries any
necessary data.
If the service is designed with a client-server interface, you can bind to the service from another
component by passing an Intent to bindService(). For more information, see the Services guide.
Delivering a broadcast
Page 22
A broadcast is a message that any app can receive. The system delivers various broadcasts for
system events, such as when the system boots up or the device starts charging. You can deliver a
broadcast to other apps by passing an Intent to sendBroadcast() or sendOrderedBroadcast().
The rest of this page explains how intents work and how to use them. For related information,
see Interacting with Other Apps and Sharing Content.
Explicit intents specify which application will satisfy the intent, by supplying either the target
app's package name or a fully-qualified component class name. You'll typically use an explicit
intent to start a component in your own app, because you know the class name of the activity
or service you want to start. For example, you might start a new activity within your app in
response to a user action, or start a service to download a file in the background.
Implicit intents do not name a specific component, but instead declare a general action to
perform, which allows a component from another app to handle it. For example, if you want
to show the user a location on a map, you can use an implicit intent to request that another
capable app show a specified location on a map.
Example filters : To demonstrate some of the intent filter behaviors, here is an example
from the manifest file of a social-sharing app:
Page 23
<data android:mimeType="video/*"/>
</intent-filter>
</activity>
The first activity, MainActivity, is the app's main entry point—the activity that opens when the
user initially launches the app with the launcher icon:
The ACTION_MAIN action indicates this is the main entry point and does not expect any intent
data.
The CATEGORY_LAUNCHER category indicates that this activity's icon should be placed in
the system's app launcher. If the <activity> element does not specify an icon with icon, then the
system uses the icon from the <application> element.
Practical -9
Application based on Activities and Services.
Activity:- An activity is a single, focused thing that the user can do. It is the foreground task that
is right in front of the user. Almost all activities interact with the user, so the Activity class creates
a window for you to place your UI by loading a UI layout.
How to Interact with User:- The way an Activity interacts with a user is by responding to events.
The UI elements in your layout are often bonded to the Activity through functions or methods. For
example, your UI has a TextView to show some static text and you want to change it when the
user presses a button. For this to work your Button must bind to a function in your activity class
and it will invoke that function every time it is pressed. The function will set the new text for the
TextView by interacting with the reference of the instanced TextView.
When to Use Activity:- You will likely be using Activities if your app depends on user inputs.
The activity displays the UI and handles any user inputs, which means your app likely have a few
activities. A simple rule to go by is that if UI is involved then you want to use an Activity. If UI is
not necessary then a Service might be better for your need.
Page 24
when the user is not interacting with your app. It is important to note that foreground services must
display a status bar icon.
Background:- A background service performs an operation that is not directly noticeable by the
user. For example, a service that compacts its storage or updates a database.
Bound:- A service is bound when an application component binds to it through the bindService()
function. Bound service offers a client-server interface that allows an application component to
interact with the service, send requests, receive requests, and even do so with interprocess
communication (IPC).
Unlike other types of services, a bound service runs as long as another application service is bound
to it. For example, multiple components can bind to the service at once, but when all the
components unbind, the service is destroyed.
Persistent Service:- In addition, you can specify if a service is persistent or not. If a service is
persistent (Sticky), then if the Android system at any point kills the service’s process, it will mark
the service for restart as soon as resources are available. If the service is not persistent (Non-sticky),
then once the service’s process is killed while running, it will not be marked for restart. In order
to define whether a service is sticky or not, you must override the “onStartCommand” function to
return the flag for Sticky or Non-sticky.
When to Use Service:- You will likely use a service when you want to do something that does not
involve UI and needs it to run whether your app is running or not. For example, if you want to play
audio a service would be a choice because the audio will still play when the user opens another
app.
Page 25
There are two simple ways for you to use an Activity and Service together. One way is to create a
bound service and bind a component in your activity to the service acting as a communication
channel. Another way is to use the Android Broadcast System, which sends out a broadcast intent
system-wide. For this to work, you will need to have your own set of actions in your app, which
only your app will understand. In your activity class, you will register a broadcast receiver that
will listen for any of the actions pertaining to your app. Since an intent can carry data, you can
communicate data back and forth between an Activity and Service through this method.
Practical -10
Application based on Action Bar.
In Android applications, ActionBar is the element present at the top of the activity screen. It is a
salient feature of a mobile application that has a consistent presence over all its activities. It
provides a visual structure to the app and contains some of the frequently used elements for the
users. Android ActionBar was launched by Google in 2013 with the release of Android 3.0(API
11). Before that, the name of this top most visual element was AppBar. AppBar contains only the
name of the application or current activity. It was not very much useful for the users and developers
also have negligible option to customize it.
Google announced a support library along with the introduction of ActionBar. This library is a
part of AppCompat and its purpose is to provide backward compatibility for older versions of
Android and to support tabbed interfaces. Components included in the ActionBar are:
App Icon: Display the branding logo/icon of the application.
View Controls: Section that displays the name of the application or current activity.
Developers can also include spinner or tabbed navigation for switching between views.
Action Button: Contains some important actions/elements of the app that may be required
to the users frequently.
Action Overflow: Include other actions that will be displayed as a menu.
Designing a Custom ActionBar:- The following example demonstrates the steps involved in
creating a custom ActionBar for the MainActivity of an application. All important aspects of visual
elements like icon, title, subtitle, action buttons, and overflow menu will be covered.
Page 26
Default ActionBar:- As mentioned earlier, every android app contains an ActionBar by default.
This pre-included ActionBar display title for the current activity that is managed by
the AncdroidManifest.xml file. The string value of the application’s title is provided
by @string/app_name resource present under the application nodes.
<application
…..
android:label=”@string/app_name”
…..
</application>
Output:
Practical – 11
Application based on Option Menu.
Android Option Menus are the primary menus of android. They can be used for settings, search,
delete item etc.Here, we are going to see two examples of option menus. First, the simple option
menus and second, options menus with images.Here, we are inflating the menu by calling
the inflate() method of MenuInflater class. To perform event handling on menu items, you need
to override onOptionsItemSelected() method of Activity class.
Android Option Menu Example:- Let's see how to create menu in android. Let's see the simple
option menu example that contains three menu items.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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="example.javatpoint.com.optionmenu.MainActivity">
Page 27
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
Output:
Page 28
Practical-12
Application based on Rating Bar.
Android RatingBar can be used to get the rating from the user. The Rating returns a floating-
point number. It may be 2.0, 3.5, 4.0 etc.Android RatingBar displays the rating in stars. Android
RatingBar is the subclass of AbsSeekBar class.The getRating() method of android RatingBar
class returns the rating number.
Android RatingBar Example:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
Page 29
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="example.javatpoint.com.ratingbar.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="submit"
android:id="@+id/button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.615" />
<RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="72dp"
android:layout_marginTop="60dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Output:
Page 30
Practical -13
Application based on Media Player.
Android provides many ways to control playback of audio/video files and streams. One of this
way is through a class called MediaPlayer.
Page 31
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point"
android:id="@+id/textView"
android:layout_below="@+id/textview"
android:layout_centerHorizontal="true"
android:textColor="#ff7aff24"
android:textSize="35dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
Page 32
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:src="@drawable/abc"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/forward"
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pause"
android:id="@+id/button2"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/imageView"
android:layout_alignStart="@+id/imageView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/back"
android:id="@+id/button3"
android:layout_alignTop="@+id/button2"
Page 33
android:layout_toRightOf="@+id/button2"
android:layout_toEndOf="@+id/button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rewind"
android:id="@+id/button4"
android:layout_alignTop="@+id/button3"
android:layout_toRightOf="@+id/button3"
android:layout_toEndOf="@+id/button3" />
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/seekBar"
android:layout_alignLeft="@+id/textview"
android:layout_alignStart="@+id/textview"
android:layout_alignRight="@+id/textview"
android:layout_alignEnd="@+id/textview"
android:layout_above="@+id/button" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/textView2"
Page 34
android:layout_above="@+id/seekBar"
android:layout_toLeftOf="@+id/textView"
android:layout_toStartOf="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/textView3"
android:layout_above="@+id/seekBar"
android:layout_alignRight="@+id/button4"
android:layout_alignEnd="@+id/button4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/textView4"
android:layout_alignBaseline="@+id/textView2"
android:layout_alignBottom="@+id/textView2"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Following is the content of the res/values/string.xml.
<resources>
<string name="app_name">My Application</string>
Page 35
<string name="back"><![CDATA[<]]></string>
<string name="rewind"><![CDATA[<<]]></string>
<string name="forward"><![CDATA[>>]]></string>
<string name="pause">||</string>
</resources>
Following is the content of AndroidManifest.xml file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sairamkrishna.myapplication" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.sairamkrishna.myapplication.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Page 36
</manifest>
Output:
Practical – 14
Application Based on Content Providers.
Page 37
A content provider component supplies data from one application to others on request. Such
requests are handled by the methods of the ContentResolver class. A content provider can use
different ways to store its data and the data can be stored in a database, in files, or even over a
network.
<provider android:name="StudentsProvider"
android:authorities="com.example.MyApplication.StudentsProvider"/>
</application>
</manifest>
Page 38
Practical – 15
Page 39
The above picture shows that my app's name is My Application, by default. However, you can
change the name to whatever you want.
Step 2:-Drag a button from the Toolbar, change the button name to Camera, and change button ID
to btncamera.
Again, drag the ImageView from Toolbar.
Give the ImageView ID. I have given it as an imageView.
You can put any picture you want to see in the ImageView. For that, copy your image from your
PC and paste it to the "Drawables" folder which you can find in the left corner of the screen. Then,
double click on ImageView and give the source of that image i.e src= @drawable/imagename.
Page 40
Step 4 :-Now, we need to execute our camera app. We will do this by using a virtual device
called emulator which is already present in the Android Studio.
Page 41
Now, when you click on camera in the app, your camera will start.
Page 42