MAD Module Solutions

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 126

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
WINTER – 2022 EXAMINATION
Subject Name Mobile Application Development Model Answer Subject Code: 22617
Important Instructions to examiners: XXXXX
1) The answers should be examined by key words and not as word-to-word as given in the model answer
scheme.
2) The model answer and the answer written by candidate may vary but the examiner may try to assess the
understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given more Importance (Not
applicable for subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components indicated in the figure. The
figures drawn by candidate and model answer may vary. The examiner may give credit for any equivalent
figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed constant values may
vary and there may be some difference in the candidate’s answers and model answer.
6) In case of some questions credit may be given by judgement on part of examiner of relevant answer based
on candidate’s understanding.
7) For programming language papers, credit may be given to any other program based on equivalent concept.
8) As per the policy decision of Maharashtra State Government, teaching in English/Marathi and Bilingual
(English + Marathi) medium is introduced at first year of AICTE diploma Programme from academic year
2021-2022. Hence if the students in first year (first and second semesters) write answers in Marathi or
bilingual language (English +Marathi), the Examiner shall consider the same and assess the answer based
on matching of concepts with model answer.

Q. Su Note: As Android programs contain many of the auto generated code statements from IDE, Marking
No b while assessing such answers correct logical steps taken to obtain the required output can be Scheme
. Q. considered.
N. Answer

1 Attempt any FIVE of the following: 10 M

a) Define OHA and state goal of OHA. 2M

An The OHA is the group that is in charge of the Android smartphones operating system. It was (Define : 1
s created by Google. The Open Handset Alliance (OHA) is consortium of multiple companies M, Stating
like Samsung, Sony, Intel and many more to provide services and deploy handsets using goal 1 M)
android platform.
The Open Handset Alliance (OHA) is an association whose goal is to develop open standards
for mobile devices, promote innovation in mobile phones and provide a better experience for
consumers at a lower cost.

b) Define Android Virtual Devices (AVD). 2M

An An Android Virtual Device (AVD) is a configuration that defines the characteristics of an (Define : 2
s Android phone, tablet, Wear OS, Android TV, or Automotive OS device that you want to M ,any
simulate in the Android Emulator. The AVD Manager is an interface you can launch from valid
Android Studio that helps you create and manage AVDs. definition
should be
considered)

Page No: 1 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
c) State how the APK files are built? 2M

An ● The javac compiler compiles the java source file into the class file. (For each
s step 1/2 M)
● The dx tool takes all the class files of your application and generates a single .dex file which
is a platform specific tool.
● Then Android Assets Packaging Tool (aapt) handles the packaging process and finally
creates an executable file with extension .apk.
● An APK file contains all of a program's code (such as .dex files), resources, assets,
certificates, and manifest file.

d) Enlist the elements of UI. 2M

An Enlist elements of UI. (1/2 mark


s Elements of UI: for each UI
● Menu Bar element,
● Toolbar any 4 UI
● Navigation Bar elements
expected)
● Editor Tabs
● Editor
● Project Explorer
● Status Bar
● Tool Buttons
e) State the uses of Intent in Android. 2M

An An Intent is a messaging object you can use to request an action from another app component. (1 M for
s Intents are used for facilitating communication between components like Activities, Services each use, 2
and Broadcast Receivers. uses
expected)

f) Name any four methods to get location data in android. 2M

An •float distanceTo(Location dest) (1/2 M for


s •float getAccuracy() each
•float getBearing() method,
•double getAltitude() any 4
•double getLatitude() methods
•float getSpeed() expected)
•boolean hasAccuracy()
•boolean hasAltitude()
•boolean hasBearing()
•boolean hasBearing()
•boolean hasSpeed()
•void reset()
•void setAccuracy(float accuracy)
•void setAltitude(double altitude)

Page No: 2 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
g) Explain significance of content provider. 2M

An Content Providers are used to share data between two applications. This can be implemented (1 M for
s in two ways: each
1. When you want to implement the existing content provider in another application. significance
2. When you want to create a new content provider that can share its data with other ,
Applications

2. Attempt any THREE of the following: 12 M

a) Describe the different features of Android. 4M

An User Interface: The user interface of the Android operating system is straight forward, and (1 M for
s these features make it very user friendly. each
feature, 4
Multiple Language Support: Android supports multiple languages in its operating system and features
one can change the language very easily based on one’s requirement, the International expected)
languages supported are English, Germany, Chinese, Dutch, French, German, Japanese,
Korean, Russian, and many more also some native language of India is also Supported Like
Hindi, Marathi, Gujarati, Punjabi and many more.
Multi-tasking: Android provides support to run apps and services in the background with ease
which allows the users to use multiple apps at the same time.
Connectivity: Android has extensive support to the connectivity and it supports connectivity
such as WiFi, Bluetooth, Hotspot, CDMA, GSM, NFC, VOLTE, UBB, VPN, 3G network
band, and 4G Network Band.
Extensive Application Support: Android have Play store which is used as the major tool to
download and update applications on the operating system, however, one can download the
installer(often called as APK file) and install it manually, but it is not much recommended as
third party applications could be prone to some security breach in the smartphones.

b) Explain features of Android SDK. 4M

An Android SDK is a collection of libraries and Software Development tools that are essential for (1 M for
s Developing Android Applications. Whenever Google releases a new version or update of each
Android Software, a corresponding SDK also releases with it. In the updated or new version of feature,
SDK, some more features are included which are not present in the previous version. Android any 4
SDK consists of some tools which are very essential for the development of Android features
Application. These tools provide a smooth flow of the development process from developing expected)
and debugging. Android SDK is compatible with all operating systems such as Windows,
Linux, macOS, etc.
1. Android Tool: This tool helps in managing the Android Virtual Device projects as well as
the installed components of the software development kit.
2. Emulator Tool: It helps us in testing the applications without the need of using the
application on an actual device.

Page No: 3 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
3. Dalvik Debug Monitor Server(DDMS): DDMS is very useful for debugging the Android
Application.
4. Android Debug Bridge (ADB): It is a very versatile command-line tool and is helpful for
the communication between the developer and the Emulator or the Android device that is
connected.

c) Explain the Android security model. 4M

An The Android security model is primarily based on a sandbox and permission mechanism. Each 2 M for
s application is running in a specific Dalvik virtual machine with a unique user ID assigned to it, explanation
which means the application code runs in isolation from the code of all other applications. , 2 M for
Therefore, one application has not granted access to other applications’ files. explaining
permission
Android application has been signed with a certificate with a private key Know the owner of s, any 2
the application is unique. This allows the author of the application will be identified if needed. permission
When an application is installed in the phone is assigned a user ID, thus avoiding it from s expected)
affecting it other applications by creating a sandbox for it. This user ID is permanent on which
devices and applications with the same user ID are allowed to run in a single process. This is a
way to ensure that a malicious application has Cannot access / compromise the data of the
genuine application. It is mandatory for an application to list all the resources it will Access
during installation. Terms are required of an application, in the installation process should be
user-based or interactive Check with the signature of the application.
Declaring and Using Permissions
The purpose of a permission is to protect the privacy of an Android user. Android apps must
request permission to access sensitive user data (such as contacts and SMS), as well as certain
system features (such as camera and internet). Depending on the feature, the system might grant
the permission automatically or might prompt the user to approve the request.
Permissions are divided into several protection levels. The protection level affects whether
runtime permission requests are required. There are three protection levels that affect third-
party apps: normal, signature, and dangerous permissions.
Normal permissions: Normal permissions cover areas where your app needs to access data or
resources outside the app’s sandbox, but where there’s very little risk to the user’s privacy or
the operation of other apps. For example, permission to set the time zone is a normal
permission. If an app declares in its manifest that it needs a normal permission, the system
automatically grants the app that permission at install time. The system doesn’t prompt the user
to grant normal permissions, and users cannot revoke these permissions.
Signature permissions: The system grants these app permissions at install time, but only when
the app that attempts to use permission is signed by the same certificate as the app that defines
the permission.
Dangerous permissions: Dangerous permissions cover areas where the app wants data or
resources that involve the user’s private information, or could potentially affect the user’s
stored data or the operation of other apps. For example, the ability to read the user’s contacts
is a dangerous permission. If an app declares that it needs a dangerous permission, the user
Page No: 4 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
must explicitly grant the permission to the app. Until the user approves the permission, your
app cannot provide functionality that depends on that permission. To use a dangerous
permission, your app must prompt the user to grant permission at runtime. For more details
about how the user is prompted, see Request prompt for dangerous permission.
d) Elaborate the need of permissions in Android. Explain the permissions to set 4M
system functionalitics like SEND-SMS, bluetooth.

An The purpose of a permission is to protect the privacy of an Android user. Android apps must (2 M for
s request permission to access sensitive user data (such as contacts and SMS), as well as certain explanation
system features (such as camera and internet). Depending on the feature, the system might grant of need, 1
the permission automatically or might prompt the user to approve the request. M each for
explaining
● android. permission. SEND_SMS permission
Allows the app to send SMS messages. This may result in unexpected charges. s of Sms
Malicious apps may cost you money by sending messages without your confirmation. and
bluetooth)
Following is the code snippet to set SEND_SMS permissions in manifest file.
<uses-permission android: name="android.permission.SEND_SMS"/>

● android. permission. BLUETOOTH


You need to provide following permissions in AndroidManifest.xml file.
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

3. Attempt any THREE of the following: 12 M

a) Explain data and time picker with its method. 4M

An Date Picker: Date picker


s In Android, DatePicker is a widget used to select a date. It allows to select date by day, month (any two
and year in our custom UI (user interface). If we need to show this view as a dialog then we methods) 2
have to use a DatePickerDialog class. M and time
Methods of DatePicker:
picker (any
1. setSpinnersShown(boolean shown): This method is used to set whether the spinner of the
two
date picker in shown or not. In this method you have to set a Boolean value either true or false.
True indicates spinner is shown, false value indicates spinner is not shown. Default value for methods) 2
this function is true. M
Syntax:
DatePicker simpleDatePicker = (DatePicker)findViewById(R.id.simpleDatePicker);
simpleDatePicker.setSpinnersShown(false);
2. getDayOfMonth(): This method is used to get the selected day of the month from a date
picker.
This method returns an integer value.
DatePicker simpleDatePicker = (DatePicker) findViewById(R.id.simpleDatePicker);
int day = simpleDatePicker.getDayOfMonth();

Page No: 5 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
3. getMonth(): This method is used to get the selected month from a date picker. This method
returns an integer value.
DatePicker simpleDatePicker = (DatePicker)findViewById(R.id.simpleDatePicker);
int month = simpleDatePicker.getMonth();
4. getYear(): This method is used to get the selected year from a date picker. This method
returns an integer value.
DatePicker simpleDatePicker = (DatePicker)findViewById(R.id.simpleDatePicker);
int year = simpleDatePicker.getYear();
5. getFirstDayOfWeek(): This method is used to get the first day of the week. This method
returns an integer value.
DatePicker simpleDatePicker = (DatePicker)findViewById(R.id.simpleDatePicker);
int firstDay=simpleDatePicker.getFirstDayOfWeek();
TimePicker:
In Android, TimePicker is a widget used for selecting the time of the day in either AM/PM
mode or 24 hours mode. The displayed time consist of hours, minutes and clock format. If we
need to show this view as a Dialog then we have to use a TimePickerDialog class.
Methods of TimePicker:
1. setCurrentHour(Integer currentHour): This method is used to set the current hours in a
time picker.
setHour(Integer hour): setCurrentHour() method was deprecated in API level 23. From api
level 23 we have to use setHour(Integer hour). In this method there is only one parameter of
integer type which is used to set the value for hours.
TimePicker simpleTimePicker=(TimePicker)findViewById(R.id.simpleTimePicker);
simpleTimePicker.setCurrentHour(5);
simpleTimePicker.setHour(5);
2. setCurrentMinute(Integer currentMinute): This method is used to set the current minutes
in a time picker. setMinute(Integer minute): setCurrentMinute() method was deprecated in API
level 23. From api level 23 we have to use setMinute(Integer minute). In this method there is
only one parameter of integer type which set the value for minutes.
TimePicker simpleTimePicker=(TimePicker)findViewById(R.id.simpleTimePicker);
simpleTimePicker.setCurrentMinute(35);
simpleTimePicker.setMinute(35);
4. getCurrentMinute(): This method is used to get the current minutes from a time picker.
getMinute(): getCurrentMinute() method was deprecated in API level 23. From api level 23
we have to use getMinute(). This method returns an integer value.
TimePicker simpleTimePicker = (TimePicker)findViewById(R.id.simpleTimePicker);
int minutes = simpleTimePicker.getCurrentMinute();
int minutes = simpleTimePicker.getMinute();
5. setIs24HourView(Boolean is24HourView): This method is used to set the mode of the
Time picker either 24 hour mode or AM/PM mode. In this method we set a Boolean value
either true or false. True value indicate 24 hour mode and false value indicate AM/PM mode.
TimePicker simpleTimePicker = (TimePicker)findViewById(R.id.simpleTimePicker);
simpleTimePicker.setIs24HourView(true);
6. is24HourView(): This method is used to check the current mode of the time picker. This
method returns true if its 24 hour mode or false if AM/PM mode is set.
TimePicker simpleTimePicker = (TimePicker)findViewById(R.id.simpleTimePicker);

Page No: 6 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Boolean mode=simpleTimePicker.is24HourView();
7.setOnTimeChangedListener(TimePicker.OnTimeChangedListener
onTimeChanged(): This method is used to set the callback that indicates the time has been
adjusted by the user.
onTimeChanged(TimePicker view, int hourOfDay, int minute) is an override function of this
listener in which we have three parameters first is for TimePicker, second for getting hour of
the day and last is for getting the minutes after changing the time of the time picker.
TimePicker simpleTimePicker = (TimePicker)findViewById(R.id.simpleTimePicker);
simpleTimePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() {
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
}
});
b) Explain the steps to install and configure Android studio and SDK. 4M

