MAD 22617 Model Answer Paper 2024

83% found this document useful (6 votes)
15K views58 pages
The document contains 6 sample questions from an Android exam paper. Question 1 contains 5 short questions about Android features, directories, attributes, and publishing apps. Question 2 as…

Uploaded by

sofiyan
  • Q1: Android Concepts
  • Q2: Android Architecture and Lifecycle
  • Q3: Android Studio and Components
  • Q4: GUI and Programming Tasks
  • Q5: Sensors and Communications
  • Q6: Advanced Android Features

Sample Paper Questions

Q.1) Attempt any FIVE of the following. (10 Marks)


a) List features of Android Operating System.
b) Define Android Virtual Devices (AVD).
c) Write the directory path where images are stored while developing Android application.
d) List all attributes to develop a simple button.
e) Write the syntax for Intent-Filter tag.
f) Define services in Android operating system.
g) Enlist the steps to publish the Android application.
Q.2) Attempt any THREE of the following. (12 Marks)
a) Describe the Android architecture in detail.
b) Differentiate between JVM and DVM.
c) Explain the activity life cycle.
d) Discuss the need of permissions in Android. Describe the permissions to set system
functionalities like Bluetooth, camera.
Q.3) Attempt any THREE of the following. (12 Marks)
a) Explore the Steps to install and configure Android Studio and SDK.
b) Explain Date and Time picker with its methods.
c) Describe the significance of SQLite database in Android.
d) Discuss Developer console with its purpose.
Q.4) Attempt any THREE of the following. (12 Marks)
a) Observe the following GUI and write an XML file using relative layout to create the same.

1
b) Write a program to display circular progress bar.
c) List sensors in Android and explain any one in detail.
d) Explain zoom control (IN / OUT) with the help of an example.
e) Develop an application to send and receive SMS. (Write ONLY .java and permission tag
in manifest file)
Q.5) Attempt any TWO of the following. (12 Marks)
a) Develop the registration form using the following GUI.

b) Write a program to capture an image using camera and display it.


c) Develop a program to send an email.
Q.6) Attempt any TWO of the following. (12 Marks)
a) Develop an application to store student details like roll no, name, branch, marks,
percentage and retrieve student information using roll no. in SQLite databases.
b) Write a program to locate user’s current location. (Write ONLY .java and manifest file)
c) Develop a simple calculator using table layout.

2
Sample Question Paper Solutions

Q.1) Attempt any FIVE of the following. (10 Marks)


a) List features of Android Operating System.
Ans: 1. Beautiful UI: Android OS basic screen provides a beautiful and intuitive user interface.
2. Connectivity: GSM/EDGE, Bluetooth, Wi-Fi, LTE, NFC and WiMAX.
3. Storage: SQLite, a lightweight relational database, is used for data storage purposes.
4. Web browser: Based on the open-source WebKit layout engine, coupled with Chrome's V8
JavaScript engine supporting HTML5 and CSS3.
5. Multi-touch: Android has native support for multi-touch which was initially made available
in handsets such as the HTC Hero.
6. Multi-tasking: User can jump from one task to another and same time various application can
run simultaneously.
7. Resizable widgets: Widgets are resizable, so users can expand them to show more content or
shrink them to save space.

b) Define Android Virtual Devices (AVD).


Ans: An Android Virtual Device (AVD) is an emulator configuration that allows developers to
test the application by simulating the real device capabilities. We can configure the AVD by
specifying the hardware and software options. AVD manager enables an easy way of creating
and managing the AVD with its graphical interface. We can create as many AVDs as we need,
based on the types of device we want to test for.

c) Write the directory path where images are stored while developing Android
application.
Ans: Images, including photographs and screenshots, which are stored in the DCIM/ and
Pictures/ directories. The system adds these files to the MediaStore. Images table. For example
these are manifest file, java file, activity file and the most important file is resource file. This is
also shows as res file sometimes.

3
We stored our image in the resource file by following steps.
• First we need to download the image from our browser.
• Then we have to copy it from the folder in which the image is stored.
• Then after that we have to simple paste it in the resource
• If we want to put the icon or launcher icon then we have to paste the image in the mipmap
folder and select the shape and size.

d)List all attributes to develop a simple button.


Ans: The following attributes to develop a button in android studio are:
• id: id is an attribute used to uniquely identify a text Button.
• gravity: The gravity attribute is an optional attribute which is used to control the alignment of
the text like left, right, center, top, bottom, center_vertical, center_horizontal etc.
• text: text attribute is used to set the text in a Button. We can set the text in xml as well as in the
java
• textColor: textColor attribute is used to set the text color of a Button. Color value is in the
form of “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb”
• textSize: textSize attribute is used to set the size of the text on Button. We can set the text size
in sp(scale independent pixel) or dp(density pixel)

e) Write the syntax for Intent-Filter tag.


Ans: An Android Intent is an abstract description of an operation to be performed. It can be
used with startActivity to launch an Activity, broadcastIntent to send it to any interested
BroadcastReceiver components, and startService(Intent) or bindService(Intent,
ServiceConnection, int) to communicate with a background Service.
syntax:
<intent-filter
android:icon=”drawable resource”
android:label=”string resource”
android:priority=”integer” >
</intent-filter>

4
f) Define services in Android operating system.
Ans: Android service is a component that is used to perform operations on the background such
as playing music, handle network transactions, interacting content providers etc. It doesn’t has
any UI (user interface). The service runs in the background indefinitely even if application is
destroyed. Moreover, service can be bounded by a component to perform interactivity and inter
process communication (IPC). There can be two forms of a service. The lifecycle of service can
follow two different paths: started or bound.
1. Started
2. Bound
1)Started Service: A service is started when component (like activity) calls startService()
method, now it runs in the background indefinitely. It is stopped by stopService() method. The
service can stop itself by calling the stopSelf() method.
2) Bound Service: A service is bound when another component (e.g. client) calls bindService()
method. The client can unbind the service by calling the unbindService() method

g) Enlist the steps to publish the Android application.


Ans:
1)Create a Developer Account 6) Provide an appropriate content rating
2) Link our Merchant Account 7) Set up pricing & Distribution
3) Create an App 8) Rollout Release to publish the App
4) Prepare store Listing
5)Upload APK to an App Release