An ● Download the latest version of Android Studio from above URL and launch Android 4 M for
s Studio.exe file by double clicking on it. steps
● The initial android studio setup screen will open in that click Next to continue for further
steps of environment setup
● Now we need to select a required components to setup an android environment. Here
we selected all three components (Android Studio, Android SDK and Android Virtual
Device) and click Next.
● Now we need to agree the License agreements to proceed further, click on I Agree
button
● Now we need to specify the local machine drive location to install Android Studio and
Android SDK.
● After selecting the location path to install required components, click Next.
● Now select the start menu folder to create a shortcut for android studio and click Install
● Once we click Install button the installation process will start and click Next after
completion of Installation.
● After that it will show installation completion wizard in that click Finish to launch
android studio While launching Android Studio it will give you an option to import
settings from previous version of studio. In case if you don’t have any previous version,
select second option and click OK
● Now android studio will open a welcome wizard window in that click Next to validate
our current Android SDK and development environment setup
● Now select a Standard installation type and click Next to install a common settings and
options
● Now verify settings and click Finish to complete android studio setup process
● After completion of required components installation click on Finish
● After completion of all required components installation, we will be able to see Android
Studio welcome window
c) Explain the activity life cycle. 4M

Page No: 7 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
An Diagram 2
s M
explanation
2M

Activities have a predefined life-cycle methods as follows:

onCreate (): Called then the activity is created. Used to initialize the activity, for
example create the user interface.

onStart ():called when activity is becoming visible to the user.

onResume (): Called if the activity get visible again and the user starts interacting
with the activity again. Used to initialize fields, register listeners, bind
to services, etc.

onPause (): Called once another activity gets into the foreground. Always called
before the activity is not visible anymore. Used to release resources or
save application data. For example you unregister listeners, intent
receivers, unbind from services or remove system service listeners.

Page No: 8 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
onStop (): Called once the activity is no longer visible. Time or CPU intensive shutdown
operations, such as writing information to a database should be down in the onStop() method.
This method is guaranteed to be called as
of API 11.

onDestroy (): called before the activity is destroyed.

d) Explain the steps to deploy app on Google Play Store. 4M

An Step 1: Create a Developer Account 4 M for all


s Before you can publish any app on Google Play, you need to create a Developer Account. You steps
can easily sign up for one using your existing Google Account. You’ll need to pay a one-time
registration fee of $25 using your international credit or debit card. It can take up to 48 hours
for your registration to be fully processed.

Step 2: Plan to Sell? Link Your Merchant Account


If you want to publish a paid app or plan to sell in-app purchases, you need to create a payments
center profile, i.e. a merchant account. A merchant account will let you manage your app sales
and monthly payouts, as well as analyze your sales reports right in your Play Console.

Step 3: Create an App


After creating application by clicking on ‘Create Application'. Here you have to select your
app’s default language from the drop-down menu and then type in a title for your app. The title
of your app will show on Google Play after you’ve published.

Step 4: Prepare Store Listing


Before you can publish your app, you need to prepare its store listing. These are all the details
that will show up to customers on your app’s listing on Google Play. You not necessarily
complete it at once, you can always save a draft and revisit it later when you’re ready to publish.
The information required for your store listing is divided into several categories such as
Product Details containing title, short and full description of the app, your app’s title and
description should be written with a great user experience in mind. Use the right keywords, but
don’t overdo it. Make sure your app doesn’t come across as spam-y or promotional, or it will
risk getting suspended on the Play Store.
Graphic Assets where you can add screenshots, images, videos, promotional graphics, and
icons that showcase your app’s features and functionality.
Languages & Translations, Categorization where in category can be selected to which your
app belong to. Contact Details, Privacy Policy for apps that request access to sensitive user
data or permissions, you need to enter a comprehensive privacy policy that effectively discloses
how your app collects, uses, and shares that data.

Step 5: Upload APK to an App Release


Finally upload your app, by uploading APK file. Before you upload APK, you need to create
an app release. You need to select the type of release you want to upload your first app version
to. You can choose between an internal test, a closed test, an open test, and a production release.

Page No: 9 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
The first three releases allow you to test out your app among a select group of users before you
make it go live for everyone to access.
This is a safer option because you can analyze the test results and optimize or fix your app
accordingly if you need to before rolling it out to all users.
Once you create a production release, your uploaded app version will become accessible to
everyone in the countries you choose to distribute it in and click on ‘Create release.’

Step 6: Provide an Appropriate Content Rating


If you don’t assign a rating to your app, it will be listed as ‘Unrated’. Apps that are ‘Unrated’
may get removed from Google Play.
To rate your app, you need to fill out a content rating questionnaire An appropriate content
rating will also help you get to the right audience, which will eventually improve your
engagement rates.

Step 7: Set Up Pricing & Distribution


Before you can fill out the details required in this step, you need to determine your app’s
monetization strategy. Once you know how your app is going to make money, you can go ahead
and set up your app as free or paid.
You can always change your app from paid to free later, but you cannot change a free app to
paid. For that, you’ll need to create a new app and set its price.

Step 8: Rollout Release to Publish Your App


The final step involves reviewing and rolling out your release after making sure you’ve taken
care of everything else.
Before you review and rollout your release, make sure the store listing, content rating, and
pricing and distribution sections of your app each have a green check mark next to them.
Once you’re sure about the correctness of the details, select your app and navigate to ‘Release
management’ – ‘App releases.’ You can always opt for reviews by clicking on ‘Review’ to be
taken to the ‘Review and rollout release’ screen. Here, you can see if there are any issues or
warnings you might have missed out on.
Finally, select ‘Confirm rollout.’ This will also publish your app to all users in your target
countries on Google Play.

4. Attempt any THREE of the following: 12 M

a) Explain the fundamentals of Ul design in detail. 4M

An 1. Views: 1 M for
s • The basic building block for user interface in Android is a View, which is created from the each
View class and occupies a rectangular area on the screen and is responsible for drawing and
event handling.
• Views are the base class for all visual interface elements (commonly known as controls or
widgets). All user interface UI controls, including the layout classes, are derived from View.
• A View is an object/widget that draws something on the sreen by the help of user interact.
Page No: 10 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
• Examples of widgets are buttons, text boxes, labels etc.
2. View Groups:
• The ViewGroup is a subclass of View and provides invisible container that hold other Views
or other ViewGroups and define their layout properties.
• View groups are extensions of the View class that can contain multiple child Views. In order
to Extend the ViewGroup class to create compound controls made up of interconnected child
views.
• A ViewGroup provides the layout in which we can order the appearance and sequence of
views.
Examples of ViewGroup are FrmaeLayout, LineourLayout etc.
3. Fragments:
• Fragments represents a portion of user interface in an Activity. Fragments, introduced in
Android 3.0 which uses API level 11, are used to encapsulate portions of your UI. This
encapsulation makes fragments particularly useful when optimizing our UI layouts for different
screen sizes and creating reusable user interface (UI) elements.
• Each Fragment includes its own user interface (UI) layout and receives the related input events
but is tightly bound to the activity into which each must be embedded. Fragments are similar
to UI view controller in iPhone development.
4. Activities:
• Activities dictate the UI and handle the user interaction to the smart phone screen. Activities
represent a single screen that user interact.
• Activities are the Android equivalent of Forms in traditional windows desktop development.
To display a UI we assign a View (Usually a layout or Fragment) to an Activity
b) Write a program to display a rectangular progress bar. 4M

An Xml File: xml file 2


s <?xml version="1.0" encoding="utf-8"?> M, java file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2M
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<ProgressBar
android:id="@+id/progressBar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:indeterminate="false"
android:max="100"

Page No: 11 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:minHeight="50dp"
android:minWidth="200dp"
android:progress="1" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/progressBar"
android:layout_below="@+id/progressBar"/>
</RelativeLayout>
Java file:
package in.edu.vpt.progressbar;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.widget.ProgressBar;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private ProgressBar progressBar;
private int progressStatus = 0;
private TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
textView = (TextView) findViewById(R.id.textView);
// Start long running operation in a background thread
new Thread(new Runnable() {
public void run() {
while (progressStatus < 100) {
progressStatus += 1;
new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
progressBar.setProgress(progressStatus);
textView.setText(progressStatus+"/"+progressBar.getMax());
}
});
try {
// Sleep for 200 milliseconds.
Thread.sleep(200);
} catch (InterruptedException e) {
Page No: 12 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
e.printStackTrace();
}
}
}
}).start();
}
}
c) Explain Android system architecture in detail. 4M

An Diagram 2
s M,
Explanatio
n2M

1. Applications:
• The top layer of android architecture is Applications. The native and third party applications
like Contacts, Email, Music, Gallery, Clock, Games, etc. whatever we will build those will be
installed on this layer only.
• The application layer runs within the Android run time using the classes and services made
available from the application framework.
2. Application Framework:
• The Application Framework provides the classes used to create an Android application. It
also provides a generic abstraction for hardware access and manages the user interface and
application resources.
• It basically provides the services through which we can create the particular class and make
that class helpful for the Applications creation.
• The application framework includes services like telephony service, location services,
notification manager, NFC service, view system, etc. which we can use for application
development as per our requirements.
3. Android Runtime:
Page No: 13 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
• Android Runtime environment is an important part of Android rather than an internal part and
it contains a components like core libraries and the Dalvik virtual machine.
• The Android run time is the engine that powers our applications along with the libraries and
it forms the basis for the application framework.
(i) Dalvik Virtual Machine (DVM) is a register-based virtual machine like Java Virtual
Machine (JVM).
It is specially designed and optimized for android to ensure that a device can run multiple
instances efficiently. It relies on the Linux kernel for threading and low-level memory
management.
(ii) The core libraries in android runtime will enable us to implement an android applications
using standard JAVA programming language.
4. Platform Libraries:
• The Platform Libraries includes various C/C++ core libraries and Java based libraries such as
SSL, libc, Graphics, SQLite, Webkit, Media, Surface Manger, OpenGL etc. to provide a
support for android development.
5. Linux Kernel:
• Linux Kernel is a bottom layer and heart of the android architecture. It is heart of Android
architecture that exists at the root of android architecture and contains all the low-level device
drivers for the various hardware components of an Android device.
• Linux Kernel is responsible for device drivers, power management, memory management,
device management and resource access. It manage all the drivers such as display drivers,
camera drivers, Bluetooth drivers, audio drivers, memory drivers, etc. which are mainly
required for the android device during the runtime.
• The Linux Kernel will provide an abstraction layer between the device hardware and the
remainder of the stack. It is responsible for memory management, power management, device
management, resource access, etc.
d) Explain the procedure of Geo-coding and reverse Geo-coding. 4M

An Geo-Coding: geocoding 2
s • If we know the latitude and longitude of a location, we can find out its address using a process M and
known as Geocoding. Google Maps in Android supports this via the Geocoder class. reverse
geocoding 2
• The following code shows how we can find out the address of a location we have just touched
M
using the getFromLocation() method:
classMapOverlay extends com.google.android.maps.Overlay
{
@Override
publicboolean draw(Canvas canvas, MapViewmapView,
boolean shadow, long when)
{
//...
}
@Override
publicbooleanonTouchEvent(MotionEvent event, MapViewmapView)

Page No: 14 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
{
//---when user lifts his finger---
if (event.getAction() == 1) {
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
Geocoder geoCoder = new Geocoder(
getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
p.getLatitudeE6() / 1E6,
p.getLongitudeE6() / 1E6, 1);
String add = "";
if (addresses.size() > 0)
{
for (inti=0; i<addresses.get(0).getMaxAddressLineIndex();
i++)
add += addresses.get(0).getAddressLine(i) + "n";
}
Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show();
}
catch (IOException e) {
e.printStackTrace();
}
return true;
}
else
return false;
}
}

Reverse-geocoding:
If we know the address of a location but want to know its latitude and longitude, we can do so
via reverse-Geocoding. Again, we can use the Geocoder class for this purpose.
• The following code shows how we can find the exact location of the Empire State Building
by using the getFromLocationName() method:
Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocationName(
"empire state building", 5);
String add = "";
if (addresses.size() > 0) {
p = new GeoPoint(
Page No: 15 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
(int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));
mc.animateTo(p);
mapView.invalidate();
}
} catch (IOException e) {
e.printStackTrace();
}
Once. the location is found, the above code navigates the map to the location.
e) Develop an application to send and receive SMS (Write only Java and 4M
permission tag in manifest file).
An Permissions and <receiver> tag required in AndroidManifest.xml Manifest
s <uses-permission android:name="android.permission.RECEIVE_SMS" /> File:2M
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/> Java Code:
<uses-permission android:name="android.permission.WRITE_SMS"/> 4M

<receiver
android:name=".SmsReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>

MainActivity.java
(Cosidering appropriate layout file with 2 edit text boxes namely for phone number,
message and a button for sending sms)

package com.example.testreceivesms;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


SmsReceiver sms= new SmsReceiver();
EditText et1,et2;
Page No: 16 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Button b1;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=findViewById(R.id.etPhno);
et2=findViewById(R.id.etmsg);
b1=findViewById(R.id.btnSms);
if(ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.SEND_S
MS)!=
PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(MainActivity.this,new
String[]{Manifest.permission.SEND_SMS},100);
}
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String phno= et1.getText().toString();
String msg=et2.getText().toString();
SmsManager smsManager= SmsManager.getDefault();
smsManager.sendTextMessage(phno,null,msg,null,null);
Toast.makeText(MainActivity.this,"Sms sent successfully",
Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(MainActivity.this,"Sms failed to send... try again",
Toast.LENGTH_LONG).show();
}
}
});
}
@Override
protected void onStart() {
super.onStart();
IntentFilter filter=new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(sms,filter);
}

@Override
protected void onStop() {
super.onStop();
unregisterReceiver(sms);
}
}

SmsReceiver.java
Page No: 17 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
package com.example.testreceivesms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class SmsReceiver extends BroadcastReceiver {


SmsReceiver(){}
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();

if (bundle != null) {
// Retrieve the SMS Messages received
Object[] sms = (Object[]) bundle.get("pdus");

// For every SMS message received


for (int i=0; i < sms.length; i++) {
// Convert Object array
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);

String phone = smsMessage.getOriginatingAddress();


String message = smsMessage.getMessageBody().toString();

Toast.makeText(context, “Received from “+ phone + ": " + message,


Toast.LENGTH_SHORT).show();
}
}
}
}

5. Attempt any TWO of the following: 12 M

a) Develop a program to send and receive an Email. 6M

An Program to send Email Any


s activity_main.xml correct
<?xml version="1.0" encoding="utf-8"?> logic
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" program
xmlns:tools="http://schemas.android.com/tools" should be
android:layout_width="match_parent" considered,
android:layout_height="match_parent" 3M for
tools:context=".MainActivity"> send logic,
3M for
<EditText receive
android:id="@+id/editText1" logic
android:layout_width="wrap_content"
Page No: 18 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="18dp"
android:layout_marginRight="22dp" />

<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_alignLeft="@+id/editText1"
android:layout_marginTop="20dp" />

<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_alignLeft="@+id/editText2"
android:layout_marginTop="30dp" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_alignParentLeft="true"
android:text="Send To:"
android:textColor="#0F9D58" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText2"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true"
android:text="Email Subject:"
android:textColor="#0F9D58" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText3"
android:layout_alignBottom="@+id/editText3"
android:text="Email Body:"
Page No: 19 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:textColor="#0F9D58" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText3"
android:layout_alignLeft="@+id/editText3"
android:layout_marginLeft="76dp"
android:layout_marginTop="20dp"
android:text="Send email!!" />
</RelativeLayout>

MainActivity.java
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
// define objects for edit text and button
Button button;
EditText sendto, subject, body;

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

// Getting instance of edittext and button


sendto = findViewById(R.id.editText1);
subject = findViewById(R.id.editText2);
body = findViewById(R.id.editText3);
button = findViewById(R.id.button);

// attach setOnClickListener to button with Intent object define in it


button.setOnClickListener(view -> {
String emailsend = sendto.getText().toString();
String emailsubject = subject.getText().toString();
String emailbody = body.getText().toString();

// define Intent object with action attribute as ACTION_SEND


Intent intent = new Intent(Intent.ACTION_SEND);

// add three fields to intent using putExtra function


intent.putExtra(Intent.EXTRA_EMAIL, new String[]{emailsend});
intent.putExtra(Intent.EXTRA_SUBJECT, emailsubject);
intent.putExtra(Intent.EXTRA_TEXT, emailbody);

Page No: 20 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
// set type of intent
intent.setType("message/rfc822");

// startActivity with intent with chooser as Email client using


createChooser function
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
});
}
}

Program to receive Email


(Note: Receiving email is not the service of Android OS, instead it uses some third party
applicaton like Gmail, so instead of receiving email in android app, a code which broadcasts
message if email comes using broadcast receiver or any relevant logic can be considered.)
MainActivity.java
package com.example.myemailprog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.IntentFilter;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {


GmailReceiver gml;
IntentFilter intf;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gml = new GmailReceiver();
intf = new IntentFilter("android.intent.action.VIEW");
}

@Override
protected void onResume() {
super.onResume();
registerReceiver(gml, intf);
}

@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(gml);
}
}
Gmailrerciever..java
package com.example.myemailprog;

import android.app.Notification;
import android.app.NotificationManager;

Page No: 21 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.widget.Toast;

public class GmailReceiver extends BroadcastReceiver


{
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Email Received", Toast.LENGTH_LONG).show();

}
}

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myemailprog">
<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/Theme.MyEmailProg">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="GmailReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.PROVIDER_CHANGED"
android:priority="-10">
</action>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="content" android:host="gmail-ls"
android:pathPattern="/unread/.*">
</data>
</intent-filter>
</receiver>
Page No: 22 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
</application>
</manifest>
b) Develop a program for providing bluetooth connectivity. 6M

An activity_main.xml Layout file


s <RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android" : 2M
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" Java File :
android:layout_height="match_parent" 3M
tools:context=".MainActivity" >
Manifest
file : 1M
<TextView android:text=""
android:id="@+id/out"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<Button

android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="49dp"
android:text="TURN_ON" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="27dp"
android:text="DISCOVERABLE" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_below="@+id/button2"
android:layout_marginTop="28dp"
android:text="TURN_OFF" />

</RelativeLayout>

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>

Page No: 23 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
<manifest xmlns:androclass="http://schemas.android.com/apk/res/android"
package="com.example.bluetooth"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.bluetooth.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>
</manifest>

MainActivity.java
package com.example.bluetooth;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {


private static final int REQUEST_ENABLE_BT = 0;
private static final int REQUEST_DISCOVERABLE_BT = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Page No: 24 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
final TextView out=(TextView)findViewById(R.id.out);
final Button button1 = (Button) findViewById(R.id.button1);
final Button button2 = (Button) findViewById(R.id.button2);
final Button button3 = (Button) findViewById(R.id.button3);
final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
out.append("device not supported");
}
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (!mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if (!mBluetoothAdapter.isDiscovering()) {
//out.append("MAKING YOUR DEVICE DISCOVERABLE");
Toast.makeText(getApplicationContext(), "MAKING YOUR DEVICE DISCOVERA
BLE",
Toast.LENGTH_LONG);

Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVER


ABLE);
startActivityForResult(enableBtIntent, REQUEST_DISCOVERABLE_BT);

}
}
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
mBluetoothAdapter.disable();
//out.append("TURN_OFF BLUETOOTH");
Toast.makeText(getApplicationContext(), "TURNING_OFF BLUETOOTH", Toast.LENGT
H_LONG);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

Page No: 25 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
}
c) Develop a program to implement 6M

i) List view of 5 items


ii) Grid view of 4 x 4 items
iii) Image view.

An <?xml version="1.0" encoding="utf-8"?> Correct


s <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" Logics for
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" ListView :
android:layout_width="match_parent" 2M
android:layout_height="match_parent"
GridView :
android:orientation="vertical"
2M
tools:context=".MainActivity">
ImageView
<ListView : 2M
android:id="@+id/sample_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>

<GridView
android:id="@+id/gridview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnWidth="50dp"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
</GridView>

<ImageView
android:id="@+id/full_logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="@drawable/android_logo" />

</LinearLayout>
Placed image that has to be displayed in drawable folder

package in.msbte.controls_exam_ques;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListView;
Page No: 26 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

public class MainActivity extends AppCompatActivity {


String[] sampleArray = {"Item 1","Item 2","Item 3","Item 4", "Item 5"};
GridView gridView;
static final String[] alphabets = new String[]{
"A", "B", "C", "D", "E",
"F", "G", "H", "I", "J",
"K", "L", "M", "N", "O",
"P", "Q", "R", "S", "T",
"U", "V", "W", "X", "Y", "Z"
};
ArrayAdapter adapter, adapter1;

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

//List View
adapter = new ArrayAdapter<String>(this, R.layout.simple_item, sampleArray);
ListView listView = (ListView) findViewById(R.id.sample_list);
listView.setAdapter(adapter);

//Grid View
gridView = (GridView) findViewById(R.id.gridview1);
adapter1 = new ArrayAdapter<String>(this, R.layout.simple_item, alphabets);
gridView.setAdapter(adapter1);

}
}
6. Attempt any TWO of the following: 12 M

a) Develop an application to store customer's details like, customer-id, customer-name, 6M


mobile number, address, pin-code and retrieve customer information using customer-id
in SQLite databases.
(Any other relevant logic can be considered)
An activity_main.xml Layout File
s <?xml version="1.0" encoding="utf-8"?> : 1M
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" Java File :
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" Correct
android:layout_height="match_parent" Logics for
tools:context=".MainActivity">
Create
table : 1M
<TextView Insertion of
android:text="Insert Customer Details" record :
android:layout_width="wrap_content" 2M

Page No: 27 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_height="wrap_content" Retrival of
android:layout_alignParentTop="true" data : 2M
android:layout_centerHorizontal="true"
android:id="@+id/textView"
android:gravity="center"
android:textSize="20dp"
android:textColor="#000000"/>

<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="ID"
android:id="@+id/editid"
android:layout_below="@+id/textView"/>

<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:id="@+id/editname"
android:layout_below="@+id/editid"/>

<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Mobile No."
android:id="@+id/editmobile"
android:layout_below="@+id/editname"/>

<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Address"
android:lines="3"
android:id="@+id/editaddress"
android:layout_below="@+id/editmobile"/>

<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Pin Code"
android:id="@+id/editpincode"
android:layout_below="@+id/editaddress"/>
Page No: 28 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

<Button
android:text="Insert Data"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editpincode"
android:layout_centerHorizontal="true"
android:id="@+id/button" />

<TextView
android:text="Search Customer Details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
android:id="@+id/textView1"
android:gravity="center"
android:textSize="20dp"
android:layout_below="@+id/button"
android:textColor="#000000"/>

<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Enter ID"
android:id="@+id/editsearchid"
android:layout_below="@+id/textView1"/>

<Button
android:text="Search Data"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editsearchid"
android:layout_centerHorizontal="true"
android:id="@+id/button1" />
</RelativeLayout>

MainActivity.java
package in.msbte.database;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
Page No: 29 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


SQLiteDatabase sqLiteDatabaseObj;
EditText editTextID, editTextName, editMobileNo, editAddress, editPincode,
editSearchid;
String cid, cname, cmobile, caddress, cpincode, sql_query, sid;
Button EnterData, SearchData;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EnterData = (Button)findViewById(R.id.button);
SearchData = (Button)findViewById(R.id.button1);
editTextID = (EditText)findViewById(R.id.editid);
editTextName = (EditText)findViewById(R.id.editname);
editMobileNo = (EditText)findViewById(R.id.editmobile);
editAddress = (EditText)findViewById(R.id.editaddress);
editPincode = (EditText)findViewById(R.id.editpincode);
editSearchid = (EditText)findViewById(R.id.editsearchid);

EnterData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sqLiteDatabaseObj = openOrCreateDatabase("AndroidJSonDataBase",
Context.MODE_PRIVATE, null);
sqLiteDatabaseObj.execSQL("CREATE TABLE IF NOT EXISTS
AndroidJSonTable(id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, cid
VARCHAR, name VARCHAR, mobile VARCHAR, address VARCHAR, pincode
VARCHAR);");
cid = editTextID.getText().toString();
cname = editTextName.getText().toString() ;
cmobile = editMobileNo.getText().toString();
caddress = editAddress.getText().toString();
cpincode = editPincode.getText().toString();
sql_query = "INSERT INTO AndroidJSonTable (cid, name, mobile, address,
pincode) VALUES('"+cid+"', '"+cname+"', '"+cmobile+"', '"+caddress+"', '"+cpincode+"');";
sqLiteDatabaseObj.execSQL(sql_query);
Page No: 30 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Toast.makeText(getApplicationContext(), "Data Inserted Successfully",
Toast.LENGTH_LONG).show();
}
});

SearchData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sid = editSearchid.getText().toString();
Cursor cursor = sqLiteDatabaseObj.rawQuery( "select * from AndroidJSonTable
where cid="+sid+"", null );
StringBuffer buffer= new StringBuffer();
while (cursor.moveToNext())
{
String cid =cursor.getString(1);
String name =cursor.getString(2);
String mob =cursor.getString(3);
String addr =cursor.getString(4);
String pcode =cursor.getString(5);
buffer.append(cid+ " " + name + " " + mob +" " + addr +" " + pcode +"
\n");
Toast.makeText(getApplicationContext(), buffer,
Toast.LENGTH_LONG).show();
} }); } }
b) Write a program to find the direction from user's current location to MSBTE, 6M
Bandra. (Write only Java and manitest file).
(Note : Any other relevant logic to get the required output can also be considered.)
An AndroidManifest.xml Manifest
s file :2M
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" Java File :
package="com.example.msbte.google_map_currentlocationroute"> 4M

<uses-permission android:name="android.permission.INTERNET" />


<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_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/AppTheme">
Page No: 31 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
</application>
</manifest>

MainActivity.java

import android.Manifest;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.net.Uri;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
Page No: 32 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
import com.karumi.dexter.Dexter;
import com.karumi.dexter.MultiplePermissionsReport;
import com.karumi.dexter.PermissionToken;
import com.karumi.dexter.listener.DexterError;
import com.karumi.dexter.listener.PermissionRequest;
import com.karumi.dexter.listener.PermissionRequestErrorListener;
import com.karumi.dexter.listener.multi.MultiplePermissionsListener;
import java.util.List;

public class MainActivity extends AppCompatActivity implements


GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
com.google.android.gms.location.LocationListener , OnMapReadyCallback,
TaskLoadedCallback{

//variables for map and route

private GoogleMap mMap;


private MarkerOptions place1, place2;
Button getDirection;
private Polyline currentPolyline;
private MapFragment mapFragment;
private boolean isFirstTime = true;

//variables for current location


private static final String TAG = "MainActivity";

private TextView tvLocation;


private GoogleApiClient mGoogleApiClient;
private Location mLocation;
private LocationRequest mLocationRequest;
private com.google.android.gms.location.LocationListener listener;
private long UPDATE_INTERVAL = 2 * 1000; /* 10 secs */
private long FASTEST_INTERVAL = 2000; /* 2 sec */

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

//code for getting current location


requestMultiplePermissions();
tvLocation = (TextView) findViewById((R.id.tv));
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}

Page No: 33 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
//code for drawing route

@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.clear();
Log.d("mylog", "Added Markers");
mMap.addMarker(place1);
mMap.addMarker(place2);

CameraPosition googlePlex = CameraPosition.builder()


.target(new LatLng(22.7739,71.6673))
.zoom(7)
.bearing(0)
.tilt(45)
.build();

mMap.animateCamera(CameraUpdateFactory.newCameraPosition(googlePlex), 5000,
null);
}

private String getUrl(LatLng origin, LatLng dest, String directionMode) {


// Origin of route
String str_origin = "origin=" + origin.latitude + "," + origin.longitude;
// Destination of route
String str_dest = "destination=" + dest.latitude + "," + dest.longitude;
// Mode
String mode = "mode=" + directionMode;
// Building the parameters to the web service
String parameters = str_origin + "&" + str_dest + "&" + mode;
// Output format
String output = "json";
// Building the url to the web service
String url = "https://maps.googleapis.com/maps/api/directions/" + output + "?" +
parameters + "&key=" + getString(R.string.google_maps_key);
return url;
}

@Override
public void onTaskDone(Object... values) {
if (currentPolyline != null)
currentPolyline.remove();
currentPolyline = mMap.addPolyline((PolylineOptions) values[0]);
}

//runtime permission method