5
Q.2) Attempt any THREE of the following. (12 Marks)
a) Describe the Android architecture in detail.
Ans: Android application is divided into five parts they are as followed:
[Link]
[Link] Framework
[Link] Runtime
[Link] Libraries
[Link] Kernel

1. Linux Kernel: Linux Kernel is the core of the android operating system architecture that
exists at the root of android architecture. It is responsible for device drivers, power management,
memory management, device management, and resource management.
2. Native Libraries: On the top of the Linux kernel, there are Native libraries such as WebKit,
OpenGL, FreeType, SQLite, Media, C runtime library (libs), etc. The WebKit library is
responsible for browser support, SQLite is for database, Free Type for font support, Media for
playing and recording audio and video formats.
3. Android runtime: In the android runtime, there are core libraries and DVM (Dalvik Virtual
Machine) which is responsible for run android applications. DVM is like JVM but it is optimized
for mobile devices. It consumes less memory and provides fast performance.

6
4. Android framework: On the top of Native libraries and android runtime, there is an Android
framework. Android framework includes Android APIs such as UI (User Interface), telephony,
resources, locations, Content Providers(data), and package managers. It provides a lot of classes
and interfaces for android application development.
5. Applications: On top of the Android framework, there are applications. All applications such
as home, contact, settings, games, gallery, browsers are using the android framework that uses
android runtime and libraries. Android runtime and native libraries are using the Linux kernel.

b) Differentiate between JVM and DVM.


Ans:

[Link] Java Virtual Machine (JVM) Dalvik Virtual Machine (DVM)

1. JVM Supports multiple OS. DVM Supports only Android OS.

2. JVM uses java byte code and runs .class DVM uses its own byte code and runs its
file having JIT (Just in Time). [Link] byte code file.

3. It forms separate classes in separate It forms multiple classes in [Link] file.S


.class files.

4. Its Stack Based VM. Its Register Based VM.

5. Runs on More Memory Runs on Less Memory.

6. Executable file generated is .JAR file. Executable file generated is .APK file.
Multiple instances can be run efficiently.

7. Single instance of JVM is shared with Applicates are given their own instance.
multiple applications.

8. There is a constant pool for every class There is a constant pool for every
application.

7
c) Explain the activity life cycle.
Ans: Android Activity Lifecycle is controlled by 7 methods of [Link] class. The
android Activity is the subclass of ContextThemeWrapper class. An activity is the single screen
in android. It is like window or frame of Java. By the help of activity, you can place all your UI
components or widgets in a single screen.

The 7 lifecycle method of Activity describes how activity will behave at different states.
1. onCreate: called when activity is first created.
2. onStart: called when activity is becoming visible to the user.
3. onResume: called when activity will start interacting with the user.
4. onPause: called when activity is not visible to the user.
5. onStop: called when activity is no longer visible to the user.
6. onRestart: called after your activity is stopped, prior to start.
7. onDestroy: called before the activity is destroyed.

8
d) Discuss the need of permissions in Android. Describe the permissions to set
system functionalities like bluetooth,camera.
Ans: Permission requests protect sensitive information available from a device and should only
be used when access to information is necessary for the functioning of your app. This document
provides tips on ways you might be able to achieve the same (or better) functionality without
requiring access to such information; it is not an exhaustive discussion of how permissions work
in the Android operating system.
For example, suppose your app needs to be able to take pictures with the device camera. Your
app can request the CAMERA permission, which allows your app to access the camera directly.
Your app would then use the camera APIs to control the camera and take a picture. This
approach gives your app full control over the photography process, and lets you incorporate the
camera UI into your app.
Requesting Camera Permissions for Your App:
If your app requires a dangerous permission, check whether your app has been granted access for
the operation that requires the permission:
if ([Link](thisActivity, [Link])
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
}
Requesting Bluetooth Permissions for Your App:
In order to use Bluetooth features in your application, you must declare two permissions. The
first of these is BLUETOOTH. You need this permission to perform any Bluetooth
communication, such as requesting a connection, accepting a connection, and transferring data.
<uses-permission android:name=”[Link]” />
<uses-permission android:name=”[Link].BLUETOOTH_ADMIN” />

9
Q.3) Attempt any THREE of the following. (12 Marks)
a) Explore the Steps to install and configure Android Studio and SDK.
Ans: Follow steps below for complete installation and configuration of Android Studio.
Step 1: Download android studio
You can download Android Studio from this link or go to [Link] homepage and
search for downloads. Choose appropriate platform either for windows, mac or linux. Following
are the pre requirements for windows operating system.
Step 2: Run Exe File
Now the next step is to launch .exe file you just download. Following screen will appear. Click
next and select Android SDK checked if you don’t have it already. Better is to leave the default
settings. Make sure Android virtual device is also checked.
Step 3: Choose components
Next step is to accept license and agreement. Click on I Agree
Step 4: Accept license
Next step is to set location of installation. Please make sure your disk has minimum required
space before clicking on Next. For Android Studio installation location must have at least
500MB free space. For Android SDK installation, selected location must have at least 3.25GB
free space.
Step 5: Install location
Next step is to choose the start menu folder, where you want to create shortcut. If you don’t want
to create a shortcut just mark Do not create shortcut.
Step 6: Choose start menu folder And hit Install button. It will start installation.
Step 7: Finish
This informs you installation has completed. Click Finish. Make sure Start Android Studio is
checked. Following splash screen of Android Studio will appear.