private void requestMultiplePermissions(){


Dexter.withActivity(this)
Page No: 34 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
.withPermissions(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION )
.withListener(new MultiplePermissionsListener() {
@Override
public void onPermissionsChecked(MultiplePermissionsReport report) {
// check if all permissions are granted
if (report.areAllPermissionsGranted()) {
Toast.makeText(getApplicationContext(), "All permissions are granted by
user!", Toast.LENGTH_SHORT).show();
}

// check for permanent denial of any permission


if (report.isAnyPermissionPermanentlyDenied()) {
// show alert dialog navigating to Settings
openSettingsDialog();
}
}

@Override
public void onPermissionRationaleShouldBeShown(List<PermissionRequest>
permissions, PermissionToken token) {
token.continuePermissionRequest();
}
}).
withErrorListener(new PermissionRequestErrorListener() {
@Override
public void onError(DexterError error) {
Toast.makeText(getApplicationContext(), "Some Error! ",
Toast.LENGTH_SHORT).show();
}
})
.onSameThread()
.check();
}

private void openSettingsDialog() {


AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Required Permissions");
builder.setMessage("This app require permission to use awesome feature. Grant them in
app settings.");
builder.setPositiveButton("Take Me To SETTINGS", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
Intent intent = new
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", getPackageName(), null);
Page No: 35 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
intent.setData(uri);
startActivityForResult(intent, 101);
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}

//methods for getting current location


@Override
public void onConnected(Bundle bundle) {
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
return;
}

startLocationUpdates();
mLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if(mLocation == null){
startLocationUpdates();
}
if (mLocation != null) {
// mLatitudeTextView.setText(String.valueOf(mLocation.getLatitude()));
//mLongitudeTextView.setText(String.valueOf(mLocation.getLongitude()));
} else {
Toast.makeText(this, "Location not Detected", Toast.LENGTH_SHORT).show();
} }

@Override
public void onConnectionSuspended(int i) {
Log.i(TAG, "Connection Suspended");
mGoogleApiClient.connect();
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.i(TAG, "Connection failed. Error: " + connectionResult.getErrorCode());
}
@Override
protected void onStart() {
super.onStart();
if (mGoogleApiClient != null) {
Page No: 36 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
mGoogleApiClient.connect();
} }

@Override
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
} }

protected void startLocationUpdates() {


// Create the location request
mLocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(UPDATE_INTERVAL)
.setFastestInterval(FASTEST_INTERVAL);
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,
mLocationRequest, this);
}

@Override
public void onLocationChanged(Location location) {

String msg = "Updated Location: " +


Double.toString(location.getLatitude()) + "," +
Double.toString(location.getLongitude());

tvLocation.setText(String.valueOf(location.getLatitude() +"
"+String.valueOf(location.getLongitude())));
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();

if(isFirstTime){
//code to draw path on map

getDirection = findViewById(R.id.btnGetDirection);
getDirection.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new FetchURL(MainActivity.this).execute(getUrl(place1.getPosition(),
place2.getPosition(), "driving"), "driving");
}
});
Page No: 37 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

place1 = new MarkerOptions().position(new LatLng(location.getLatitude(),


location.getLongitude())).title("Location 1");
place2 = new MarkerOptions().position(new
LatLng(19.021824,72.8662016)).title("MSBTE");
mapFragment = (MapFragment)
getFragmentManager().findFragmentById(R.id.mapNearBy);
mapFragment.getMapAsync(this);
isFirstTime = false;
} }}
c) Develop a simple calculator using relative layout. 6M

An activity_main.xml Use of
s <?xml version="1.0" encoding="utf-8"?> Relative
<RelativeLayout Layout
with
xmlns:android="http://schemas.android.com/apk/res/android"
appropriat
xmlns:app="http://schemas.android.com/apk/res-auto" e attributes
xmlns:tools="http://schemas.android.com/tools" : 3M
android:layout_width="match_parent"
android:layout_height="match_parent" Logic for
simple
tools:context=".MainActivity">
calculator
with basic
<TextView arithmetic
android:id="@+id/heading" operations
android:layout_width="wrap_content" : 3M
android:layout_height="wrap_content"
android:text=" Calculator"
android:layout_centerHorizontal="true"
android:textSize="30dp" />

<EditText
android:id="@+id/num1"
android:layout_below="@+id/heading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Number 1"
android:inputType="number" />

<EditText
android:id="@+id/num2"
android:layout_below="@+id/num1"
android:hint="Enter Number 2"
android:layout_width="match_parent"
android:layout_height="wrap_content"

Page No: 38 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:inputType="number" />

<TextView
android:id="@+id/result"
android:layout_below="@+id/num2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:text="Result" />

<Button
android:id="@+id/sum"
android:layout_below="@id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="+" />

<Button
android:id="@+id/sub"
android:layout_below="@id/result"
android:layout_toRightOf="@id/sum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="-" />

<Button
android:id="@+id/div"
android:layout_below="@id/result"
android:layout_toRightOf="@id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="/" />

<Button
android:id="@+id/mul"
android:layout_below="@id/result"
android:layout_toRightOf="@id/div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Page No: 39 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_marginLeft="10dp"
android:text="x"/>
</RelativeLayout>

MainActivity.java
package in.msbte.calculator;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
public EditText e1, e2;
Button add, sub , mul, div;
TextView t1;
int num1, num2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1 = (EditText) findViewById(R.id.num1);
e2 = (EditText) findViewById(R.id.num2);
t1 = (TextView) findViewById(R.id.result);
add = (Button) findViewById(R.id.sum);
mul = (Button) findViewById(R.id.mul);
div = (Button) findViewById(R.id.div);
sub = (Button) findViewById(R.id.sub);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
num1 = Integer.parseInt(e1.getText().toString());
num2 = Integer.parseInt(e2.getText().toString());
int sum = num1 + num2;
t1.setText(Integer.toString(sum));
}
});
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
num1 = Integer.parseInt(e1.getText().toString());
num2 = Integer.parseInt(e2.getText().toString());
int sum = num1 - num2;
Page No: 40 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
t1.setText(Integer.toString(sum));
}
});
mul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
num1 = Integer.parseInt(e1.getText().toString());
num2 = Integer.parseInt(e2.getText().toString());
int sum = num1 * num2;
t1.setText(Integer.toString(sum));
}
});
div.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
num1 = Integer.parseInt(e1.getText().toString());
num2 = Integer.parseInt(e2.getText().toString());
int sum = num1 / num2;
t1.setText(Integer.toString(sum));
}
});
}
}

Page No: 41 | 41
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
SUMMER – 2022 EXAMINATION
Subject Name: Mobile Application Development Model Answer Subject Code: 22617
Important Instructions to examiners: XXXXX
1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme.
2) The model answer and the answer written by candidate may vary but the examiner may try to assess the
understanding level of the candidate.
3) The language errors such as grammatical, spelling errors should not be given more Importance (Not applicable for
subject English and Communication Skills.
4) While assessing figures, examiner may give credit for principal components indicated in the figure. The figures
drawn by candidate and model answer may vary. The examiner may give credit for any equivalent figure drawn.
5) Credits may be given step wise for numerical problems. In some cases, the assumed constant values may vary and
there may be some difference in the candidate’s answers and model answer.
6) In case of some questions credit may be given by judgement on part of examiner of relevant answer based on
candidate’s understanding.
7) For programming language papers, credit may be given to any other program based on equivalent concept.
8) As per the policy decision of Maharashtra State Government, teaching in English/Marathi and Bilingual (English +
Marathi) medium is introduced at first year of AICTE diploma Programme from academic year 2021-2022. Hence if
the students in first year (first and second semesters) write answers in Marathi or bilingual language (English
+Marathi), the Examiner shall consider the same and assess the answer based on matching of concepts with
model answer.

Q. Su Answer Marking
No b Scheme
. Q. Note: As Android programs contain many of the generated code statements from IDE,
N. while assessing such answers correct logical steps taken to obtain the required output
can be considered.

1 Attempt any FIVE of the following: 10 M

a) List any four features of Android operating system. 2M

An Features of Android Operating System: (Any four, ½


s 1)Storage M for one
2)Multitasking feature)
3)Web Browser
4)Open Source
5)Accessibility
6)Media Support
7)Streaming Media Support
8)Voice Based Features
9)Multitouch
10)External Storage
11)Video Calling
12)Handset Layout
13)Google cloud Messaging
14)WiFi Direct
b) Define Dalvik Virtual Machine (DVM). 2M

Page No: 1 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
An Dalvik Virtual Machine is a register-based machine that compiles byte code to get dex (Correct
s code and that ensures that a device can run multiple instances efficiently. definition
2 M)
c) List any four folders from directory structure of Android project and 2M
elaborate in one line.
An Folders from directory structure: (List of
s 1)app: The App folder contains three subfolders (manifests, java and res) that make up names of any
our application. four folders :
They are divided so that it should be fairly easy to determine which resources go in which 1 M and
folder. elaboration
2)Manifest: This is where we would put our manifest files. Most Android apps have in one line
single manifest file. But an app may have several manifest files due to application
:1 M)
versioning, or for supporting specific hardware.
3)Java: This is the folder in our project where we will be storing all of the source code
files written in Java programming language.
4)res: It contains folders that help us to separate and sort the resources of our application.
Resources
basically mean all the needed files except the source code.
5)drawable: The drawable folder contains graphics that can be drawn to the screen.
6)layout: The layout folder contains XML files used for your layouts. These file are used
to set up the layout for your Activity and is used for basic alignment of your layouts,
components, widgets, and similar
resources that are used for the UI of your application.
7)mipmap : The mipmap folder contains the launcher icon files for the app. A launcher
icon is a graphic that
represents your app to users.
8)values: The values folder contains XML files that contain simple values, such as
strings, integers, and colors.
The values folder is used to keep track of the values we will be using in our application.

d) List any four attributes of check box. 2M

An 1)id (Any four


s 2)checked attribute, ½
3)gravity M for each)
4)text
5)text color
6)text size
7)text style
8)background
9)padding
e) Draw diagram of activity life cycle. 2M

Page No: 2 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
An (2 M for
s correct
diagram)

f) State syntax to display built in zoom control. 2M

An a) Built in Zoom control in Google map can be displayed with : Correct


s Syntax : 2
UiSettings.setZoomControlsEnabled(true); M)
OR

b) In case, while display Google map by intent, default zoom level can be given in
the form of data as
geo:latitude,longitude?z=zoom
where lat and lag are for location and zoom level is to set initial zoom level which
Page No: 3 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
ranges from 0 to 21.

OR

c) In any normal activity, ZoomControl can be displayed as component by following


syntax :
ZoomControl zoomControls = (ZoomControls) findViewById(R.id.simpleZoomControl);
zoomControls.show()
g) Name two classes used to play audio and video in Android. 2M

An 1) MediaPlayer (Any two


s class names
2) MediaController 1 M each)

3) AudioManager

2. Attempt any THREE of the following: 12 M

a) Describe Android architecture with diagram. 4M

Page No: 4 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
An Diagram: 2M
s Explanation:
2M

1. Applications:

• The top layer of android architecture is Applications. The native and third party
applications like Contacts, Email, Music, Gallery, Clock, Games, etc. whatever we will
build those will be installed on this layer only.

• The application layer runs within the Android run time using the classes and services
made available from the application framework.

2. Application Framework:

• The Application Framework provides the classes used to create an Android application.
It also provides a generic abstraction for hardware access and manages the user interface

Page No: 5 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
and application resources.

• It basically provides the services through which we can create the particular class and
make that class helpful for the Applications creation.

• The application framework includes services like telephony service, location services,
notification. manager, NFC service, view system, etc. which we can use for application
development as per our requirements.

3. Android Runtime:

• Android Runtime environment is an important part of Android rather than an internal


part and it contains a components like core libraries and the Dalvik virtual machine.

• The Android run time is the engine that powers our applications along with the libraries
and it forms the basis for the application framework.

(i) Dalvik Virtual Machine (DVM) is a register-based virtual machine like Java Virtual
Machine (JVM).

It is specially designed and optimized for android to ensure that a device can run multiple

instances efficiently. It relies on the Linux kernel for threading and low-level memory

management.

(ii) The core libraries in android runtime will enable us to implement an android
applications using standard JAVA programming language.

4. Platform Libraries:

• The Platform Libraries includes various C/C++ core libraries and Java based libraries
such as SSL, libc, Graphics, SQLite, Webkit, Media, Surface Manger, OpenGL etc. to
provide a support for android development.

• Following are the summary details of some core android libraries available for android
development.

• Media library for playing and recording an audio and video formats

(i) The Surface manager library to provide a display management

(ii) SGL and OpenGL Graphics libraries for 2D and 3D graphics

(iii) SQLite is for database support and FreeType for font support

(iv) Web-Kit for web browser support and SSL for Internet security.

5. Linux Kernel:

Page No: 6 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
• Linux Kernel is a bottom layer and heart of the android architecture. It is heart of
Android

architecture that exists at the root of android architecture and contains all the low-level
device

drivers for the various hardware components of an Android device.

• Linux Kernel is responsible fro device drivers, power management, memory


management, device management and resource access. It manage all the drivers such as
display drivers, camera drivers,

Bluetooth drivers, audio drivers, memory drivers, etc. which are mainly required for the
android device during the runtime.

• The Linux Kernel will provides an abstraction layer between the device hardware and
the remainder of the stack. It is responsible for memory management, power
management, device management, resource access, etc.

b) Differentiate between DVM and JVM. 4M

An Any 4 points
s of
DVM (Dalvik Virtual Machine) JVM (Java Virtual Machine) differences :
It is Register based which is designed to run It is Stack based. 1 M each
on low memory.
DVM uses its own byte code and runs the JVM uses java byte code and runs
“.Dex” file. From Android 2.2 SDK Dalvik “.class” file having JIT (Just In Time).
has got a Just in Time compiler
DVM has been designed so that a device A single instance of JVM is shared
can run multiple instances of the VM with multiple applications.
efficiently. Applications are given their own
instance.
DVM supports the Android operating JVM supports multiple operating
system only. systems.
There is a constant pool for every It has a constant pool for every class.
application.
Here the executable is APK. Here the executable is JAR.

c) List and elaborate steps to deploy an Android application on Google play 4M


store.

An Steps to deploy and Android Application on Google Play Store: (List 1 M


s and
Step 1: Make a Developer Account Elaboration 3
Step 2: Plan to Sell? Link Your Merchant Account M)
Step 3: Create an App
Step 4: Prepare Store Listing

Page No: 7 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Step 5: Upload APK to an App Release
Step 6: Provide an Appropriate Content Rating
Step 7: Set Up Pricing & Distribution
Step 8: Rollout Release to Publish Your App

Step 1: Create a Developer Account


Before you can publish any app on Google Play, you need to create a Developer Account.
You can easily sign up for one using your existing Google Account. You’ll need to pay a
one-time registration fee of $25 using your international credit or debit card. It can take
up to 48 hours for your registration to be fully processed.

Step 2: Plan to Sell? Link Your Merchant Account


If you want to publish a paid app or plan to sell in-app purchases, you need to create a
payments center profile, i.e. a merchant account. A merchant account will let you manage
your app sales and monthly payouts, as well as analyze your sales reports right in your
Play Console.

Step 3: Create an App