10
b) Explain Date and Time picker with its methods.
Ans: Android Date Picker allows you to select the date consisting of day, month and year in
your custom user interface. For this functionality android provides DatePicker and
DatePickerDialog components.
Apart form date attributes, DatePicker object is also passed into this function. You can use the
following methods of the DatePicker to perform further operation.
1. getDayOfMonth(): This method gets the selected day of month
2. getMonth(): This method gets the selected month
3. getYear(): This method gets the selected year
4. setMaxDate(long maxDate): This method sets the maximal date supported by this DatePicker
in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone
5. setMinDate(long minDate): This method sets the minimal date supported by this
NumberPicker in milliseconds since January 1, 1970 00:00:00 in getDefault() time zone
6. setSpinnersShown(boolean shown): This method sets whether the spinners are shown
7. updateDate(int year, int month, int dayOfMonth): This method updates the current date
8. getCalendarView(): This method returns calendar view
9. getFirstDayOfWeek(): This Method returns first day of the week
Android Time Picker allows you to select the time of day in either 24 hour or AM/PM mode.
The time consists of hours, minutes and clock format. Android provides this functionality
through TimePicker class.
Apart form these methods, there are other methods in the API that gives more control over
TimePicker Component. They are listed below.
1. is24HourView(): This method returns true if this is in 24 hour view else false
2. isEnabled(): This method returns the enabled status for this view
3. setCurrentHour(Integer currentHour): This method sets the current hour
4. setCurrentMinute(Integer currentMinute): This method sets the current minute
5. setEnabled(boolean enabled): This method set the enabled state of this view
6. setIs24HourView(Boolean is24HourView): This method set whether in 24 hour or AM/PM
mode
7. setOnTimeChangedListener([Link] onTimeChangedListener):
This method Set the callback that indicates the time has been adjusted by the user

11
c) Describe the significance of SQLite database in Android.
Ans: Android SQLite is very important lightweight database which comes with android as.
Android SQLuite combines a clean SQL interface with. Very Small memory footprint and decent
speed for android sqlite is "baked into" the Android runtime. So every Android application can
create its own sqluite database sqlite is typical relational database, containing tables index
SQLite Database has method to create, delete, execute sql command & perform other common
relational database management task SQLite is embedded Relational Database Management
system Most relational database are standalone server processes that run independently, and in
cooperation with application that require database access. SQLite is referred to as embedded
because it is provided in I the form of a library that is linked into the application AG such there is
no standalone database Server running in the background. All database operation are handled
internally within the application through calls to function contained in the SQLite library. The
developers of sqlite have placed the technology into the public domain with the result that it is
now q widely deployed database solution, sqlite is Written in the c programming language and as
such, the android SDK provides a Java based "wrapper around the underlying database Interface.
The essentially consist of set of classes that may be utilized within the Java code of an
application to create and manage SQLite based database...
Necessity of SQL lite database:
Self-contained (requires no other components)
Serverless (requires no server backend)
Zero-configuration (does not need to configured for your application)
Transactional (changes within a single transaction in sqlite either occur completely or not at all)
Sqlite is the most widely deployed database engine in the world. The source code for SQLite is
in the public domain.

12
d) Discuss Developer console with its purpose?
Ans: Once we have registered and received-verification by we can e-mail sign in to the google
play android developer console which will be the home for the app publishing operations tools
on google play
Developer profile: The developer profile identifies us to Google play and to the customers
during registration we can provide information for the profile but que can go back at any time to
edit the information and change the settings.
The developer profile contains: The developer’s name, the name we wait to show users on the
Product details page and elsewhere a Google play. The developer contact information show
Google can contact me if needed (this information is not exposed to users). Merchant
information in-app billing information. The developers public key for licensing and in-app
Billing
Multiple User Account:
1. if we are working with a team, we can set up multiple user account to access different parts of
the Developer console.
2. The first account registered is the account owner with Full access to all parts of the console.
3. The owner can add user accounts manage what parts of the console they have access to for
example, an owner can grant users access to publishing and app configuration. but not access to
financial reports.
Linking the merchant hunt:
1. if we are working with a team, we can set up multiple user account to access different parts of
the developer console. The first account registered is the account with full access to all parts of
the console.
2. if we want to tell sell apps or in-app product, you can link the google checkout merchant
account to the developer [Link] paly uses the linked checkout account for financial and
tax identification and month pay out of sales.
The product and listing details:
1. The developer console lets we set up a colourful store front page for the app called the product
details pack. The product details page is the home for app in google play, It i's page users see on
their mobile phone or on the web when they want to learn about the app and download it.

13
2. we can upload custom brand assets screen shots and videos to high light what's great about the
app, and we can provide a localized description add notes about the latest version and more we
can update the store listing of any time even if we don't have a new version of the application.
Uploading and Publishing:
1. From the developer console can quickly upload a release ready APK and publish it when
ready.
2. The app is a draft until publish it at which time Google play makes the product details page &
app available to users, we can unpublish the app at any time.
Distribution controls:
In the Developer console we can manage what countries & territories the app is distributed to
and for some countries. we can choose what carries we want to target.
Selling and pricing the products:
1. The Developer console gives us tool to set prices for the Lapps and in-apps products The app
can either be free to download or priced.
2. if publish the app as free, it must remain free apps can be downloaded by any users in Google
play. If publish it as priced, we can change it to free priced app can be purchased and
downloaded only by users who have registered a form of payment in Google play.
3. if we are selling a priced app or in-app products or subscription the developer console lets set
prices in a large number of different currencies.
App Statistics:
1. The Developer console gives us detailed statics on the install performance of the app we can
view installation of the app measured by unique users, as well as by unique devices.
2. For user Installation, we can view active details install total installs and daily installs and
uninstall for devices, we can see active installs as well as daily install, uninstall upgrade
3. At a glance these charts highlight the app's installation peaks and longer-terms trend which
can correlate to promotion app improvement or other factors.

14
Q.4) Attempt any THREE of the following. (12 Marks)
a) Observe the following GUI and write an XML file using relative layout to
create the same.

<RelativeLayout xmlns: android= “[Link]


android:layout_width= “fill_parent”
android:layout_height= “fill_parent” android:paddingLeft= “16dp”
android:paddingRight= “16dp” >
<EditText
android:id= “@+id/name” android:layout_width= “fill_parent”
android:layout_height= “wrap_content” android:hint= “@string/reminder” />
<LinearLayout android:orientation= “vertical” android:layout_width= “fill_parent”
android:layout_height= “fill_parent” android:layout_alignParentStart= “true”
android:layout_below= “@+id/name” android:orientation= “horizontal”>
<EditText
android:id= “@+id/name” android:layout_width= “fill_parent”
android:layout_height= “wrap_content” android:hint= “@string/reminder” />
<EditText
android:id= “@+id/name” android:layout_width= “fill_parent”
android:layout_height= “wrap_content” android:hint= “@string/reminder” />
</LinearLayout>
<Button android:layout_width= “wrap_content” android:layout_height= “wrap_content”
android:text= “New Button” android:id= “@+id/button” /
</RelativeLayout>