Now you have create an application by clicking on 'Create Application'. Here you have
to select your app’s default language from the drop-down menu and then type in a title
for your app. The title of your app will show on Google Play after you’ve published.

Step 4: Prepare Store Listing


Before you can publish your app, you need to prepare its store listing. These are all the
details that will show up to customers on your app’s listing on Google Play. You not
necessarily complete it at once , you can always save a draft and revisit it later when
you’re ready to publish.
The information required for your store listing is divided into several categories such as
Product Details containing title, short and full description of the app, Your app’s title
and description should be written with a great user experience in mind. Use the right
keywords, but don’t overdo it. Make sure your app doesn’t come across as spam-y or
promotional, or it will risk getting suspended on the Play Store.
Graphic Assets where you can add screenshots, images, videos, promotional graphics,
and icons that showcase your app’s features and functionality.
Languages & Translations, Categorization where in category can be selected to which
your app belong to. Contact Details , Privacy Policy for apps that request access to
sensitive user data or permissions, you need to enter a comprehensive privacy policy that
effectively discloses how your app collects, uses, and shares that data.

Step 5: Upload APK to an App Release


Finally upload your app, by uploading APK file. Before you upload APK, you need to
create an app release. You need to select the type of release you want to upload your first
app version to. You can choose between an internal test, a closed test, an open test, and a
production release. The first three releases allow you to test out your app among a select
Page No: 8 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
group of users before you make it go live for everyone to access.
This is a safer option because you can analyze the test results and optimize or fix your
app accordingly if you need to before rolling it out to all users.
Once you create a production release, your uploaded app version will become accessible
to everyone in the countries you choose to distribute it in and click on ‘Create release.’

Step 6: Provide an Appropriate Content Rating


If you don’t assign a rating to your app, it will be listed as ‘Unrated’. Apps that are
‘Unrated’ may get removed from Google Play.
To rate your app, you need to fill out a content rating questionnaire An appropriate
content rating will also help you get to the right audience, which will eventually improve
your engagement rates.

Step 7: Set Up Pricing & Distribution


Before you can fill out the details required in this step, you need to determine your app’s
monetization strategy. Once you know how your app is going to make money, you can go
ahead and set up your app as free or paid.
You can always change your app from paid to free later, but you cannot change a free app
to paid. For that, you’ll need to create a new app and set its price.

Step 8: Rollout Release to Publish Your App


The final step involves reviewing and rolling out your release after making sure you’ve
taken care of everything else.
Before you review and rollout your release, make sure the store listing, content rating,
and pricing and distribution sections of your app each have a green check mark next to
them.
Once you’re sure about the correctness of the details, select your app and navigate to
‘Release management’ – ‘App releases.’ You can always opt for reviews by clicking on
‘Review’ to be taken to the ‘Review and rollout release’ screen. Here, you can see if there
are any issues or warnings you might have missed out on.
Finally, select ‘Confirm rollout.’ This will also publish your app to all users in your target
countries on Google Play.
d) Describe with example, how to create a simple database in SQLite (Assume 4M
suitable data).
(Note : Any other method such as creating subclass of SQLiteOpenHelper class
and overriding and using required methods with relevant example can also be
considered)
An This procedure is by openOrCreateDatabase() Description 1
s 1. The package imported into the application is android.database.sqlite.SQLiteDatabase. M, 1 M for
2. Here the class used is SQLiteDatabase. XML file , 2
3. The method used to create the database or connect to the database is M for Java
openOrCreateDatabse() method. File)
Program:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
Page No: 9 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:text="Create SQLite Database"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:id="@+id/button" />
</RelativeLayout>

MainActivity.java

package in.edu.vpt.insertusingasync;
import android.app.ProgressDialog;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;;

public class MainActivity extends AppCompatActivity {


SQLiteDatabase sqLiteDatabaseObj;
Button EnterData;

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

createData = (Button)findViewById(R.id.button);
createData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sqLiteDatabaseObj = openOrCreateDatabase("AndroidJSonDataBase",
Context.MODE_PRIVATE, null);
} });
}

3. Attempt any THREE of the following: 12 M

a) Write down the steps to install and configure Android studio. 4M

An Step 1: Go to https://developer.android.com/android-studio/download to get the Android (4 M for


Studio executable or zip file. appropriate
Page No: 10 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
s Step 2: steps)
● Click on the Download Android Studio Button.
● Click on the “I have read and agree with the above terms and conditions”
checkbox followed by the download button
● Click on the Save file button in the appeared prompt box and the file will start
downloading.
Step 3: After the downloading has finished, open the file from downloads and will
prompt the following dialog box. Click on next. In the next prompt, it’ll ask for a path for
installation. Choose a path and hit next.
Step 4: It will start the installation, and once it is completed, it will be like the image
shown below.
Step 5: Once “Finish” is clicked, it will ask whether the previous settings need to be
imported [if the android studio had been installed earlier], or not. It is better to choose the
‘Don’t import Settings option’. Click the OK button.
Step 6: This will start the Android Studio. Meanwhile, it will be finding the available
SDK components.
Step 7: After it has found the SDK components, it will redirect to the Welcome dialog
box.
Choose Standard and click on Next. Now choose the theme, whether the Light theme or
the Dark one. The light one is called the IntelliJ theme whereas the dark theme is
called Darcula. Choose as required. Click on the Next button.
Step 8: Now it is time to download the SDK components. Click on Finish. Components
begin to download let it complete. The Android Studio has been successfully
configured. Now it’s time to launch and build apps. Click on the Finish button to launch
it.
Step 9: Click on Start a new Android Studio project to build a new app.

b) State syntax to create Text View and Image button with any two attributes of each. 4M

An Text View: (Syntax of


s Syntax : TextView
<TextView and
android:id="@+id/textView1" ImageButton
android:layout_width="<width value>” : 1 M each
android:layout_height="<height_value>" Any two
android:text="<text to be displayed>"/> appropriate
Attributes/Properties of TextView: attributes of
● id: Supply an identifier name of this view, to later retrieve it with each : 1/2 M
View.findViewByID() or Activity.findViewById() each)
● alpha: alpha property of the view as a value between 0 (entirely transparent) and
1(Completely Opaque). [flag]
● auto link: Controls whether links such as urls and email addresses are
automatically found and converted to clickable links.[flag]
● 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

Page No: 11 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
● text: text attribute is used to set the text in a text view. We can set the text in xml as
well as in the java class.
● textColor: textColor attribute is used to set the text color of a text view. Color
value is in the form of “#argb”, “#rgb”, “#rrggbb”, or “#aarrggbb”.
● textSize: textSize attribute is used to set the size of text of a text view. We can set
the text size in sp(scale independent pixel) or dp(density pixel).
● textStyle: textStyle attribute is used to set the text style of a text view. The possible
text styles are bold, italic and normal. If we need to use two or more styles for a text
view then “|” operator is used for that.
● background: background attribute is used to set the background of a text view. We
can set a color or a drawable in the background of a text view.
● padding: padding attribute is used to set the padding from left, right, top or bottom.
In above example code of background we also set the 10dp padding from all the
sides of text view.

ImageButton:
Syntax :
<ImageButton
android:id="@+id/imageButton"
android:layout_width="<width value>"
android:layout_height="<height value>"
app:srcCompat="<image source from drawable folder "/>
Attributes/Properties of ImageButton:

● id: id is an attribute used to uniquely identify a image button. Below is the


example code in which we set the id of a image button.
● src: src is an attribute used to set a source file of image or you can say image in
your image button to make your layout look attractive.
● background: background attribute is used to set the background of an image
button. We can set a color or a drawable in the background of a Button.
● padding: padding attribute is used to set the padding from left, right, top or
bottom of the ImageButton.

c) Describe Android service life cycle along with diagram. 4M

An ● A service is an application component which runs without direst interaction with (Explanation
s the user in the background. 2 M,
● Services are used for repetitive and potentially long running operations, i.e., Diagram
Internet downloads, checking for new data, data processing, updating content 2M)
providers and the like.
● Service can either be started or bound we just need to call either startService() or
bindService() from any of our android components. Based on how our service
was started it will either be “started” or “bound”

Page No: 12 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

Service Lifecycle
1. Started
a. A service is started when an application component, such as an activity,
starts it by calling startService().
b. Now the service can run in the background indefinitely, even if the
component that started it is destroyed.
2. Bound
a. A service is bound when an application component binds to it by calling
bindService().
b. A bound service offers a client-server interface that allows components to
interact with the service, send requests, get results, and even do so across
processes with InterProcess Communication (IPC).
c. Like any other components service also has callback methods. These will
be invoked while the service is running to inform the application of its
state. Implementing these in our custom service would help you in
performing the right operation in the right state. •
d. There is always only a single instance of service running in the app. If you
are calling startService() for a single service multiple times in our

Page No: 13 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
application it just invokes the onStartCommand() on that service. Neither
is the service restarted multiple times nor are its multiple instances created
1. onCreate():
This is the first callback which will be invoked when any component starts the
service. If the same service is called again while it is still running this method
wont be invoked. Ideally one time setup and intializing should be done in this
callback.
2. onStartCommand() /startSetvice()
This callback is invoked when service is started by any component by calling
startService(). It basically indicates that the service has started and can now run
indefinetly.
3. onBind()
To provide binding for a service, you must implement the onBind() callback
method. This method returns an IBinder object that defines the programming
interface that clients can use to interact with the service.
4. onUnbind()
This is invoked when all the clients are disconnected from the service.
5. onRebind()
This is invoked when new clients are connected to the service. It is called after
onRebind
6. onDestroy()
This is a final clean up call from the system. This is invoked just before the
service is being destroyed.

d) State and elaborate the syntax of required class and methods for 4M
Geocoding.
An Geocoder: (2 M for
s explanation
A class for handling geocoding and reverse geocoding.
and syntax of
Geocoding is the process of transforming a street address or other description of a class, 2 M
location into a (latitude, longitude) coordinate. for
explanation
Reverse geocoding is the process of transforming a (latitude, longitude) coordinate into a and syntax of
(partial) address. The amount of detail in a reverse geocoded location description may any two
vary, for example one might contain the full street address of the closest building, while methods)
another might contain only a city name and postal code.

The Geocoder class requires a backend service that is not included in the core android
framework.

The Geocoder query methods will return an empty list if there no backend service in the
platform. Use the isPresent() method to determine whether a Geocoder implementation
exists.

Page No: 14 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
Syntax
Geocoder (Context context)

Constructs a Geocoder localized for the default locale.

Geocoder(Context context, Locale locale)

Constructs a Geocoder localized for the given locale.

Methods with Syntax


a. getFromLocation

Syntax

public List<Address> getFromLocation (double latitude, double longitude, int


maxResults)

public void getFromLocation (double latitude, double longitude, int maxResults,


Geocoder.GeocodeListener listener)

This method returns an array of Addresses that attempt to describe the area immediately
surrounding the given latitude and longitude. The returned addresses should be localized
for the locale provided to this class's constructor.

b. getFromLocationName
Syntax :

● public List<Address> getFromLocationName (String locationName, int


maxResults, double lowerLeftLatitude, double lowerLeftLongitude, double
upperRightLatitude, double upperRightLongitude)
● public void getFromLocationName (String locationName, int maxResults,
double lowerLeftLatitude, double lowerLeftLongitude, double
upperRightLatitude, double upperRightLongitude, Geocoder.GeocodeListener
listener)
● public void getFromLocationName (String locationName, int maxResults,
Geocoder.GeocodeListener listener)
● public List<Address> getFromLocationName (String locationName, int
maxResults)

Returns an array of Addresses that attempt to describe the named location, which may be
a place name such as "Dalvik, Iceland", an address such as "1600 Amphitheatre Parkway,
Mountain View, CA", an airport code such as "SFO", and so forth. The returned
addresses should be localized for the locale provided to this class's constructor.

c. isPresent

Syntax

Page No: 15 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

public static boolean isPresent ()

Returns true if there is a geocoder implementation present that may return results. If true,
there is still no guarantee that any individual geocoding attempt will succeed.

4. Attempt any THREE of the following: 12 M

a) Explain with example, code to create GUI using absolute layout (Assume 4M
suitable data).

An ● AbsoluteLayout is based on the simple idea of placing each control at an absolute (Explanation
s position. We specify the exact x and y coordinates on the screen for each control. 2 M,
This is not recommended for most UI development (in fact AbsoluteLayout is Example 2
currently deprecated) since absolutely positioning every element on the screen makes M)
an inflexible UI that is much more difficult to maintain.

Absolute Layout
● An Absolute Layout lets you specify exact locations (x/y coordinates) of its children.
Absolute layouts are less flexible and harder to maintain than other types of layouts
without absolute positioning. AbsoluteLayout is based on the simple idea of placing
each control at an absolute position.
● We specify for the exact x and y corodinates on the screen for every control. So this
recommended for most UI development (in fact Absolute Layout is currentaly
deprecated)since absolute positioning of every element on the screen makes an
inflexible UI that is much more difficult to maintain.
● Consider what happens if a control needs to be added to the user interface UI, we
would have to change the position of every single element that is shifted by the new
control. This allows child views to be positioned at specified X and Y coordinates
within the containing layout view.

Example
(Note :Any other relevant example using absoluteLayout can be considered, No java
code is expected)

Page No: 16 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
activity_main.xml

<AbsoluteLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_x="110px"
android:layout_y="110px"
android:text="User Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_x="250px"
android:layout_y="80px"
android:width="100px"
android:layout_width="200dp"
android:layout_height="wrap_content" />
<TextView
android:layout_x="110px"
android:layout_y="200px"
android:text="Password"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_x="250px"
android:layout_y="150px"
android:width="100px"
android:layout_width="200dp"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Log In"
android:layout_x="300px"
android:layout_y="300px"/>
</AbsoluteLayout>

b) Write a program to demonstrate Date and Time picker. 4M


(Note: Consider the appropriate XML file. All attributes are not required.
In java file all imports are not expected. Different relevant logic/code can be
considered.)
An activity_main.xml (2M for
s <?xml version="1.0" encoding="utf-8"?> correct use
<androidx.constraintlayout.widget.ConstraintLayout of Date
xmlns:android="http://schemas.android.com/apk/res/android" picker
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" 2M for
android:layout_width="match_parent"
Page No: 17 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_height="match_parent" correct use
tools:context=".MainActivity"> of
TimePicker)
<TextView
android:id="@+id/tvDate"
android:layout_width="149dp"
android:layout_height="46dp"
android:layout_marginEnd="224dp"
android:layout_marginBottom="312dp"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/btnDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="96dp"
android:layout_marginBottom="312dp"
android:text="Set Date"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="DuplicateClickableBoundsCheck" />