15
b) Write a program to display circular progress bar.
Ans:
activity_main.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".MainActivity">
<RelativeLayout
android:id="@+id/progress_layout"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="100dp">
<!--progress bar implementation-->
<ProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/circular_shape"
android:indeterminate="false"
android:progressDrawable="@drawable/circular_progress_bar"
android:textAlignment="center" />

16
<!--Text implementation in center of the progress bar-->
<TextView
android:id="@+id/progress_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="---"
android:textColor="@color/colorPrimary"
android:textSize="28sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
[Link] file:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private ProgressBar progressBar;
private TextView progressText;
int i = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
// set the id for the progressbar and progress text

17
progressBar = findViewById([Link].progress_bar);
progressText = findViewById([Link].progress_text);
final Handler handler = new Handler();
[Link](new Runnable() {
@Override
public void run() {
// set the limitations for the numeric
// text under the progress bar
if (i <= 100) {
[Link]("" + i);
[Link](i);
i++;
[Link](this, 200);
} else {
[Link](this);
}
}
}, 200);
}
}
Output:

18
c) List sensors in Android and explain any one in detail.
Ans: List sensors in Android:
TYPE_ ACCELEROMETER
TYPE _AMBIENT_TEMPERATURE
TYPE _GRAVITY
TYPE _LIGHT
TYPE _GYROSCOPE.
TYPE _ PRESSURE
TYPE _PROXIMITY
TYPE _ ROTATION_VECTOR
TYPE _ ORIENTATION
TYPE _ MAGNETIC_FIELD
Motion Sensor: Motion Sensor are useful for monitoring device movement, such as tilt shake
rotation, or swing. The movement is usually a reflection of direct user input (for example, a user
steering a car in a game or user controlling a ball in game) but it can also be a reflection of the
physical environment in which the device is sitting (for example moving with you drive you
while car) in first case you are monitoring motion relative to the devices' frame of reference or
your application's frame or reference in the second case you are monitoring motion relative to the
device's frame of reference or your application's Frame of Reference. Motion sensors are by
themselves are not typically used to monitor device position but they can be used with others
sensor such as the geomagnetic field sensor to determine a device position relative to the world's
frame of reference

d) Explain zoom control (IN / OUT) with the help of an example.


Ans: In Android, Zoom Controls class display simple set of controls that is used for zooming
and provides callback to register for events. Zoom Controls has two buttons ZoomIn and
ZoomOut which are used to control the zooming functionality.
Zoom Controls code in XML:
<ZoomControls android:id=”@+id/simpleZoomControl”
android:layout_width=”wrap_content”

19
android:layout_height=”wrap_content” />
Important Methods Of Zoom Controls: Now let’s discuss some common methods which are
used to configure ZoomControls in our application.
1. hide(): This method is used to hide the ZoomControls from the screen. In some cases we need
to hide the ZoomControls from the screen so that we use this function.
2. show(): This method is used to show the ZoomControls which we hide from the screen by
using hide method.
This example demonstrates how do I Zoom In and Zoom Out an android ImageView.
Step 1: Create a new project in Android Studio, go to File ⇒ New Project and fill all required
details to create a new project.
Step 2: Add the following code to res/layout/activity_main.xml.
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout
xmlns:android=”[Link] xmlns:tools=”[Link]
[Link]/tools”
android:layout_width=”match_parent” android:layout_height=”match_parent”
android:orientation=”vertical” android:padding=”16dp” android:gravity=”center”
tools:context=”.MainActivity”>
<ImageView android:id=”@+id/imageView” android:layout_width=”match_parent”
android:layout_height=”match_parent” android:src=”@drawable/image” />
</LinearLayout>
Step 3: Add the following code to src/[Link]
import [Link]; import [Link];
import [Link];
import [Link]; import [Link];
public class MainActivity extends AppCompatActivity { private ScaleGestureDetector
scaleGestureDetector; private float mScaleFactor = 1.0f;
private ImageView imageView; @Override
protected void onCreate(Bundle savedInstanceState) { [Link](savedInstanceState);
setContentView([Link].activity_main); imageView=findViewById([Link]);
scaleGestureDetector = new ScaleGestureDetector(this, new

20
ScaleListener());
}
@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
[Link](motionEvent); return true;
}
private class ScaleListener extends [Link] {
@Override
public boolean onScale(ScaleGestureDetector scaleGestureDetector) { mScaleFactor *=
[Link](); mScaleFactor = [Link](0.1f,
[Link](mScaleFactor, 10.0f)); [Link](mScaleFactor);
[Link](mScaleFactor);
return true; }
}
}
Step 4 : Add the following code to [Link]
<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”[Link] package=”[Link].
sample”>
<application android:allowBackup=”true” android:icon=”@mipmap/ic_launcher”
android:label=”@string/app_name”
android:roundIcon=”@mipmap/ic_launcher_round” android:supportsRtl=”true”
android:theme=”@style/AppTheme”>
<activity android:name=”.MainActivity”>
<intent-filter>
<action android:name=”[Link]” />
<category android:name=”[Link]” />
</intent-filter>
</activity>
</application>
</manifest>

21
e) Develop an application to send and receive SMS. (Write ONLY .java and
permission tag in manifest file)
Ans:
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends Activity {
private static final int MY_PERMISSIONS_REQUEST_SEND_SMS =0 ;
Button sendBtn;
EditText txtphoneNo;
EditText txtMessage;
String phoneNo;
String message;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
sendBtn = (Button) findViewById([Link]);
txtphoneNo = (EditText) findViewById([Link]);
txtMessage = (EditText) findViewById([Link].editText2);
[Link](new [Link]() {
public void onClick(View view) {
sendSMSMessage();
}
});
}