<DatePicker
android:id="@+id/dtpcker"
android:layout_width="314dp"
android:layout_height="293dp"
android:layout_marginBottom="368dp"
android:datePickerMode="spinner"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.36"
app:layout_constraintStart_toStartOf="parent" />

<TimePicker
android:id="@+id/timepcker"
android:layout_width="184dp"
android:layout_height="195dp"
android:layout_marginEnd="132dp"
android:layout_marginBottom="108dp"
android:timePickerMode="spinner"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<TextView
android:id="@+id/tvTime"
android:layout_width="130dp"
Page No: 18 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_height="56dp"
android:layout_marginEnd="232dp"
android:layout_marginBottom="40dp"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/btnTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="104dp"
android:layout_marginBottom="48dp"
android:text="Set Time"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.datepickereg;
import androidx.appcompat.app.AppCompatActivity;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
import java.util.Calendar;

public class MainActivity extends AppCompatActivity {


TextView tvDate,tvTime;
DatePicker dtpcker;
TimePicker timepcker;
Button b1,b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvDate=findViewById(R.id.tvDate);
tvTime=findViewById(R.id.tvTime);
b1=findViewById(R.id.btnDate);
b2=findViewById(R.id.btnTime);
dtpcker=findViewById(R.id.dtpcker);
timepcker=findViewById(R.id.timepcker);
b1.setOnClickListener(new View.OnClickListener() {
@Override
Page No: 19 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
public void onClick(View view) {
tvDate.setText("Date : "+dtpcker.getDayOfMonth()+"-
"+dtpcker.getMonth()+"-"+dtpcker.getYear());
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

tvTime.setText(timepcker.getCurrentHour()+":"+timepcker.getCurrentMinute());
}
});
}
}
c) Describe multimedia framework of Android with diagram. 4M

An ● The android multimedia system includes multimedia applications, multimedia (Explanation


s frameworks, OpenCore engine and hardware abstract for audio/video input/output 2M,
devices. And the goal of the android multimedia framework is to provide a
Diagram 2
reliable interface for java services. The multimedia framework consists of several
M)
core dynamic libraries such as libmediajni, libmedia, libmediaplayservice and so
on.
● Java classes call the Native C library Libmedia through Java JNI(Java Native
Interface). Libmedia library communications with Media Server guard process
through Android’s Binder IPc (inter process communication) mechanism.
● Media Server process creates the corresponding multimedia service according to
the Java multimedia applications.
● The whole communication between Libmedia and Media Server forms a
Client/Server model

Android Multimedia Framework Architecture

Page No: 20 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
● Typical video/audio data stream works in Android as follows. Particularly, Java
applications first set the URI of the media (from file or network) to PVPlayer
through Java framework, JNI and Native C. In this process, there are no data
stream flows.
● Then PVPlayer processes the media data stream with the steps: demux the media
data to separate video/audio data stream, decode video/audio data, sync
video.audio time, send the decoded data out.
● The below is the description of media codec/format, container and network
protocol supported by the Android platform.
1. Container: The audio file format is a file for storing digital audio data on
a system. This data can be manipulated to reduce the size or change the
quality of the audio. It is a kind of container to store audio information.
2. Audio Format: Any format or codec can be used including the ones
provided by Android or those which are specific devices. However it is
recommended to use the specified file formats as per devices.
3. Network Protocol: Protocols such as RTSP, HTTP,HTTPS are supported
in audio and video playback.

d) Discuss developer console with at least four features 4M

An ● Google Play Developer Console is the platform that Google provides for Google (Any 4
s Play and Android developers to publish their apps. relevant
● The Google Play Developer console allows app developers and marketers to features 1M
better understand how their apps are performing in terms of growth, technical each )
performance such as crashes or display issues, and financials.
● The console offers acquisition reports and detailed analysis which can help app
devs find out how well an app is really performing.
● The platform is important as it provides developers with access to first party data
(trustworthy information collected about an app’s audience that comes straight
from Google Play) that highlights the real performance of an app.
● It shows the number of impressions an app listing receives and the number of
Installs an app receives from different sources over time.

e) Write a program to demonstrate declaring and using permissions with any 4M


relevant example.
An Permission declaring : 4 M for any
s correct
The permissions are declared in AndroidManifest.xml file under Manifest folder. program
Permission can be set by <uses-permission> tag in AndroidManifest.xml.
demonstratin
Example:
Following example is to send SMS. g declaration
(Note: Any other relevant example which uses permissions can be considered) and use of
permissions
AndroidManifest.xml

Page No: 21 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
<uses-permission android:name="android.permission.SEND_SMS"/>

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="81dp"
android:layout_height="41dp"
android:layout_marginEnd="268dp"
android:layout_marginBottom="576dp"
android:text="To :"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

<TextView
android:id="@+id/textView2"
android:layout_width="70dp"
android:layout_height="43dp"
android:layout_marginEnd="276dp"
android:layout_marginBottom="512dp"
android:text="Sms Text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<EditText
android:id="@+id/etPhno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp"
android:layout_marginBottom="572dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<EditText
android:id="@+id/etmsg"
android:layout_width="193dp"
android:layout_height="51dp"
android:layout_marginEnd="56dp"
android:layout_marginBottom="504dp"
Page No: 22 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="SpeakableTextPresentCheck" />

<Button
android:id="@+id/btnSms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="156dp"
android:layout_marginBottom="400dp"
android:text="SEND SMS"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.testreceivesms;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


EditText et1,et2;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=findViewById(R.id.etPhno);
et2=findViewById(R.id.etmsg);
b1=findViewById(R.id.btnSms);
if(ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.SEN
D_SMS)!=
PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(MainActivity.this,new
String[]{Manifest.permission.SEND_SMS},100);
}
b1.setOnClickListener(new View.OnClickListener() {
Page No: 23 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
@Override
public void onClick(View v) {
try {
String phno= et1.getText().toString();
String msg=et2.getText().toString();
SmsManager smsManager= SmsManager.getDefault();
smsManager.sendTextMessage(phno,null,msg,null,null);
Toast.makeText(MainActivity.this,"Sms sent successfully",
Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(MainActivity.this,"Sms failed to send... try again",
Toast.LENGTH_LONG).show();
}
}
});
}
}
5. Attempt any TWO of the following: 12 M

a) Write a program to convert temperature from celcius to farenhite and vice versa 6M
using Toggle button. (Design UI as per your choice. Write XML and java file)
(Note: Consider the appropriate XML file. All attributes are not required.
In java file all imports are not expected. Different relevant logic/code can be
considered.)
An activity_main.xml XML file:
s <?xml version="1.0" encoding="utf-8"?> 2M
<RelativeLayout 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" Java Code:
android:layout_width="match_parent"
4M
android:layout_height="match_parent"
tools:context=".MainActivity">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edittext"
android:hint="Enter the temp"/>

<ToggleButton
android:id="@+id/togglebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/edittext"
android:layout_marginTop="35dp"
android:textOff="F to C"
android:textOn="C to F" />
Page No: 24 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/togglebutton"
android:layout_marginTop="56dp" />
</RelativeLayout>
MainActivity.java
package com.example.p1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.ToggleButton;

public class MainActivity extends AppCompatActivity {


Button b1;
EditText et;
ToggleButton tb;
Double a;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et=findViewById(R.id.edittext);
b1=findViewById(R.id.button);
tb=findViewById(R.id.togglebutton);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(tb.isChecked())
{
a=Double.parseDouble(String.valueOf(et.getText()));
Double b=a*9/5+32;
String r=String.valueOf(b);
Toast.makeText(MainActivity.this,r+"°F",Toast.LENGTH_SHORT).show();
}
else
{
a=Double.parseDouble(String.valueOf(et.getText()));
Double b=a-32;
Double c=b*5/9;
String r=String.valueOf(c);

Toast.makeText(MainActivity.this,r+"°C",Toast.LENGTH_SHORT).show();
}
Page No: 25 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
}
});
}
}

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


(Note: Consider the appropriate XML file. All attributes are not required.
In java file all imports are not expected. Different relevant logic/code can be
considered.)
An activity_main.xml XML file:
s 2M
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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" Java Code:
android:layout_width="match_parent" 4M
android:layout_height="match_parent"
android:padding="40dp"
android:orientation="horizontal"
tools:context=".MainActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CAMERA"
android:id="@+id/text"
android:textSize="20dp"
android:gravity="center"/>

<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_marginTop="81dp"
android:src="@drawable/rose"/>

<Button
android:id="@+id/photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/image"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:text="TAKE PHOTO" />

</RelativeLayout>

Page No: 26 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

MainActivity.java

package com.example.ifcdiv;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {


Button b1;
ImageView imageView;
int CAMERA_REQUEST=1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

b1=findViewById(R.id.photo);
imageView=findViewById(R.id.image);

b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);


startActivityForResult(i,CAMERA_REQUEST);
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent
data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode==CAMERA_REQUEST)
{
Bitmap image= (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(image);
}
}
}

Page No: 27 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
c) Develop and application to send and receive SMS (Design minimal UI as per 6M
your choice. Write XML, java and manifest file)
(Note: Consider appropriate XML file. All attributes are not required. In java
file all imports are not expected. Different relevant login/code can be considered.
Statements showing permissions can be written under AndroidManifest.xml)
An Permissions and <receiver> tag required in AndroidManifest.xml XML file:
s <uses-permission android:name="android.permission.RECEIVE_SMS" /> 1M
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/> Manifest
<uses-permission android:name="android.permission.WRITE_SMS"/> File:1M
Java Code:
<receiver 4M
android:name=".SmsReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="81dp"
android:layout_height="41dp"
android:layout_marginEnd="268dp"
android:layout_marginBottom="576dp"
android:text="To :"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

<TextView
android:id="@+id/textView2"
android:layout_width="70dp"
android:layout_height="43dp"
android:layout_marginEnd="276dp"
android:layout_marginBottom="512dp"
android:text="Sms Text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
Page No: 28 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________

<EditText
android:id="@+id/etPhno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp"
android:layout_marginBottom="572dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<EditText
android:id="@+id/etmsg"
android:layout_width="193dp"
android:layout_height="51dp"
android:layout_marginEnd="56dp"
android:layout_marginBottom="504dp"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="SpeakableTextPresentCheck" />

<Button
android:id="@+id/btnSms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="156dp"
android:layout_marginBottom="400dp"
android:text="SEND SMS"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.testreceivesms;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

Page No: 29 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
public class MainActivity extends AppCompatActivity {
SmsReceiver sms= new SmsReceiver();
EditText et1,et2;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=findViewById(R.id.etPhno);
et2=findViewById(R.id.etmsg);
b1=findViewById(R.id.btnSms);
if(ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.SEN
D_SMS)!=
PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(MainActivity.this,new
String[]{Manifest.permission.SEND_SMS},100);
}
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String phno= et1.getText().toString();
String msg=et2.getText().toString();
SmsManager smsManager= SmsManager.getDefault();
smsManager.sendTextMessage(phno,null,msg,null,null);
Toast.makeText(MainActivity.this,"Sms sent successfully",
Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(MainActivity.this,"Sms failed to send... try again",
Toast.LENGTH_LONG).show();
}
}
});
}
@Override
protected void onStart() {
super.onStart();
IntentFilter filter=new
IntentFilter("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(sms,filter);
}

@Override
protected void onStop() {
super.onStop();
unregisterReceiver(sms);
Page No: 30 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
}
}

SmsReceiver.java
package com.example.testreceivesms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class SmsReceiver extends BroadcastReceiver {


SmsReceiver(){}
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();

if (bundle != null) {
// Retrieve the SMS Messages received
Object[] sms = (Object[]) bundle.get("pdus");

// For every SMS message received


for (int i=0; i < sms.length; i++) {
// Convert Object array
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);

String phone = smsMessage.getOriginatingAddress();


String message = smsMessage.getMessageBody().toString();

Toast.makeText(context, “Received from “+ phone + ": " + message,


Toast.LENGTH_SHORT).show();
}
}
}
}

6. Attempt any TWO of the following: 12 M

a) Write a program to implement Android Activity Life Cycle. Use toast messages 6M
to display message through life cycle.
(Note: No XML code is required. In java file all imports are not expected.)
An package com.example.p1; Use of any 6
s import androidx.appcompat.app.AppCompatActivity; methods of
import android.os.Bundle; Activity life
import android.widget.Toast; cycle : 1 M
public class MainActivity extends AppCompatActivity { each
@Override
Page No: 31 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(getApplicationContext(),"Activity
created",Toast.LENGTH_LONG).show();
}

@Override
protected void onStart() {
super.onStart();
Toast.makeText(getApplicationContext(),"Activity
Started",Toast.LENGTH_LONG).show();
}

@Override
protected void onStop() {
super.onStop();
Toast.makeText(getApplicationContext(),"Activity
Stop",Toast.LENGTH_LONG).show();
}

@Override
protected void onDestroy() {
super.onDestroy();
Toast.makeText(getApplicationContext(),"Activity
Destroy",Toast.LENGTH_LONG).show();
}

@Override
protected void onPause() {
super.onPause();
Toast.makeText(getApplicationContext(),"Activity
Pause",Toast.LENGTH_LONG).show();
}
@Override
protected void onRestart() {
super.onResume();
Toast.makeText(getApplicationContext(),"Activity
Restart",Toast.LENGTH_LONG).show();

@Override
protected void onResume() {
super.onResume();
Toast.makeText(getApplicationContext(),"Activity
Resume",Toast.LENGTH_LONG).show();
}
}
b) Develop an application to display Google map with user's current location. 6M
(Note : Consider the appropriate XML file. All attributes are not required.
Page No: 32 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
In java file all imports are not expected. Different relevant logic/code can be
considered.)
An act ivity_main.xml XML file:
s <?xml version="1.0" encoding="utf-8"?> 1M
<RelativeLayout 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" Java Code:
android:layout_width="match_parent" 5M
android:layout_height="match_parent"
tools:context=".MainActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/google_map"
android:name="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>

MainActivity.Java

package com.example.location;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;

public class MainActivity extends FragmentActivity implements OnMapReadyCallback


{
Location currentlocation;
Page No: 33 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
FusedLocationProviderClient fusedLocationProviderClient;
private static final int REQUEST_CODE = 101;

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

fusedLocationProviderClient =
LocationServices.getFusedLocationProviderClient(this);
fetchLastLocation();
}

private void fetchLastLocation() {

if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,new
String[]{Manifest.permission.ACCESS_FINE_LOCATION},REQUEST_CODE);
return;
}
Task<Location> task = fusedLocationProviderClient.getLastLocation();
task.addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if(location!=null)
{
currentlocation=location;

Toast.makeText(getApplicationContext(),currentlocation.getLatitude()+""+current
location.getLongitude(), Toast.LENGTH_SHORT).show();
SupportMapFragment supportMapFragment =
(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.go
ogle_map);
supportMapFragment.getMapAsync(MainActivity.this);
}
}
});
}
Page No: 34 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
@Override
public void onMapReady(@NonNull GoogleMap googleMap) {
LatLng latLng=new
LatLng(currentlocation.getLatitude(),currentlocation.getLongitude());
MarkerOptions markerOptions=new MarkerOptions().position(latLng)
.title("I am Here");
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,5));
googleMap.addMarker(markerOptions);

}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[]
permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case REQUEST_CODE:
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
fetchLastLocation();
}
break;
}
}
}
c) Design UI using table layout to display buttons with 0 9 numbers on it. Even display 6M
submit and clear button. When user clicks on particular buttons and later when
clicks on submit button, it should display the numbers clicked.
(Note: Consider the appropriate XML file. All attributes are not required.
In java file all imports are not expected. Different relevant logic/code can be
considered.)
An activity_main.xml XML file:
s <?xml version="1.0" encoding="utf-8"?> 3M
<TableLayout 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"
Java Code:
android:layout_width="match_parent"
3M
android:layout_height="match_parent"
android:stretchColumns="*"
tools:context=".MainActivity">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">