22
protected void sendSMSMessage() {
phoneNo = [Link]().toString();
message = [Link]().toString();
if ([Link](this,
[Link].SEND_SMS)
!= PackageManager.PERMISSION_GRANTED) {
if ([Link](this,
[Link].SEND_SMS)) {
} else {
[Link](this,
new String[]{[Link].SEND_SMS},
MY_PERMISSIONS_REQUEST_SEND_SMS);
}
}
}
@Override
public void onRequestPermissionsResult(int requestCode,String permissions[], int[]
grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_SEND_SMS: {
if ([Link] > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
SmsManager smsManager = [Link]();
[Link](phoneNo, null, message, null, null);
[Link](getApplicationContext(), "SMS sent.",
Toast.LENGTH_LONG).show();
} else {
[Link](getApplicationContext(),
"SMS faild, please try again.", Toast.LENGTH_LONG).show();
return;
}
}
}

}
}

23
[Link]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
package="[Link]" >
<uses-permission android:name="[Link].SEND_SMS" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="[Link]"
android:label="@string/app_name" >
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
</application>
</manifest>

24
Q.5) Attempt any TWO of the following. (12 Marks)
a) Develop the registration form using the following GUI.

Ans:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/iv"
android:src="@drawable/ic_account"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"

25
android:id="@+id/name"
android:layout_margin="10dp"
android:padding="10dp"
android:hint="Name"
android:drawableLeft="@drawable/ic_name"
android:drawablePadding="10dp"
android:background="@drawable/ic_box"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:id="@+id/email"
android:layout_margin="10dp"
android:padding="10dp"
android:hint="Email ID"
android:drawableLeft="@drawable/ic_email"
android:drawablePadding="10dp"
android:background="@drawable/ic_box"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:id="@+id/password"
android:layout_margin="10dp"
android:padding="10dp"
android:hint="Password"
android:drawableLeft="@drawable/ic_password"
android:drawablePadding="10dp"
android:background="@drawable/ic_box"
/>

26
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:id="@+id/confirm"
android:layout_margin="10dp"
android:padding="10dp"
android:hint="Confirm Password"
android:drawableLeft="@drawable/ic_password"
android:drawablePadding="10dp"
android:background="@drawable/ic_box"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:id="@+id/mobile"
android:layout_margin="10dp"
android:padding="10dp"
android:hint="Enter Mobile"
android:drawableLeft="@drawable/ic_mobile"
android:drawablePadding="10dp"
android:background="@drawable/ic_box"
/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/male"

27
android:text="Male"
android:layout_marginRight="20dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/female"
android:text="Female" />
</RadioGroup>
<Button
android:layout_width="200dp"
android:layout_height="70dp"
android:layout_gravity="center"
android:text="Register"
android:onClick="register"
/>
</LinearLayout>
[Link]
package [Link].q5_a_guiregistrationform;
import [Link];
import [Link];
import [Link];
import [Link].*;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}

28
public void register(View view) {
EditText name = findViewById([Link]);
EditText email = findViewById([Link]);
EditText password = findViewById([Link]);
EditText confirm = findViewById([Link]);
RadioButton male = findViewById([Link]);
RadioButton female = findViewById([Link]);
String nameTxt = [Link]().toString();
String emailTxt = [Link]().toString();
String passTxt = [Link]().toString();
String confirmTxt = [Link]().toString();
if( ! ( [Link]() && [Link]() && [Link]() &&
[Link]() )
){
if( [Link]() || [Link]() ) {
[Link](this, "Registration Successful", Toast.LENGTH_SHORT).show();
}
else {
[Link](this, "Registration Unsuccessful", Toast.LENGTH_SHORT).show();
}
}
else {
[Link](this, "Registration Unsuccessful", Toast.LENGTH_SHORT).show();
}
}
}

29
b) Write a program to capture an image using camera and display it.
Ans:
[Link]
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
apk/res/android"
xmlns: tools "http:\\schemas [Link]/tools"
android:id="@+id/activity main"
android layout width="match_parent"
android layout. height="match_parent"
android : background="#FFF9c4"
android orientation="vertical"
tools context = "MainActivity">
<Imageview
android & id="@+id/ imageview"
android : layout width ="match_parent"
android:layout_height =" "goodp"
android:layout_centertlarizontal/="true"/>
<Button
android : id = @+id/button"
android:laybut width = "match-Parent"
android:layout_height="wrap_content"
android : text = "click help to capture image using camera"/>
</LinearLayout>
MainActivity Java
package [Link], my camera;
import [Link];
import [Link]. Intent
import [Link];
import [Link] Bitmap;
import [Link] Bundle;.

30
import [Link] view;
import [Link]. Button;
import [Link]. Imageview;
import [Link]. Toast;
import [Link] app AppCompatActivity
import [Link] [Link];
public class MainActivity extends AppCompatActivity {
Button button;
Imageview imageview.
Intent intent
public static final int RequestPermissionCode = 1;
Protected void onCreate(Bundle savedInstanceState) {
[Link] (savedInstanceState);
setContentView([Link]);
button = (Button) findViewById([Link]. button);
imageview (imageview) findViewById([Link])
EnableRuntime Permission();
button setonclickListener ((view) {
intent = new Intent([Link] mediastore.ACTION_IMAGE_CAPTURE);
StartActivity For
Result ( intent, request code: 7);
} );
}
Protected void onActivityResult(intRequestCode, int resultcode, Intent data) {
if (requestCode==7 && resultcode == RESULT_OK) {
Bitmap bitmap = (Bitmap) [Link]().get("data")
[Link] (bitmap);
}
}
Public void EnableRuntimepermission () {
if ([Link])

31
(activity: MainActivity. this, Manifest. [Link])
{
[Link] (context: mainActivity this text "CAMERA permission allow us to access
camera App",
Toast.LENGTH_SHORT_LONG) Show();
}
else
{
[Link](activity [Link], new string [] {
[Link]), Requestpermissioncode);
}
}
Public void onRequestPermissionResult(int RC, string per[], int[] PResult) {
Switch (Rc) {
case Request Permission code :
if ([Link] > 0 && PResult (0] == PackageManager PERMISSION_GRANTED) {
[Link](context: [Link] text;"
Permission Granted, Now your application can access camera",
Toast.LENGTH_LONG).show();
}
else
{
[Link]( context: MainActivity this, text: "Perimission canceled " +
Toost.LENGTH_LONG).show();
}
break;
}
}
}

32
[Link]
<?xml version="1.0" encoding="utf-8" ?>
<manifest xmlns:android="[Link]
xmlns:tools="[Link]
Package "[Link]">
<uses-permission android:name="[Link] CAMERA"/>
<application
android:allow Backup="true"
android:icon="@mipmap/ic launcher"
android:label="Mycamera"
android:roundIcon="@mipmap/ic_launcher-round"
android:supportsRt. ="true"
android:theme="@style/ AppTheme"
tools :Ignore="[Link]">
<activity android:name="MainActivity">
<intent-filter>
action android:name="[Link]"/>
<category android:name="[Link]"/>
</intent-filter>
</activity>
</application )
</manifest>

33
c) Develop a program to send an email?
Ans:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
tools:context="[Link]"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20px"
android:paddingRight="20px"
android:orientation="horizontal" >
<EditText
android:id="@+id/etTo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="22dp"
android:layout_marginTop="16dp"
android:ems="10" />
<EditText
android:id="@+id/etSub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etTo"
android:layout_below="@+id/etTo"
android:layout_marginTop="18dp"
android:ems="10" >
</EditText>

34
<EditText
android:id="@+id/etMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etSub"
android:layout_below="@+id/etSub"
android:layout_marginTop="28dp"
android:ems="10"
android:inputType="textMultiLine" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/etTo"
android:layout_alignBottom="@+id/etTo"
android:layout_alignParentLeft="true"
android:text="To:" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/etSub"
android:layout_alignBottom="@+id/etSub"
android:layout_alignParentLeft="true"
android:text="Subject:" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/etMsg"
android:layout_alignBottom="@+id/etMsg"

35
android:layout_alignParentLeft="true"
android:text="Message:" />
<Button
android:id="@+id/btSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etMsg"
android:layout_below="@+id/etMsg"
android:layout_marginLeft="76dp"
android:layout_marginTop="20dp"
android:text="Send" />
</RelativeLayout>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
EditText etTo, etSub, etMsg;
Button btSend;
String to, subject, message;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
etTo = (EditText) findViewById([Link]);
etSub = (EditText) findViewById([Link]);
etMsg = (EditText) findViewById([Link]);

36
btSend = (Button) findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View view) {
to = [Link]().toString();
subject = [Link]().toString();
message = [Link]().toString();
Intent email = new Intent(Intent.ACTION_SEND);
[Link](Intent.EXTRA_EMAIL, new String[]{ to});
[Link](Intent.EXTRA_SUBJECT, subject);
[Link](Intent.EXTRA_TEXT, message);
//need this to prompts email client only
[Link]("message/rfc822");
startActivity([Link](email, "Choose Email client :"));
}
});
}
}

37
Q.6) Attempt any TWO of the following. (12 Marks)
a) Develop an application to store student details like roll no, name, branch, marks,
percentage and retrieve student information using roll no. in SQLite databases.
Ans:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tv"
android:text="Insert Data"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rn"
android:layout_below="@+id/tv"
android:hint="Roll Number"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/name"
android:layout_below="@+id/rn"
android:hint="Name"
/>

38
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/branch"
android:layout_below="@+id/name"
android:hint="Branch"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/marks"
android:layout_below="@+id/branch"
android:hint="Marks"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/percentage"
android:layout_below="@+id/marks"
android:hint="Percentage"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/insert"
android:layout_below="@+id/percentage"
android:text="Insert Data"
android:onClick="insert"
/>
<EditText
android:layout_width="match_parent"

39
android:layout_height="wrap_content"
android:id="@+id/rnView"
android:layout_below="@+id/insert"
android:hint="Roll Number"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/view"
android:layout_below="@+id/rnView"
android:text="View Data"
android:onClick="view"
/>
</RelativeLayout>
[Link]
package [Link].q6_a_databasestudent;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}
public void insert(View view) {
EditText rn = findViewById([Link]);
EditText name = findViewById([Link]);
EditText branch = findViewById([Link]);

40
EditText marks = findViewById([Link]);
EditText percentage = findViewById([Link]);
DatabaseHandler db = new DatabaseHandler(this);
if([Link]([Link]().toString(), [Link]().toString(), [Link]().toString(),
[Link]().toString(), [Link]().toString())) {
[Link](getApplicationContext(), "Data Inserted!", Toast.LENGTH_SHORT).show();
}
else {
[Link](getApplicationContext(), "Student Exists", Toast.LENGTH_SHORT).show();
}
}
public void view(View view) {
EditText rn = findViewById([Link]);
DatabaseHandler db = new DatabaseHandler(this);
Cursor cursor = [Link]([Link]().toString());
if([Link]() == 0) {
[Link](getApplicationContext(), "No Records", Toast.LENGTH_SHORT).show();
return;
}
[Link]();
[Link](getApplicationContext(), [Link](0) + " " + [Link](1) + " " +
[Link](2) + " " + [Link](3) + " " + [Link](4) ,
Toast.LENGTH_SHORT).show();
}
}
[Link]
package [Link].q6_a_databasestudent;
import [Link].*;
import [Link].*;
import [Link].*;
public class DatabaseHandler extends SQLiteOpenHelper {

41
DatabaseHandler(Context context) { super(context, "ct2_qb", null, 1); }
@Override
public void onCreate(SQLiteDatabase db) {
String query = "create table students(roll text primary key, name text, branch text, marks text,
percentage text)";
[Link](query);
}
public Boolean addStudent(String rn, String name, String branch, String marks, String
percentage) {
SQLiteDatabase db = [Link]();
ContentValues values = new ContentValues();
[Link]("roll", rn);
[Link]("name", name);
[Link]("branch", branch);
[Link]("marks", marks);
[Link]("percentage", percentage);
Cursor cursor = [Link]("select * from students where roll = ?", new String[] { rn });
if([Link]() > 0) { return false; }
[Link]("students", null, values);
return true;
}
public Cursor viewStudent(String rn) {
SQLiteDatabase db = [Link]();
Cursor cursor = [Link]("select * from students where roll = ?", new String[] { rn });
return cursor;
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
[Link]("drop table if exists student");
}
}