<Button
Page No: 35 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/button0"
android:text="0"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/button1"
android:text="1"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:text="2" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">

<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/button3"
android:text="3"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/button4"
android:text="4"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:id="@+id/button5"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">

<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="6"
android:id="@+id/button6"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="7"
Page No: 36 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
android:id="@+id/button7"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:id="@+id/button8"/>

</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="9"
android:id="@+id/button9"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Submit"
android:id="@+id/submit"/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Clear"
android:id="@+id/clear"/>
</TableRow>
</TableLayout>
(Java File)
package com.example.p1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


Button button0, button1, button2, button3, button4, button5, button6,button7,
button8, button9,submit,clear;
String a=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button0 = (Button) findViewById(R.id.button0);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
Page No: 37 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
button3 = (Button) findViewById(R.id.button3);
button4 = (Button) findViewById(R.id.button4);
button5 = (Button) findViewById(R.id.button5);
button6 = (Button) findViewById(R.id.button6);
button7 = (Button) findViewById(R.id.button7);
button8 = (Button) findViewById(R.id.button8);
button9 = (Button) findViewById(R.id.button9);
submit=(Button) findViewById(R.id.submit);
clear=(Button) findViewById(R.id.clear);
button0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

a=button0.getText().toString();
}
});
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

a=button1.getText().toString();
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

a=button2.getText().toString();
}
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

a=button3.getText().toString();
}
});
button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

a=button4.getText().toString();
}
});
button5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

a=button5.getText().toString();
Page No: 38 | 39
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
(Autonomous)
(ISO/IEC - 27001 - 2013 Certified)
__________________________________________________________________________________________________
}
});
button6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

a=button6.getText().toString();
}
});
button7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
a=button7.getText().toString();
}
});
button8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

a=button8.getText().toString();
}
});
button9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

a=button9.getText().toString();
}
});
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

Toast.makeText(getApplicationContext(),a,Toast.LENGTH_LONG).show(); }
});
}
}

Page No: 39 | 39
Mobile Application Development - 22617

Mobile Application Development (MAD)

MSBTE Sample Question Bank

Question One [2 Marks Each]


1. List any five features of Android Operating System.

Write Any Five

Features of Android:

1. Storage

2. Multitasking

3. Web Browser

4. Open Source

5. Accessibility

6. Media Support

7. Voice Based Features

8. Multitouch

9. External Storage

10. GCM

2. Define Android Virtual Devices (AVD).

• An Android Virtual Device (AVD) represents a device configuration.

• An AVD is a software that defines the characteristics of an Android Phone, tablet,


wear OS, Android TV or Automotive OS device that we want to simulate in the
Android Emulator.

• It enables us to model an actual device by calling hardware and software options


to be emulated in the Android Emulator.

1
Mobile Application Development - 22617

3. Write the directory path where images are stored while developing
Android Applications.

app/src/main/res/drawable

4. List all attributes to develop a simple button

<Button
android:id="@+id/simpleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android"/>

5. Write the syntax for Intent-Filter Tag

<intent-filter android:icon="drawable resource"


android:label="string resource"
android:priority="integer" >
. . .
</intent-filter>

6. Define services in Android Operating System.

• A service is an application component which runs without direct interaction with


the user in the background.

• Services run with a higher priority than inactive or invisible activities.

• They will continue to run in the background even if you switch to the interface of a
different application

• Services can be categorized to two types:

o Started

o Bound

2
Mobile Application Development - 22617

7. Enlist the steps to publish the Android Application

1. Open the Google Play Developer’s Console and create a Developers Acco unt

2. Link the Developer Account with Google Wallet Merchant Account

3. Create the Application

4. Provide App Store Listing

5. Upload the APK File to Google Play Store

6. Set the Content Rating

7. Fix the App Pricing and Distribution

8. Finally, Publish the Application

3
Mobile Application Development - 22617

Question Two [4 Marks Each]


1. Describe the Android Architecture in detail.

• Android Architecture is a software stack of components to support a mobile device


need.

Components:

Linux Kernel

• Linux kernel It is the heart of android architecture that exists at the root of
android architecture.

• Linux kernel is responsible for device drivers, power management, memory


management, device management and resource access.

Platform Libraries

• Running on the top of the kernel, the Android framework was developed with
various features.

4
Mobile Application Development - 22617

• It consists of various C/C++ core libraries with numerous of open-source tools.


Some of these are:

o The Android runtime

o Open GL(graphics library)

o WebKit

o Media frameworks:

o Secure Socket Layer (SSL):

Android Runtime

• In android runtime, there are core libraries and DVM (Dalvik Virtual Machine)
which is responsible to run android application.

• DVM is like JVM but it is optimized for mobile devices. It consumes less memory
and provides fast performance.

Applications Framework

• It includes Android API's such as UI (User Interface), telephony, resources,


locations, Content Providers (data) and package managers.

• It provides a lot of clas ses and interfaces for android application development.

Applications

• On the top of android framework, there are applications.

• All applications such as home, contact, settings, games, browsers are using
android framework that uses android runtime and lib raries.

• Android runtime and native libraries are using Linux kernel.

5
Mobile Application Development - 22617

2. Differentiate between DVM and JVM

Write Any Two

JVM DVM

JVM supports multiple Operating DVM Supports only Android Operating


Systems System

JVM forms a separate class in separate DVM forms multiple class in .dex byte
.class byte code files code file

It is based on stack based virtual It is based on register based virtual


machine architecture machine architecture

JVM runs on more memory DVM runs on less memory

The executable format of JVM is .JAR The executable form of DVM is .APK

JVM has different constant pools DVM has same constant pools

The .class byte code are optimized to.


It runs .class byte code directly
odex format before executing in DVM

6
Mobile Application Development - 22617

3. Explain Activity Life Cycle

• Activities in the system are managed as an activity stack.

• When a new activity is happening, it is placed on the top of the stack and becomes
the running activity.

• The activity always remains below it in the stack, and will n ot come to the
foreground again until the new activity exits.

• Activities have predefined life cycle and which certain methods are called.
Following table shows important life cycle methods:

7
Mobile Application Development - 22617

Sr.
Method Purpose
No

Called then the activity is created. Used to initialize the


1 onCreate()
activity, for example create the user interface.

Called if the activity gets visible again and the user starts
2 onResume() interacting with it. Used to initialize fields, register listeners,
bind to services, etc.

Called once another activity gets into foreground. Always


called before the activity is not visible anymore. Used to
3 onPause() release the resources or save application development. For
example, unregister listener, intent receivers, unbind from
services or remove system service listeners

Called once the activity is no longer visible. Time or CPU -


intensive shutdown operations, such as writing information to
4 onStop()
database should be down to onStop() method. The method is
guaranteed to be called as of API 11

8
Mobile Application Development - 22617

4. Describe the need of permission in Android. Describe the


permission to set system functionalities like Bluetooth and camera.

• The purpose of a permission is to protect the data and privacy of a user. Android
apps must request permission to access sensitive user data such as contacts, as
well as to use certain system and hardware features like calling, camera or
internet.

• Permission for Bluetooth:

<uses-permission android:name="android.permission.BLUETOOTH" />


<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

• Permission for Camera:

<uses-permission android:name="android.permission.CAMERA" />>

9
Mobile Application Development - 22617

Question Three [4 Marks Each]


1. Explore the steps to install and configure Android Studio and SDK.

Steps to install and configure the studio and SDK:

1. Download the latest version of android studio from http://developer.android.com

2. After the download has completed, run the installer and click next on the dialog
box if prompted.

3. It will start the installation, and once completed , click NEXT.

4. Now click on FINISH. It will ask whether to import the previous settings or not.
Choose on “Do not import settings” option.

5. Meanwhile, the Studio will start to find required SDK components.

6. After the SDK has been found, it will redirect to the welcome dialog box , on which
you’ve to click NEXT.

7. Click on Standard and press NEXT .

8. Now select the theme as per as your choice.

9. Now the Studio will start downloading the SDK Components and may take a while.
Once finished, click on NEXT.

10. Now we have successfully configured android studio.

11. Click on the finish button to launch it.

12. Click on “Start new Project” to build a new app.

2. Explain date and time picker with its methods.

DatePicker

The Android DatePicker allows you to select a date consisting of any day, month and
the year in your custom user interface.

Methods of DatePicker

getMonth() : Gets the selected month.

getYear() : Gets the selected year.

getDayOfMonth() : Gets selected day of month.

getCalenderView() : It returns the Calender View Interface.

10
Mobile Application Development - 22617

Timepicker

The Android Timepicker allows you to select a time either in the 12 ho urs or 24 hours
format. The time consists of hours and minutes in the clock format.

Methods of Timepicker

isEnabled() : Returns the enabled status of the view.

setCurrentHour() : Sets the current ho ur of the day.

setCurrentMinute() : Sets the current minute.

setEnabled() : sets the enabled state of the view .

3. Describe significance of SQLite Database in Android.

• Android SQLite is a very lightweight database which comes with Android OS

• . Android SQLite combines a clean SQL interface with a very small memory
footprint and decent speed.

• For Android, SQLite is "baked into" the Android runtime, so every Android
application can create its own SQLite databases .

• Significance:

1. Serverless: SQLite is serverless which does not need a detach server process or
system to operate.

2. Zero Configurations: SQLite does not require any setup or administration.

3. Cross-platform: A complete SQLite database is stored in a single cross -platform


disk file.

4. Less Memory: SQLite is very small and light weight, less than 400 KiB compl etely
configured or less than 250 KiB with optional features omitted.

5. Self-Contained: SQLite has no external dependencies.

6. Transaction: SQLite transactions are supported ACID properties to allow safe


access from multiple processes or threads.

7. Languages and operating system: SQLite support most of the query language
features found in SQL92 (SQL2) standard.

11
Mobile Application Development - 22617

4. Discuss Developer console with its purpose

• Google Play Developer Console is the platform that Google provides for Google
Play and Android developers to publish their apps.

• The Google Play console allows app developers and marketers to better
understand how their apps are performing in terms of growth, technical
performance such as crashes or display issues, and financials.

• The console offers acquisition reports and detailed analysis which can help app
devs find out how well an app is really performing .

• The platform is important as it provides developers with access to first party


data (trustworthy information collected about an app’s audience that comes
straight from Google Play) that highlights the real performance of an app.

• it shows the number of impressions an app listing receives and the number of
installs an app receives from different sources over time.

12
Mobile Application Development - 22617

Question Four [4 Marks Each]


1. Observe the following GUI and write an XML File using relative
layout to create the same.

Code

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<View
android:id="@+id/v1"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:layout_marginRight="40dp"
android:background="@color/purple_200" />

<View
android:id="@+id/v2"
android:layout_width="wrap_content"
android:layout_height="276dp"
android:layout_below="@+id/v1"

13
Mobile Application Development - 22617

android:layout_marginLeft="40dp"
android:layout_marginTop="165dp"
android:layout_marginRight="40dp"
android:layout_marginBottom="20dp"
android:background="@color/purple_200" />

<View
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/v1"
android:layout_marginLeft="40dp"
android:layout_marginTop="37dp"
android:layout_marginRight="230dp"
android:layout_marginBottom="330dp"
android:background="@color/purple_200" />

<View
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/v1"
android:layout_marginLeft="230dp"
android:layout_marginTop="37dp"
android:layout_marginRight="40dp"
android:layout_marginBottom="330dp"
android:background="@color/purple_200" />
</RelativeLayout>

OUTPUT

14
Mobile Application Development - 22617

2. Write a program to display circular progress bar

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<RelativeLayout
android:id="@+id/progress_layout"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_margin="100dp">

<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" />

<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:textSize="28sp"/>
</RelativeLayout>
</LinearLayout>

15
Mobile Application Development - 22617

circular_progress_bar.xml

<?xml version="1.0" encoding="utf-8"?>


<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="270"
android:toDegrees="270">

<!--styling the progress bar-->


<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thickness="8dp"
android:useLevel="true">
<gradient
android:angle="0"
android:endColor="@color/purple_200"
android:startColor="#000000"
android:type="sweep"
android:useLevel="false" />
</shape>

</rotate>

circular_shape.xml

<?xml version="1.0" encoding="utf-8"?>


<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadiusRatio="2.5"
android:shape="ring"
android:useLevel="false">
<solid android:color="@color/purple_200" />
</shape>

MainActivity.java

package com.experiments.progressbarcircular;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;
import android.widget.TextView;

16
Mobile Application Development - 22617

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private ProgressBar progressBar;


private TextView progressText;
int i = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = findViewById(R.id.progress_bar);
progressText = findViewById(R.id.progress_text);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@SuppressLint("SetTextI18n")
@Override
public void run() {
if (i <= 100) {
progressText.setText("" + i);
progressBar.setProgress(i);
i++;
handler.postDelayed(this, 200);
} else {
handler.removeCallbacks(this);
}
}
}, 200);
}
}

17
Mobile Application Development - 22617

OUTPUT