42
b) Write a program to locate user’s current location. (Write ONLY .java and
manifest file)
Ans:
[Link] file
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
// initializing
// FusedLocationProviderClient
// object
FusedLocationProviderClient mFusedLocationClient;
// Initializing other items
// from layout file
TextView latitudeTextView, longitTextView;
int PERMISSION_ID = 44;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

43
latitudeTextView = findViewById([Link]);
longitTextView = findViewById([Link]);
mFusedLocationClient = [Link](this);
// method to get the location
getLastLocation();
}
@SuppressLint("MissingPermission")
private void getLastLocation() {
// check if permissions are given
if (checkPermissions()) {
// check if location is enabled
if (isLocationEnabled()) {
// getting last
// location from
// FusedLocationClient
// object
[Link]().addOnCompleteListener
(new OnCompleteListener<Location>() {
@Override
public void onComplete(@NonNull Task<Location> task)
{
Location location = [Link]();
if (location == null) {
requestNewLocationData();
} else {

[Link]([Link]() + "");

[Link]([Link]() + "");
}
}
});
} else {
[Link](this, "Please turn on" + " your location...",
Toast.LENGTH_LONG).show();
Intent intent = new
Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
} else {

44
// if permissions aren't available,
// request for permissions
requestPermissions();
}
}
@SuppressLint("MissingPermission")
private void requestNewLocationData() {

// Initializing LocationRequest
// object with appropriate methods
LocationRequest mLocationRequest = new LocationRequest();
[Link](LocationRequest.PRIORITY_HIGH_ACCURACY);
[Link](5);
[Link](0);
[Link](1);
// setting LocationRequest
// on FusedLocationClient
mFusedLocationClient = [Link](this);
[Link](mLocationRequest,
mLocationCallback, [Link]());
}
private LocationCallback mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
Location mLastLocation = [Link]();
[Link]("Latitude: " + [Link]() +
"");
[Link]("Longitude: " + [Link]() +
"");
}
};

// method to check for permissions


private boolean checkPermissions() {
return [Link](this,
[Link].ACCESS_COARSE_LOCATION) ==
PackageManager.PERMISSION_GRANTED && [Link](this,
[Link].ACCESS_FINE_LOCATION) ==
PackageManager.PERMISSION_GRANTED;

45
// If we want background location
// on Android 10.0 and higher,
// use:
// [Link](this,
[Link].ACCESS_BACKGROUND_LOCATION) ==
PackageManager.PERMISSION_GRANTED
}
// method to request for permissions
private void requestPermissions() {
[Link](this, new String[]{
[Link].ACCESS_COARSE_LOCATION,
[Link].ACCESS_FINE_LOCATION},
PERMISSION_ID);
}
// method to check
// if location is enabled
private boolean isLocationEnabled() {
LocationManager locationManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
return [Link](LocationManager.GPS_PROVIDER)
|| [Link](LocationManager.NETWORK_PROVIDER);
}
// If everything is alright then
@Override
public void
onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
[Link](requestCode, permissions, grantResults);

if (requestCode == PERMISSION_ID) {
if ([Link] > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
getLastLocation();
}
}
}

@Override
public void onResume() {
[Link]();

46
if (checkPermissions()) {
getLastLocation();
}
}
}
[Link] file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
package="[Link]">
<uses-permission android:name="[Link].ACCESS_COARSE_LOCATION" />
<uses-permission android:name="[Link].ACCESS_FINE_LOCATION" />
<uses-permission android:name="[Link].ACCESS_BACKGROUND_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/[Link]">
<activity android:name=".MainActivity">
<intent-filter>
<action
android:name="[Link]" />
<category
android:name="[Link]
" />
</intent-filter>
</activity>
</application>
</manifest>
Output:

47
c) Develop a simple calculator using table layout.
Ans:
activity_main.xml file.
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#8BC34A"
android:backgroundTint="@android:color/darker_gray"
tools:context=".MainActivity">
<!-- Text View to display our basic heading of "calculator"-->
<TextView
android:layout_width="194dp"
android:layout_height="43dp"
android:layout_marginStart="114dp"
android:layout_marginLeft="114dp"
android:layout_marginTop="58dp"
android:layout_marginEnd="103dp"
android:layout_marginRight="103dp"
android:layout_marginBottom="502dp"
android:scrollbarSize="30dp"
android:text=" Calculator"
android:textAppearance="@style/[Link].Body1"
android:textSize="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

48
<!-- Edit Text View to input the values -->
<EditText
android:id="@+id/num1"
android:layout_width="364dp"
android:layout_height="28dp"
android:layout_marginStart="72dp"
android:layout_marginTop="70dp"
android:layout_marginEnd="71dp"
android:layout_marginBottom="416dp"
android:background="@android:color/white"
android:ems="10"
android:onClick="clearTextNum1"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- Edit Text View to input 2nd value-->
<EditText
android:id="@+id/num2"
android:layout_width="363dp"
android:layout_height="30dp"
android:layout_marginStart="72dp"
android:layout_marginTop="112dp"
android:layout_marginEnd="71dp"
android:layout_marginBottom="374dp"
android:background="@android:color/white"
android:ems="10"
android:onClick="clearTextNum2"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"

49
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- Text View to display result -->
<TextView
android:id="@+id/result"
android:layout_width="356dp"
android:layout_height="71dp"
android:layout_marginStart="41dp"
android:layout_marginTop="151dp"
android:layout_marginEnd="48dp"
android:layout_marginBottom="287dp"
android:background="@android:color/white"
android:text="result"
android:textColorLink="#673AB7"
android:textSize="25sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- A button to perform 'sum' operation -->
<Button
android:id="@+id/sum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="292dp"
android:layout_marginEnd="307dp"
android:layout_marginBottom="263dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doSum"

50
android:text="+"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- A button to perform subtraction operation. -->
<!-- A button to perform division. -->
<Button
android:id="@+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="210dp"
android:layout_marginTop="292dp"
android:layout_marginEnd="113dp"
android:layout_marginBottom="263dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doSub"
android:text="-"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.507" />
<Button
android:id="@+id/div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="307dp"
android:layout_marginTop="292dp"
android:layout_marginEnd="16dp"

51
android:layout_marginBottom="263dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doDiv"
android:text="/"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<!-- A button to perform multiplication. -->


<Button
android:id="@+id/mul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="356dp"
android:layout_marginEnd="307dp"
android:layout_marginBottom="199dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doMul"
android:text="x"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- A button to perform a modulus function. -->
<!-- A button to perform a power function. -->
<Button
android:id="@+id/button"
android:layout_width="103dp"

52
android:layout_height="46dp"
android:layout_marginStart="113dp"
android:layout_marginTop="356dp"
android:layout_marginEnd="206dp"
android:layout_marginBottom="199dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doMod"
android:text="%(mod)"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.515" />
<Button
android:id="@+id/pow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="113dp"
android:layout_marginTop="292dp"
android:layout_marginEnd="210dp"
android:layout_marginBottom="263dp"
android:backgroundTint="@android:color/holo_red_light"
android:onClick="doPow"
android:text="n1^n2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.507" />
</[Link]>

53
[Link]
package [Link].calculator2;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private AppBarConfiguration appBarConfiguration;
private ActivityMainBinding binding;
public EditText e1, e2;
TextView t1;
int num1, num2;
public boolean getNumbers() {
//checkAndClear();
// defining the edit text 1 to e1
e1 = (EditText) findViewById([Link].num1);
// defining the edit text 2 to e2
e2 = (EditText) findViewById([Link].num2);
// defining the text view to t1
t1 = (TextView) findViewById([Link]);
// taking input from text box 1
String s1 = [Link]().toString();
// taking input from text box 2

54
String s2 = [Link]().toString();
if([Link]("Please enter value 1") && [Link](null))
{
String result = "Please enter value 2";
[Link](result);
return false;
}
if([Link](null) && [Link]("Please enter value 2"))
{
String result = "Please enter value 1";
[Link](result);
return false;
}
if([Link]("Please enter value 1") || [Link]("Please enter value 2"))
{
return false;
}
if((![Link](null) && [Link](null))|| (![Link]("") && [Link]("")) ){

String result = "Please enter value 2";

[Link](result);
return false;
}
if(([Link](null) && ![Link](null))|| ([Link]("") && ![Link]("")) ){
//checkAndClear();
String result = "Please enter value 1";
[Link](result);
return false;
}
if(([Link](null) && [Link](null))|| ([Link]("") && [Link]("")) ){
//checkAndClear();
String result1 = "Please enter value 1";
[Link](result1);
String result2 = "Please enter value 2";
[Link](result2);
return false;
}
else {
// converting string to int.
num1 = [Link](s1);

// converting string to int.


num2 = [Link](s2);
}
return true;

55
}
public void doSum(View v) {
// get the input numbers
if (getNumbers()) {
int sum = num1 + num2;
[Link]([Link](sum));
}
else
{
[Link]("Error Please enter Required Values");
}

}
public void clearTextNum1(View v)
// get the input numbers
[Link]().clear();
}
public void clearTextNum2(View v) {
// get the input numbers
[Link]().clear();
}
public void doPow(View v) {
//checkAndClear();
// get the input numbers
if (getNumbers()) {
double sum = [Link](num1, num2);
[Link]([Link](sum));
}
else
{
[Link]("Error Please enter Required Values");
}
}
// a public method to perform subtraction
public void doSub(View v) {
//checkAndClear();
// get the input numbers
if (getNumbers()) {
int sum = num1 - num2;
[Link]([Link](sum));
}
else
{
[Link]("Error Please enter Required Values");
}
}

56
// a public method to perform multiplication
public void doMul(View v) {
//checkAndClear();
// get the input numbers
if (getNumbers()) {
int sum = num1 * num2;
[Link]([Link](sum));
}
else
{
[Link]("Error Please enter Required Values");
}
}
// a public method to perform Division
public void doDiv(View v) {
//checkAndClear();
// get the input numbers
if (getNumbers()) {
// displaying the text in text view assigned as t1
double sum = num1 / (num2 * 1.0);
[Link]([Link](sum));
}
else
{
[Link]("Error Please enter Required Values");
}
// a public method to perform modulus function
public void doMod(View v) {
//checkAndClear();
// get the input numbers
if (getNumbers()) {
double sum = num1 % num2;
[Link]([Link](sum));
}
else
{
[Link]("Error Please enter Required Values");
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
e1 = (EditText) findViewById([Link].num1);
// defining the edit text 2 to e2
e2 = (EditText) findViewById([Link].num2);

57
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate([Link].menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in [Link].
int id = [Link]();
//noinspection SimplifiableIfStatement
if (id == [Link].action_settings) {
return true;
}
return [Link](item);
}
@Override
public boolean onSupportNavigateUp() {
NavController navController = [Link](this,
[Link].nav_host_fragment_content_main);
return [Link](navController, appBarConfiguration)
|| [Link]();
}
Output:

58

1 
 
Sample Paper Questions 
Q.1) Attempt any FIVE of the following.  
 
 
 
 
(10 Marks) 
a) List features of Android Operat
2 
 
b) Write a program to display circular progress bar. 
c) List sensors in Android and explain any one in detail. 
d) Expl
3 
 
Sample Question Paper Solutions 
Q.1) Attempt any FIVE of the following.   
 
 
 
(10 Marks) 
a) List features of Androi
4 
 
We stored our image in the resource file by following steps. 
• First we need to download the image from our browser. 
•
5 
 
f) Define services in Android operating system. 
Ans: Android service is a component that is used to perform operations
6 
 
Q.2) Attempt any THREE of the following.  
 
 
 
(12 Marks) 
a) Describe the Android architecture in detail. 
Ans: Andro
7 
 
4. Android framework: On the top of Native libraries and android runtime, there is an Android 
framework. Android framew
8 
 
c) Explain the activity life cycle. 
Ans: Android Activity Lifecycle is controlled by 7 methods of android.app.Activity
9 
 
d) Discuss the need of permissions in Android. Describe the permissions to set 
system functionalities like bluetooth,ca
10 
 
Q.3) Attempt any THREE of the following. 
 
 
 
(12 Marks) 
a) Explore the Steps to install and configure Android Studi

You might also like