18
Mobile Application Development - 22617

3. List Sensors in Android and explain any one in detail

• There are three types of sensors in Android:

o Environmental Sensor

o Motion Sensor

o Position Sensor

Position Sensor

• The android platform provides two sensors that lets you determine the position of
a device: the geomagnetic field sensor a nd the accelerometer.

• The Android platform also provides a sensor that lets you determine how close to
a face of device is to an object. It is know n as proximity sensor.

• The geomagnetic field sensor and proximity sensor are hardware based.

• Positional sensors are useful for determining a devices physical position in the
world frame for reference. For example, you can use the geomagnetic field sensor
in combination with ac celerometer to determine devices position relative to the
magnetic north pole.

19
Mobile Application Development - 22617

4. Explain Zoom (In/Out) with help of an example

• In Android, Zoom Control is a class that has some set of methods that are used to
control the zoom functionality.

• It has two buttons that are used to control the zoom functionality ( i.e., Zoom in
and Zoom Out).

• On the emulator there is no way to zoom in or out from a particular location, but it
can possible on a real Android device where we can touch that map to zoom it.

• Hence, we should learn how users can zoom in or out of the map using the built -in
zoom controls.

• Example:

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<ImageView
android:id="@+id/image_View"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/image1" />

<ZoomControls
android:id="@+id/zoom_controls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_margin="10dp" />

</RelativeLayout>

20
Mobile Application Development - 22617

MainActivity.java

package com.experiments.zoomcontrol;

import android.graphics.Color;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ZoomControls;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

ImageView imageView;
ZoomControls zoomControls;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.image_View);
zoomControls = findViewById(R.id.zoom_controls);
zoomControls.setBackgroundColor(Color.BLACK);
zoomControls.show();
imageView.setOnTouchListener(
new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent
motionEvent) {
zoomControls.show();
return false;
}
}
);

zoomControls.setOnZoomInClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
float x = imageView.getScaleX();
float y = imageView.getScaleY();
imageView.setScaleX((float) (x + 0.5f));
imageView.setScaleY((float) (y + 0.5f));
zoomControls.hide();
}
}
);

21
Mobile Application Development - 22617

zoomControls.setOnZoomOutClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
float x = imageView.getScaleX();
float y = imageView.getScaleY();
if (x == 1 && y == 1) {
imageView.setScaleX((float) (x));
imageView.setScaleY((float) (y));
zoomControls.hide();
} else {
imageView.setScaleX((float) (x - 0.5f));
imageView.setScaleY((float) (y - 0.5f));
zoomControls.hide();
}
}
}
);
}
}

OUTPUT

22
Mobile Application Development - 22617

5. Develop an Android to send and receive SMS. (WRITE only .java


and permission tag in Manifest file)

MainActivity.java

package com.experiments.sendmessage;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class MainActivity extends AppCompatActivity {

EditText no, msg;


Button send;
int code = 1;

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

no = findViewById(R.id.no);
msg = findViewById(R.id.msg);
send = findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String num = no.getText().toString();
String sms = msg.getText().toString();
requestPermission();
if (!TextUtils.isEmpty(num) && !TextUtils.isEmpty((sms)))
{
if (checkPermission()) {
SmsManager mana = SmsManager.getDefault();
mana.sendTextMessage(num, null, sms, null, null);

23
Mobile Application Development - 22617

no.setText("");
msg.setText("");
} else {
Toast.makeText(getApplicationContext(),
"permission not granted",
Toast.LENGTH_SHORT).show();
}
}
}
});
}

private void requestPermission() {


ActivityCompat.requestPermissions(this, new String[]
{Manifest.permission.SEND_SMS}, code);
}

private boolean checkPermission() {


int result = ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.SEND_SMS);
if (result == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
return false;
}
}
}

AndroidManifest.xml

<uses-permission android:name="android.permission.SEND_SMS" />

24
Mobile Application Development - 22617

OUTPUT

25
Mobile Application Development - 22617

Question Five [6 Marks Each]


1. Develop the registiration form using the following GUI

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<ImageView
android:layout_ width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginTop="40dp"

26
Mobile Application Development - 22617

android:src="@drawable/image1" />

<EditText
android:id="@+id/name"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:background="#E8E8E8"
android:drawableLeft="@drawable/person"
android:drawablePadding="10dp"
android:hint="Name"
android:paddingLeft="10sp" />

<EditText
android:id="@+id/email"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#E8E8E8"
android:drawableLeft="@drawable/email"
android:drawablePadding="10dp"
android:hint="Email ID"
android:paddingLeft="10sp" />

<EditText
android:id="@+id/password"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#E8E8E8"
android:drawableLeft="@drawable/password"
android:drawablePadding="10dp"
android:hint="Password"
android:paddingLeft="10sp" />

<EditText
android:id="@+id/cpassword"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#E8E8E8"
android:drawableLeft="@drawable/cpassword"
android:drawablePadding="10dp"
android:hint="Confirm Password"

27
Mobile Application Development - 22617

android:paddingLeft="10sp" />

<EditText
android:id="@+id/mobile"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:background="#E8E8E8"
android:drawableLeft="@drawable/mobile"
android:drawablePadding="10dp"
android:hint="Enter Mobile"
android:paddingLeft="10sp" />

<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="horizontal">

<RadioButton
android:id="@+id/male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male" />

<RadioButton
android:id="@+id/female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />

</RadioGroup>

<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="Register" />

</LinearLayout>

28
Mobile Application Development - 22617

MainActivity.java

package com.experiments.registerationform;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


EditText e1, e2, e3, e4, e5;
Button btn;
RadioGroup radioGroup;
RadioButton r1, r2;

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

e1 = findViewById(R.id.name);
e2 = findViewById(R.id.email);
e3 = findViewById(R.id.password);
e4 = findViewById(R.id.cpassword);
e5 = findViewById(R.id.mobile);
r1 = findViewById(R.id.male);
r2 = findViewById(R.id.female);
radioGroup = findViewById(R.id.radiogroup);
// r1 = findViewById(R.id.gender);
btn = findViewById(R.id.btn);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

String gender = "";


if (r1.isChecked()) {
gender = "Male";
} else if (r2.isChecked()) {
gender = "Female";
}

String name = e1.getText().toString();

29
Mobile Application Development - 22617

String email = e2.getText().toString();


String pass = e3.getText().toString();
String cpass = e4.getText().toString();
// String gender = (String) radioButton.getText();
String mobile = e5.getText().toString();

if (pass.equals(cpass)) {
String disp = "Name: " + name + "\n" +
"Email: " + email + "\n" +
"Gender: " + gender + "\n" +
"Mobile: " + mobile + "\n";

Toast.makeText(getApplicationContext(), disp,
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Passwords do
not Match", Toast.LENGTH_SHORT).show();
}
}
});
}
}

OUTPUT

30
Mobile Application Development - 22617

2. Write a program to capture an image and display it

activity_main.xml

<?xml version="1.0" encoding="UTF-8" ?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="Click to Capture" />

<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="Capture" />

<ImageView
android:id="@+id/img"
android:layout_width="400dp"
android:layout_height="400dp"
android:layout_gravity="center"
android:layout_marginTop="50dp" />

</LinearLayout>

31
Mobile Application Development - 22617

MainActivity.java

package com.experiments.imagecapture;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.media.Image;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {


Button btn;
ImageView img;
int CAMERA_REQUEST = 1;

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

btn = findViewById(R.id.btn);
img = findViewById(R.id.img);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, CAMERA_REQUEST);
}
});
}

protected void onActivityResult(int requestCode, int resultCode,


@Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == CAMERA_REQUEST) {
Bitmap image = (Bitmap) data.getExtras().get("data");
img.setImageBitmap(image);
}
}
}

32
Mobile Application Development - 22617

AndroidManifext.xml

<uses-permission android:name="android.permission.CAMERA" />

OUTPUT

33
Mobile Application Development - 22617

3. Develop a program to send an email

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:text="Email Example"
android:textSize="25dp" />

<EditText
android:id="@+id/ed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:hint="Enter E-mail" />

<EditText
android:id="@+id/ed1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:hint="Subject" />

<EditText
android:id="@+id/ed2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:hint="message" />

34
Mobile Application Development - 22617

<Button
android:id="@+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:text="send" />
</LinearLayout>

MainActivity.java

package com.experiments.emailsender;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

Button snd;
EditText ed,ed1,ed2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

snd=findViewById(R.id.send);
ed=findViewById(R.id.ed);
ed1=findViewById(R.id.ed1);
ed2=findViewById(R.id.ed2);

snd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String to=ed.getText().toString();
String sub=ed1.getText().toString();
String msg=ed2.getText().toString();

35
Mobile Application Development - 22617

Intent email= new Intent(Intent.ACTION_SEND);

email.putExtra(Intent.EXTRA_EMAIL, new String[] {to});


email.putExtra(Intent.EXTRA_SUBJECT,sub);
email.putExtra(Intent.EXTRA_TEXT,msg);
email.setType("message/rfc822");
startActivity(Intent.createChooser(email,"Choose an email
client"));

}
});

}
}

OUTPUT

36
Mobile Application Development - 22617

Question Six [6 Marks Each]


1. Develop an application to store student details like roll no., name,
branch, marks, percentage, and retrieve student information using
roll no. in SQLite databases.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:stretchColumns="0">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="Student Details" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="Enter Roll Number" />

<EditText
android:id="@+id/roll"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp" />

<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp" />

37
Mobile Application Development - 22617

<TextView
android:id="@+id/marks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp" />

<TextView
android:id="@+id/percent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp" />

<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="View" />

</LinearLayout>

MainActivity.java

package com.experiments.sqliteexample;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

TextView t1, t2, t3;


EditText e1;
Button btn;

38
Mobile Application Development - 22617

SQLiteDatabase db;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1 = findViewById(R.id.name);
t2 = findViewById(R.id.marks);
t3 = findViewById(R.id.percent);
e1 = findViewById(R.id.roll);
btn = findViewById(R.id.btn);
db = openOrCreateDatabase("StudentDB", Context.MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS studentmarks(rollno
VARCHAR,name VARCHAR,marks VARCHAR, percent VARCHAR);");
db.execSQL("INSERT INTO studentmarks(rollno, name, marks, percent)
VALUES ('49', 'Anurag', '94', '94%');");
db.execSQL("INSERT INTO studentmarks(rollno, name, marks, percent)
VALUES ('53', 'Maksud', '97', '97%');");

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Cursor c = db.rawQuery("SELECT * FROM studentmarks WHERE
rollno='" + e1.getText() + "'", null);
if (c.moveToFirst()) {
t1.setText("Name: " + c.getString(1));
t2.setText("Marks Obtained" + c.getString(2));
t3.setText("Percentile:" + c.getString(3));
} else {
Toast.makeText(getApplicationContext(), "Enter a Valid
Roll ID", Toast.LENGTH_SHORT).show();
}
}
});
}
}

39
Mobile Application Development - 22617

OUTPUT

40
Mobile Application Development - 22617

2. Write a program to locate the user’s current location (Only .java


and manifest file)
MainActivity.java

package com.experiments.currentlocation;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity implements LocationListener {


protected LocationManager locationManager;
protected LocationListener locationListener;
protected Context context;
TextView txtLat;
String lat;
String provider;
protected String latitude, longitude;
protected boolean gps_enabled, network_enabled;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtLat = (TextView) findViewById(R.id.textview1);

locationManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0, this);
}

@Override
public void onLocationChanged(Location location) {
txtLat = (TextView) findViewById(R.id.textview1);
txtLat.setText("Latitude:" + location.getLatitude() + ",
Longitude:" + location.getLongitude());
}
}

41
Mobile Application Development - 22617

AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

OUTPUT

42
Mobile Application Development - 22617

3. Develop a Simple Calculator using Table Layout

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TableRow>

<EditText
android:id="@+id/v1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="50dp"
android:hint="Enter value 1" />

<EditText
android:id="@+id/v2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="50dp"
android:hint="Enter value 2" />

</TableRow>

<TableRow>

<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="40dp"
android:onClick="sum"
android:text="addition" />

<Button
android:id="@+id/sub"
android:layout_width="wrap_content"

43
Mobile Application Development - 22617

android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="40dp"
android:onClick="sub"
android:text="subtract" />

</TableRow>

<TableRow>

<Button
android:id="@+id/mul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginTop="20dp"
android:onClick="mul"
android:text="multiply" />

<Button
android:id="@+id/div"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:onClick="div"
android:text="division" />

</TableRow>

</TableLayout>

MainActivity.java

package com.experiments.calculatortablelayout;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

44
Mobile Application Development - 22617

public void sum(View view){

EditText no1=findViewById(R.id.v1);
EditText no2=findViewById(R.id.v2);
Button add=findViewById(R.id.add);
String val1=no1.getText().toString();
String val2=no2.getText().toString();
Integer value1=Integer.parseInt(val1);
Integer value2=Integer.parseInt(val2);
Integer result= value1+value2;
Toast.makeText(getApplicationContext(),"Addition= "+result,
Toast.LENGTH_SHORT).show();

public void sub(View view){

EditText no1=findViewById(R.id.v1);
EditText no2=findViewById(R.id.v2);
Button add=findViewById(R.id.sub);
String val1=no1.getText().toString();
String val2=no2.getText().toString();
Integer value1=Integer.parseInt(val1);
Integer value2=Integer.parseInt(val2);
Integer result= value1-value2;
Toast.makeText(getApplicationContext(),"Subtract= "+result,
Toast.LENGTH_SHORT).show();

}
public void mul(View view){

EditText no1=findViewById(R.id.v1);
EditText no2=findViewById(R.id.v2);
Button add=findViewById(R.id.mul);
String val1=no1.getText().toString();
String val2=no2.getText().toString();
Integer value1=Integer.parseInt(val1);
Integer value2=Integer.parseInt(val2);
Integer result= value1*value2;
Toast.makeText(getApplicationContext(),"Multiplication= "+result,
Toast.LENGTH_SHORT).show();

}
public void div(View view){

EditText no1=findViewById(R.id.v1);
EditText no2=findViewById(R.id.v2);

45
Mobile Application Development - 22617

Button add=findViewById(R.id.div);
String val1=no1.getText().toString();
String val2=no2.getText().toString();
Integer value1=Integer.parseInt(val1);
Integer value2=Integer.parseInt(val2);
Integer result= value1/value2;
Toast.makeText(getApplicationContext(),"division= "+result,
Toast.LENGTH_SHORT).show();

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

}
}

OUTPUT

46

You might also like