MAD All Chapter Q and A
MAD All Chapter Q and A
MAD All Chapter Q and A
For 2 Marks
1. Define OHA and state goal of OHA. [W-22]
The OHA is the group that is in charge of the Android smartphones operating system. It was created
by Google.The Open Handset Alliance (OHA) is consortium of multiple companies like Samsung, Sony,
Intel and many more to provide services and deploy handsets using 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.
Android Studio
ADB (Android Debug Bridge)
AVD Manager
Eclipse
Fabric
FlowUp
GameMaker: Studio
Genymotion
Gradle
IntelliJ IDEA
For 4 Marks
1. Describe the different features of Android. [W-22]
User Interface: The user interface of the Android operating system is straight forward, and these
features make it very user friendly.
Multiple Language Support: Android supports multiple languages in its operating system and
one can change the language very easily based on one’s requirement, the International 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.
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:
• 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.
6. Write down the steps to install and configure Android studio.[S-22]
Step 1:
Go to https://developer.android.com/android-studio/download to get the Android
Studio executable or zip file.
Step 2:
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.
7. Explain the need of Android Operating System. Also describe any four
features of android. [W-23]
1) Storage
2) Multitasking
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
Ans: Android SDK is a collection of libraries and Software Development tools that are
essential for Developing Android Applications. Whenever Google releases a new
version or update of Android Software, a corresponding SDK also releases with it. In
the updated or new version of SDK, some more features are included which are not
present in the previous version. Android SDK consists of some tools which are very
essential for the development of Android Application. These tools provide a smooth
flow of the development process from developing and debugging. Android SDK is
compatible with all operating systems such as Windows, Linux, macOS, etc.
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.
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.
2) Explain the steps to install and configure Android studio and SDK. [W-22]
3) Explore all steps to install Android studio and SDK. [W-23] , [sample question
paper]
1. Before installing Android SDK, there is need to install Java Development Kit (JDK).
Ensure that JDK is at or above 1.8.
2. Uninstall older version(s) of "Android Studio" and "Android SDK", if any. We need
to install two packages:
1. Android Studio (IDE), which is an Integrated Development Environment (IDE)
2. Android SDK (Software Development Kit) for developing and running Android
apps.
Steps to install Android studio:
1. Click Download Android Studio. The Terms and Conditions page with the Android
Studio License Agreement opens.
2. Read the License Agreement.
3. At the bottom of the page, if you agree with the terms and conditions, select the I
have read and agree with the above terms and Android studio installation
conditions checkbox.
4. Click Download Android Studio to start the download.
5. When prompted, save the file to a location where you can easily locate it, such as
the Downloads folder.
6. Wait for the download to complete.
a. Open the folder where you downloaded and saved the Android Studio
installation file.
b. Double-click the downloaded file.
c. If you see a User Account Control dialog about allowing the installation to make
changes to your computer, click Yes to confirm the installation.
d. Click Next to start the installation.
e. Accept the default installation settings for all steps.
f. Click finish when installation is done.
1 It stands for Java Virtual Machine It stands for Dalvik Virtual Machine
JVM used java byte code and run DVM is used its own byte code and
4
“.class “ file run “.dex” file
6) Explain the need of Android Operating System. Also describe any four features of
android. [W-23]
Zero/negligible development cost: The development tools like Android SDK, JDK,
and Eclipse IDE etc. are free to download for the android mobile application
development.
Open Source: The Android OS is an open-source platform based on the Linux
kernel and multiple open-source libraries. In this way developers are free to
contribute or extend the platform as necessary for building mobile apps which run
on Android devices
. Multi-Platform Support In market, there are a wide range of hardware devices
powered by the Android OS, including many different phones and tablet. Even
development of android mobile apps can occur on Windows, Mac OS or Linux.
Multi-Carrier Support World wide a large number of telecom carriers like Airtel,
Vodafone, Idea Cellular, AT&T Mobility, BSNL etc. are supporting Android powered
phones.
Open Distribution Model Android Market place (Google Play store) has very few
restrictions on the content or functionality of an android app. So the developer can
distribute theirs app through Google Play store and as well other distribution
channels like Amazon’s app store.
Elements of UI.
EditText
TextView
ListView
GridView
ScrollView
ImageView
ToggleButton
CheckBox
RadioButton
OR Components of UI
Menu Bar
Toolbar
Navigation Bar
Editor Tabs
Editor
Project Explorer
Status Bar
Tool Buttons
2) List any four folders from directory structure of Android project and elaborate in
one line. [S-22]
app: The App folder contains three subfolders (manifests, java and res) that
make up our application. They are divided so that it should be fairly easy to
determine which resources go in which folder.
Manifest: This is where we would put our manifest files. Most Android apps have
single manifest file. But an app may have several manifest files due to application
versioning, or for supporting specific hardware.
Java: This is the folder in our project where we will be storing all of the source
code files written in Java programming language.
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.
drawable: The drawable folder contains graphics that can be drawn to the
screen.
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.
mipmap: The mipmap folder contains the launcher icon files for the app. A
launcher icon is a graphic that represents your app to users.
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.
2. For ON/OFF state two labels can 2. There is only one label for radio
be assign. button.
5) Write the directory path where images are stored while developing Android
application.[sample question paper]
6) List Eight alignment attributes of relative layout. [sample test paper]
7) Draw the hierarchical directory structure of android application. [sample test
paper]
8) List different User Interface Elements. Explain Toggle Button. [sample test paper]
For 4 Marks
1. Views:
• The basic building block for user interface in Android is a View, which is created
from the 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. • 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:
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
2) Explain with example, code to create GUI using absolute layout (Assume suitable
data). [S-22]
Absolute Layout is based on the simple idea of placing each control at an absolute
position. We specify the exact x and y coordinates on the screen for each control.
This is not recommended for most UI development (in fact Absolute Layout is
currently deprecated) since absolutely positioning every element on the screen
makes 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.
In Relative Layout we need to specify the position of child views relative to each
other or relative to the parent. In case if we didn’t specify the position of child views,
by default all child views are positioned to top-left of the layout.
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:orientation="vertical"
android:stretchColumns="1">
<TableRow android:padding="5dip">
<TextView
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_span="2"
android:gravity="center_horizontal"
android:text="@string/loginForm"
android:textColor="#0ff"
android:textSize="25sp"
android:textStyle="bold" />
</TableRow>
<TableRow>
<TextView
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="10dp"
android:text="@string/userName"
android:textColor="#fff"
android:textSize="16sp" />
<EditText
android:id="@+id/userName"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_marginLeft="10dp"
android:background="#fff"
android:hint="@string/userName"
android:padding="5dp"
android:textColor="#000" />
</TableRow>
<TableRow>
<TextView
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:text="@string/password"
android:textColor="#fff"
android:textSize="16sp"
android:layout_marginTop="20dp"
android:text="@string/password"
android:textColor="#fff"
android:textSize="16sp" />
<EditText
android:id="@+id/password"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:background="#fff"
android:hint="@string/password"
android:padding="5dp"
android:textColor="#000" />
</TableRow>
<TableRow android:layout_marginTop="20dp">
<Button
android:id="@+id/loginBtn"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_span="2"
android:background="#0ff"
android:text="@string/login"
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
4) Explain components of android directory structure. [W-23]
The android project contains different types of app modules, source code files, and
resource files.
6) Write a program to display following output using suitable layout. [sample test
paper]
For 6 Marks
activity_main.xml
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/heading"
android:layout_width="wrap_content"
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"
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"
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;
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));
}
});
}
}
2) Design UI using table layout to display buttons with 0 9 numbers on it. Even
display 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.) [S-22]
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"
android:stretchColumns="*"
tools:context=".MainActivity">
<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/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"
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);
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();
}
});
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(); }
});
}
}
3) Develop the registration form using the following GUI. [sample question paper]
For 2 Marks
1) id
2) checked
3) gravity
4) text
5) text color
6) text size
7) text style
8) background
9) padding
Dalvik Virtual Machine is a register-based machine that compiles byte code to get dex code
and that ensures that a device can run multiple instances efficiently.
4)List all attributes to develop a simple button . [sample question paper]
5)List different types of views? Explain Scroll view. [sample test paper]
For 4 Marks
1)Explain data and time picker with its method. [W-22] , [sample question paper]
Date Picker:
In Android, DatePicker is a widget used to select a date. It allows to select date by day,
month and year in our custom UI (user interface). If we need to show this view as a dialog
then we have to use a DatePickerDialog class.
Methods of DatePicker:
Syntax:
simpleDatePicker.setSpinnersShown(false);
2. getDayOfMonth(): This method is used to get the selected day of the month from a
date picker.
3. getMonth(): This method is used to get the selected month from a date picker. This
method returns an integer value.
4. getYear(): This method is used to get the selected year from a date picker. This method
5. getFirstDayOfWeek(): This method is used to get the first day of the week. This
method returns an integer value.
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:
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);
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.
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.
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.
simpleTimePicker.setOnTimeChangedListener(new
TimePicker.OnTimeChangedListener() {
@Override
}
});
Xml File:
<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">
<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"
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;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressStatus += 1;
progressBar.setProgress(progressStatus);
textView.setText(progressStatus+"/"+progressBar.getMax());
});
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}).start();
}
3) State syntax to create Text View and Image button with any two attributes of
each. [S-22]
Text View:
Syntax :
<TextView
android:id="@+id/textView1"
android:layout_width="<width value>”
android:layout_height="<height_value>"
android:text="<text to be displayed>"/>
Attributes/Properties of TextView:
View.findViewByID() or Activity.findViewById()
● alpha: alpha property of the view as a value between 0 (entirely transparent) and
● auto link: Controls whether links such as urls and email addresses are
● gravity: The gravity attribute is an optional attribute which is used to control the
alignment of the text like left, right, center, top, bottom, center_vertical,
center_horizontal etc
● text: text attribute is used to set the text in a text view. We can set the text in xml as
● textColor: textColor attribute is used to set the text color of a text view. Color
● textSize: textSize attribute is used to set the size of text of a text view. We can set
text styles are bold, italic and normal. If we need to use two or more styles for a text
● 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
ImageButton:
Syntax :
<ImageButton
android:id="@+id/imageButton"
android:layout_width="<width value>"
android:layout_height="<height value>"
Attributes/Properties of ImageButton:
● src: src is an attribute used to set a source file of image or you can say image in
● padding: padding attribute is used to set the padding from left, right, top or
activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<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"
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;
TextView tvDate,tvTime;
DatePicker dtpcker;
TimePicker timepcker;
Button b1,b2;
@Override
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
"+dtpcker.getMonth()+"-"+dtpcker.getYear());
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
tvTime.setText(timepcker.getCurrentHour()+":"+timepcker.getCurrentMinute());
});
5) Develop an application to display analog Time Picker. Also display the selected
time. (Write only java file) [W-23]
MainActivity.java
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;
TextView textview1;
TimePicker timepicker;
Button changetime;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textview1=(TextView)findViewById(R.id.textView1);
timepicker=(TimePicker)findViewById(R.id.timePicker);
timepicker.setIs24HourView(true);
changetime=(Button)findViewById(R.id.button1);
textview1.setText(getCurrentTime());
changetime.setOnClickListener(new View.OnClickListener(){
@Override
textview1.setText(getCurrentTime());
});
"+timepicker.getCurrentHour()+":"+timepicker.getCurrentMinute();
return currentTime;
}
6) Develop an android application using radio button. [W-23]
[Consider any relevant example of Radio Button and in XML file, consider
minimum attributes]
activity_main.xml
<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
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="30dp"
tools:context=".frame">
<TextView android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Radio Button"
android:textSize="20dp"
android:gravity="center"
android:textColor="#f00"/>
<RadioGroup android:id="@+id/group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text1">
<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:layout_below="@+id/male"
android:text="Female"/>
</RadioGroup>
<Button android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/group"
android:layout_marginTop="99dp"
android:layout_centerHorizontal="true"
android:text="Submit" />
</RelativeLayout>
Java File:
package com.example.ifcdiv;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Toast;
public class frame extends AppCompatActivity
RadioButton male,female;
Button b1;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frame);
male=findViewById(R.id.male);
female=findViewById(R.id.female);
b1=findViewById(R.id.submit);
b1.setOnClickListener(new View.OnClickListener()
@Override
selected="You selected"+male.getText();
else
selected="You Selected"+female.getText();
}
Toast.makeText(getApplicationContext(),selected,Toast.LENGTH_LONG).show();
} });
For 6 Marks
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ListView
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>
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;
GridView gridView;
static final String[] alphabets = new String[]{
};
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//List View
listView.setAdapter(adapter);
//Grid View
gridView.setAdapter(adapter1);
}
2. Write a program to convert temperature from celcius to farenhite and vice versa
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.) [S-22]
activity_main.xml
<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edittext"
<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"
<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;
Button b1;
EditText et;
ToggleButton tb;
Double a;
@Override
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
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();
});
}
Chapter 5 [20M]
For 2 Marks
An Intent is a messaging object you can use to request an action from another app
component.
Intents are used for facilitating communication between components like Activities,
Services and Broadcast Receivers.
1) MediaPlayer
2) MediaController
3) AudioManager
Types:
7) Enlist different ways to handle databases in android? Elaborate any one. [sample
test paper]
8) Draw the life cycle of an activity. [sample test paper]
9)Name any 4 methods to get location data in android. [sample test paper]
1) onCreate (): Called then the activity is created. Used to initialize the activity,
forexample create the user interface.
2) onStart ():called when activity is becoming visible to the user.
3) 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.
4) 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.
5) 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 uaranteed to be called as of API 11.
6) onDestroy (): called before the activity is destroyed.
3) Develop an application to send and receive SMS (Write only Java and permissio
tag in manifest file).[W-22]
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>
<receiver
android:name=".SmsReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
</intent-filter>
</receiver>
MainActivity.java
(Cosidering appropriate layout file with 2 edit text boxes namely for phone number,
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;
EditText et1,et2;
Button b1;
@Override
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
try {
String msg=et2.getText().toString();
smsManager.sendTextMessage(phno,null,msg,null,null);
Toast.LENGTH_LONG).show();
catch(Exception e)
Toast.LENGTH_LONG).show();
});
@Override
protected void onStart() {
super.onStart();
registerReceiver(sms,filter);
@Override
super.onStop();
unregisterReceiver(sms);
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;
SmsReceiver(){}
@Override
if (bundle != null) {
// Retrieve the SMS Messages received
Toast.LENGTH_SHORT).show();
openOrCreateDatabse() method.
Program:
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">
<Button
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;;
SQLiteDatabase sqLiteDatabaseObj;
Button EnterData;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createData = (Button)findViewById(R.id.button);
createData.setOnClickListener(new View.OnClickListener() {
@Override
sqLiteDatabaseObj = openOrCreateDatabase("AndroidJSonDataBase",
Context.MODE_PRIVATE, null);
} });
● Services are used for repetitive and potentially long running operations, i.e.,
Internet downloads, checking for new data, data processing, updating content
● 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
1. Started
b. Now the service can run in the background indefinitely, even if the
2. Bound
bindService().
interact with the service, send requests, get results, and even do so across
c. Like any other components service also has callback methods. These will
d. There is always only a single instance of service running in the app. If you
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()
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
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
reliable interface for java services. The multimedia framework consists of several
on.
● Java classes call the Native C library Libmedia through Java JNI(Java Native
Client/Server model
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
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
2. Audio Format: Any format or codec can be used including the ones
activity_main.xml
<RelativeLayout xmlns:androclass="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" >
<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
<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" />
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>
</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;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (mBluetoothAdapter == null) {
button1.setOnClickListener(new View.OnClickListener() {
if (!mBluetoothAdapter.isEnabled()) {
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
});
button2.setOnClickListener(new View.OnClickListener() {
@Override
if (!mBluetoothAdapter.isDiscovering()) {
BLE",
Toast.LENGTH_LONG);
ABLE);
startActivityForResult(enableBtIntent, REQUEST_DISCOVERABLE_BT);
});
button3.setOnClickListener(new View.OnClickListener() {
@Override
mBluetoothAdapter.disable();
//out.append("TURN_OFF BLUETOOTH");
H_LONG);
}
});
@Override
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
activity_main.xml
<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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
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"/>
<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: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;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
SQLiteDatabase sqLiteDatabaseObj;
editSearchid;
@Override
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
sqLiteDatabaseObj = openOrCreateDatabase("AndroidJSonDataBase",
Context.MODE_PRIVATE, null);
VARCHAR);");
cid = editTextID.getText().toString();
cname = editTextName.getText().toString() ;
cmobile = editMobileNo.getText().toString();
caddress = editAddress.getText().toString();
cpincode = editPincode.getText().toString();
sqLiteDatabaseObj.execSQL(sql_query);
Toast.LENGTH_LONG).show();
});
SearchData.setOnClickListener(new View.OnClickListener() {
@Override
sid = editSearchid.getText().toString();
while (cursor.moveToNext())
{
buffer.append(cid+ " " + name + " " + mob +" " + addr +" " + pcode +"
\n");
Toast.makeText(getApplicationContext(), buffer,
Toast.LENGTH_LONG).show();
} }); } }
10) Write a program to capture an image using camera and display it. (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.) [S-
22]
activity_main.xml
<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"
android:layout_width="match_parent"
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"
</RelativeLayout>
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;
Button b1;
ImageView imageView;
int CAMERA_REQUEST=1;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=findViewById(R.id.photo);
imageView=findViewById(R.id.image);
b1.setOnClickListener(new View.OnClickListener() {
@Override
startActivityForResult(i,CAMERA_REQUEST);
}
});
@Override
data) {
if (requestCode==CAMERA_REQUEST)
imageView.setImageBitmap(image);
11) Write a program to implement Android Activity Life Cycle. Use toast messages
to display message through life cycle. (Note: No XML code is required. In java file
all imports are not expected.)[S-22]
package com.example.p1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(getApplicationContext(),"Activity
created",Toast.LENGTH_LONG).show();
@Override
super.onStart();
Toast.makeText(getApplicationContext(),"Activity
Started",Toast.LENGTH_LONG).show();
@Override
super.onStop();
Toast.makeText(getApplicationContext(),"Activity
Stop",Toast.LENGTH_LONG).show();
@Override
super.onDestroy();
Toast.makeText(getApplicationContext(),"Activity
Destroy",Toast.LENGTH_LONG).show();
@Override
super.onPause();
Toast.makeText(getApplicationContext(),"Activity
Pause",Toast.LENGTH_LONG).show();
@Override
super.onResume();
Toast.makeText(getApplicationContext(),"Activity
Restart",Toast.LENGTH_LONG).show();
@Override
super.onResume();
Toast.makeText(getApplicationContext(),"Activity
Resume",Toast.LENGTH_LONG).show();
Code of activity_main.xml
<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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:transitionGroup="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:layout_below="@+id/textview"
android:layout_centerHorizontal="true"
android:textColor="#ff7aff24"
android:textSize="35dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_below="@+id/textView"
android:layout_marginTop="46dp"
android:text="thanks"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#ff7aff10"
android:textColorHint="#ffff23d1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:layout_below="@+id/editText"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:textSize="15dp" />
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
<TextView
android:padding="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextToSpeechDemo"
android:gravity="center"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@android:color/white"/>
</LinearLayout>
Code of MainActivity.java.
package com.example.texttospeech.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.Locale;
import android.widget.Toast;
TextToSpeech t1;
EditText ed1;
Button b1;
@Override
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CU
STOM);
getSupportActionBar().setCustomView(R.layout.toolbar_title_layout);
setContentView(R.layout.activity_main);
ed1=(EditText)findViewById(R.id.editText);
b1=(Button)findViewById(R.id.button);
TextToSpeech.OnInitListener() {
@Override
if(status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.UK);
});
b1.setOnClickListener(new View.OnClickListener() {
@Override
Toast.makeText(getApplicationContext(),
toSpeak,Toast.LENGTH_SHORT).show();
});
}
public void onPause(){
if(t1 !=null){
t1.stop();
t1.shutdown();
super.onPause();
13) Develop a program to TURN ON and OFF bluetooth. Write .java file and
permission tags. [W-23]
Code of MainActivity.java
package com.example.bluetooth.myapplication;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Set;
public class MainActivity extends Activity {
Button b1,b2,b3,b4;
private Set<BluetoothDevice>pairedDevices;
ListView lv;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.button);
b2=(Button)findViewById(R.id.button2);
b3=(Button)findViewById(R.id.button3);
b4=(Button)findViewById(R.id.button4);
BA = BluetoothAdapter.getDefaultAdapter();
lv = (ListView)findViewById(R.id.listView);
if (!BA.isEnabled()) {
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(turnOn, 0);
Toast.makeText(getApplicationContext(), "Turned
on",Toast.LENGTH_LONG).show();
} else {
BA.disable();
,Toast.LENGTH_LONG).show();
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
startActivityForResult(getVisible, 0);
pairedDevices = BA.getBondedDevices();
Devices",Toast.LENGTH_SHORT).show();
ArrayAdapter(this,android.R.layout.simple_list_item_1, list);
lv.setAdapter(adapter);
}}
Permission Tags
AndroidManifest.xml file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bluetooth.myapplication" >
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
</intent-filter>
</activity>
</application>
</manifest>
14) Write a program to capture an image using camera and display it. [sample
question paper]
Chapter 6 [20M]
For 2 Marks
The javac compiler compiles the java source file into the class file.
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,
•float getAccuracy()
•float getBearing()
•double getAltitude()
•double getLatitude()
•float getSpeed()
•boolean hasAccuracy()
•boolean hasAltitude()
•boolean hasBearing()
•boolean hasBearing()
•boolean hasSpeed()
•void reset()
Geocoding :
Reverse Geocoding :
4) Enlist the steps to publish the Android application. [sample question paper]
UiSettings.setZoomControlsEnabled(true);
OR
b) In case, while display Google map by intent, default zoom level can be given in
geo:latitude,longitude?z=zoom
where lat and lag are for location and zoom level is to set initial zoom level which
OR
syntax :
zoomControls.show()
For 4 Marks
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.
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.
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 our 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.
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.
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.
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
The Android security model is primarily based on a sandbox and permission mechanism.
Each application is running in a specific Dalvik virtual machine with a unique user ID
assigned to it,which means the application code runs in isolation from the code of all other
applications.
Therefore, one application has not granted access to other applications’ files.Android
application has been signed with a certificate with a private key Know the owner of the
application is unique. This allows the author of the application will be identified if needed.
When an application is installed in the phone is assigned a user ID, thus avoiding it from
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.
There are three protection levels that affect thirdparty 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 mustexplicitly 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.
Geo-Coding:
• If we know the latitude and longitude of a location, we can find out its address using a
process
known as Geocoding. Google Maps in Android supports this via the Geocoder class.
• The following code shows how we can find out the address of a location we have just
touched
@Override
//...
@Override
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
getBaseContext(), Locale.getDefault());
try {
p.getLatitudeE6() / 1E6,
if (addresses.size() > 0)
i++)
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
try {
if (addresses.size() > 0) {
p = new GeoPoint(
mc.animateTo(p);
mapView.invalidate();
} catch (IOException e) {
e.printStackTrace();
Once. the location is found, the above code navigates the map to the location.
3) Elaborate the need of permissions in Android. Explain the permissions to set
system functionalitics like SEND-SMS, bluetooth. [W-22]
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.
Allows the app to send SMS messages. This may result in unexpected charges.
Malicious apps may cost you money by sending messages without your confirmation.
4) List and elaborate steps to deploy an Android application on Google play store.[S-
22]
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
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.
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.
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
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
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.
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
This is a safer option because you can analyze the test results and optimize or fix your
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.’
If you don’t assign a rating to your app, it will be listed as ‘Unrated’. Apps that are
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
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.
The final step involves reviewing and rolling out your release after making sure you’ve
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
5) State and elaborate the syntax of required class and methods for Geocoding. [S-
22]
Geocoder:
(partial) address. The amount of detail in a reverse geocoded location description may
vary, for example one might contain the full street address of the closest building, while
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
exists.
Syntax
a. getFromLocation
Syntax
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
b. getFromLocationName
Syntax :
listener)
Geocoder.GeocodeListener listener)
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
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.
Google Play Developer Console is the platform that Google provides for Google
● The Google Play Developer 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
● The platform is important as it provides developers with access to first party data
● It shows the number of impressions an app listing receives and the number of
Permission declaring :
Example:
(Note: Any other relevant example which uses permissions can be considered)
AndroidManifest.xml
<uses-permission android:name="android.permission.SEND_SMS"/>
activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<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"
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;
EditText et1,et2;
Button b1;
@Override
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
try {
String msg=et2.getText().toString();
smsManager.sendTextMessage(phno,null,msg,null,null);
Toast.LENGTH_LONG).show();
catch(Exception e)
Toast.LENGTH_LONG).show();
});
}
8)Develop a program to add "Hello World" marker at (10 ,10) co-ordinates. Write
only . java file. [W-23]
Activity_maps.xml
package com.example.googlemap;
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;
OnMapReadyCallback {
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to
be used.
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
mMap = googleMap;
World"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mumbai,10F));
mechanism.
user ID assigned to it, which means the application code runs in isolation
Therefore, one application has not granted access to other applications’ files.
Android application has been signed with a certificate with a private key
This allows the author of the application will be identified if needed. When
This user ID is permanent on which devices and applications with the same
It is mandatory for an application to list all the resources it will Access during
application
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
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,
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.
time, but only when the app that attempts to use permission is signed by the
same certificate as the app that defines the permission.
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
an app declares that it needs a dangerous permission, the user must explicitly
grant the permission to the app. Until the user approves the permission, your
dangerous permission, your app must prompt the user to grant permission at
runtime. For more details about how the user is prompted, see Request
9) Develop an application to send and receive SMS. (Write only Java and permission
tag in manifest file) [W-23]
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>
<receiver
android:name=".SmsReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
</receiver>
MainActivity.java
(Cosidering appropriate layout file with 2 edit text boxes namely for phone
number,
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;
EditText et1,et2;
Button b1;
@Override
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_SMS)
!=
PackageManager.PERMISSION_GRANTED)
ActivityCompat.requestPermissions(MainActivity.this,new
String[]{Manifest.permission.SEND_SMS},100);
b1.setOnClickListener(new View.OnClickListener() {
@Override
try {
String msg=et2.getText().toString();
smsManager.sendTextMessage(phno,null,msg,null,null);
Toast.LENGTH_LONG).show();
catch(Exception e)
{
Toast.makeText(MainActivity.this,"Sms failed to send... try again",
Toast.LENGTH_LONG).show();
});
@Override
super.onStart();
IntentFilter filter=new
IntentFilter("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(sms,filter);
@Override
super.onStop();
unregisterReceiver(sms);
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;
SmsReceiver(){}
@Override
if (bundle != null) {
Toast.LENGTH_SHORT).show();
10) Discuss Developer console with its purpose. [sample question paper]
11) Explain zoom control (IN / OUT) with the help of an example. [sample
question paper]
12) Describe types of permisions used while developing android applications.
[sample test paper]
For 6 Marks
activity_main.xml
<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">
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
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:"
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"
</RelativeLayout>
MainActivity.java
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
Button button;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sendto = findViewById(R.id.editText1);
subject = findViewById(R.id.editText2);
body = findViewById(R.id.editText3);
button = findViewById(R.id.button);
button.setOnClickListener(view -> {
intent.putExtra(Intent.EXTRA_SUBJECT, emailsubject);
intent.putExtra(Intent.EXTRA_TEXT, emailbody);
// set type of intent
intent.setType("message/rfc822");
createChooser function
});
(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;
GmailReceiver gml;
IntentFilter intf;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gml = new GmailReceiver();
@Override
super.onResume();
registerReceiver(gml, intf);
@Override
super.onDestroy();
unregisterReceiver(gml);
Gmailrerciever..java
package com.example.myemailprog;
import android.app.Notification;
import android.app.NotificationManager;
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
AndroidManifest.xml
<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>
</activity>
<receiver android:name="GmailReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.PROVIDER_CHANGED"
android:priority="-10">
</action>
android:pathPattern="/unread/.*">
</data>
</intent-filter>
</receiver>
</application>
</manifest>
2) Write a program to find the direction from user's current location to MSBTE,
Bandra. (Write only Java and manitest file).
(Note : Any other relevant logic to get the required output can also be considered.) [W-22]
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.msbte.google_map_currentlocationroute">
<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">
<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>
</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;
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;
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
com.google.android.gms.location.LocationListener , OnMapReadyCallback,
TaskLoadedCallback{
Button getDirection;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
requestMultiplePermissions();
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
@Override
mMap = googleMap;
mMap.clear();
mMap.addMarker(place1);
mMap.addMarker(place2);
.target(new LatLng(22.7739,71.6673))
.zoom(7)
.bearing(0)
.tilt(45)
.build();
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(googlePlex), 5000,
null);
// Origin of route
// Destination of route
// Mode
// Output format
return url;
@Override
if (currentPolyline != null)
currentPolyline.remove();
Dexter.withActivity(this)
.withPermissions(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION )
.withListener(new MultiplePermissionsListener() {
@Override
if (report.areAllPermissionsGranted()) {
user!", Toast.LENGTH_SHORT).show();
openSettingsDialog();
@Override
token.continuePermissionRequest();
}).
withErrorListener(new PermissionRequestErrorListener() {
@Override
Toast.LENGTH_SHORT).show();
} })
.onSameThread()
.check();
builder.setTitle("Required Permissions");
app settings.");
builder.setPositiveButton("Take Me To SETTINGS", new
DialogInterface.OnClickListener() {
@Override
dialog.cancel();
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setData(uri);
startActivityForResult(intent, 101);
});
@Override
dialog.cancel();
});
builder.show();
@Override
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 {
}}
@Override
mGoogleApiClient.connect();
@Override
}
@Override
super.onStart();
if (mGoogleApiClient != null) {
mGoogleApiClient.connect();
}}
@Override
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}}
mLocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(UPDATE_INTERVAL)
.setFastestInterval(FASTEST_INTERVAL);
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient,
mLocationRequest, this);
@Override
Double.toString(location.getLatitude()) + "," +
Double.toString(location.getLongitude());
tvLocation.setText(String.valueOf(location.getLatitude() +"
"+String.valueOf(location.getLongitude())));
if(isFirstTime){
getDirection = findViewById(R.id.btnGetDirection);
getDirection.setOnClickListener(new View.OnClickListener() {
@Override
new FetchURL(MainActivity.this).execute(getUrl(place1.getPosition(),
});
location.getLongitude())).title("Location 1");
LatLng(19.021824,72.8662016)).title("MSBTE");
mapFragment = (MapFragment)
getFragmentManager().findFragmentById(R.id.mapNearBy);
mapFragment.getMapAsync(this);
isFirstTime = false;
} }}
3) Develop and application to send and receive SMS (Design minimal UI as per 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) [S-22]
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>
<receiver
android:name=".SmsReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
</intent-filter>
</receiver>
activity_main.xml
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"
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;
EditText et1,et2;
Button b1;
@Override
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
try {
String msg=et2.getText().toString();
smsManager.sendTextMessage(phno,null,msg,null,null);
Toast.LENGTH_LONG).show();
catch(Exception e)
{
Toast.makeText(MainActivity.this,"Sms failed to send... try again",
Toast.LENGTH_LONG).show();
});
@Override
super.onStart();
IntentFilter filter=new
IntentFilter("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(sms,filter);
@Override
super.onStop();
unregisterReceiver(sms);
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;
SmsReceiver(){}
@Override
if (bundle != null) {
Toast.LENGTH_SHORT).show();
}
4) Develop an application to display Google map with user's current location. (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.)[S-22]
act ivity_main.xml
<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"
android:layout_width="match_parent"
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;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fusedLocationProviderClient =
LocationServices.getFusedLocationProviderClient(this);
fetchLastLocation();
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.addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
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);
}
});
} @Override
LatLng latLng=new
LatLng(currentlocation.getLatitude(),currentlocation.getLongitude());
.title("I am Here");
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,5));
googleMap.addMarker(markerOptions);
@Override
switch (requestCode) {
case REQUEST_CODE:
PackageManager.PERMISSION_GRANTED) {
fetchLastLocation();
break;
}
5) Develop a program to perform addition, subtraction, division, multiplication of
two numbers and display the result. (Use appropriate UI controls). [W-23]
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp">
<TextView
android:id="@+id/textResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="70dp"
android:background="#008080"
android:padding="5dp"
android:text="Code4Example"
android:textColor="#fff"
android:textSize="24sp"
android:textStyle="bold" />
<EditText
android:id="@+id/editNum1"
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<EditText
android:id="@+id/editNum2"
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/editNum1"
android:layout_centerInParent="true" />
<GridLayout
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_below="@+id/editNum2"
android:columnCount="2"
android:rowCount="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="1dp"
android:onClick="btnAdd"
android:text="+" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="1dp"
android:onClick="btnSub"
android:text="-" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="1dp"
android:onClick="btnMul"
android:text="*" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="1dp"
android:onClick="btnDiv"
android:text="/" />
</GridLayout>
</RelativeLayout>
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
EditText editNum1,editNum2;
TextView textResult;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editNum1= findViewById(R.id.editNum1);
editNum2= findViewById(R.id.editNum2);
textResult= findViewById(R.id.textResult);
textResult.setText(Double.toString(result));
textResult.setText(Double.toString(result));
textResult.setText(Double.toString(result));
textResult.setText(Double.toString(result));
Output:
6) Develop an application to display a Google Map. (Write JAVA & Manifest file) [W-
23]
AndroidManifest.xml code:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.com.mapexample">
<!--
ed to use
Google Maps Android API v2, but you must specify either coarse or fine
-->
<usespermission android:name="android.permission.ACCESS_FINE_LOCATION
" />
<usespermission android:name="android.permission.ACCESS_COARSE_LOCAT
ION" />
<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">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps">
<intent-filter>
</intent-filter>
</activity>
</application>
</manifest>
code of MapsActivity.java :
package example.com.mapexample;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
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;
allback{
private GoogleMap mMap;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used
Manager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
@Override
mMap = googleMap;
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sy
dney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
7) Develop an application to update a record of an employee whose emp.id is ‘E101’
in SQlite database. Change employee name from “POR" to “XYZ". Also display the
updated record (Write .java and .xml files). [W-23]
activity_update_emp.xml file
<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">
<EditText
android:id="@+id/idEdtEmpName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
<EditText
android:id="@+id/idEdtEmpSalary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
<Button
android:id="@+id/idBtnAddCourse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Add Employee"
android:textAllCaps="false" />
</LinearLayout>
DBHandler.java file
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
@Override
db.execSQL(query);
SQLiteDatabase db = this.getWritableDatabase();
values.put(NAME_COL, empName);
values.put(TRACKS_COL, empSalary);
db.close();
@Override
onCreate(db);
}
}
empRVAdapter.java file
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
empNameEdt = findViewById(R.id.idEdtempName);
empSalaryEdt = findViewById(R.id.idEdtempSalary);
addempBtn = findViewById(R.id.idBtnAddemp);
addCourseBtn.setOnClickListener(new View.OnClickListener() {
@Override
Toast.LENGTH_SHORT).show();
return;
dbHandler.addNewemp(empName, empSalary);
Toast.LENGTH_SHORT).show();
empNameEdt.setText("");
empSalaryEdt.setText("");
});
}
Update employee record java file:
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
// variables for our edit text, button, strings and dbhandler class.
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_update_emp);
empNameEdt = findViewById(R.id.idEdtempName);
empSalaryEdt = findViewById(R.id.idEdtempSalary);
updateempBtn = findViewById(R.id.idBtnUpdateemp);
empName = getIntent().getStringExtra("emp_name");
empSalary = getIntent().getStringExtra("emp_salary");
empNameEdt.setText(empName);
empSalaryEdt.setText(empSalary);
updateempBtn.setOnClickListener(new View.OnClickListener() {
@Override
dbHandler.updateemp(empName, empNameEdt.getText().toString(),
empSalaryEdt.getText().toString());
// displaying a toast message that our employee database has been updated.
Toast.LENGTH_SHORT).show();
startActivity(i);
}});
}
8) Describe all steps in application deployment on google playstore. ii) Write steps
for customized permissions. [W-23]
Publishing is the general process that makes your Android app available to users.
When you publish an Android app on google play store, you do the following:
During the preparation step, you build a release version of your app.
During the release step, you publicize, sell, and distribute the release version
of your app, which users can download and install on their Android-powered
devices.
1)Preparing your app for release is a multistep process involving the following tasks:
At a minimum, you need to make sure that logging is disabled and removed
and that your release variant has debuggable false for Groovy
or isDebuggable = false for Kotlin script set. You should also set your app's
version information.
You can use the Gradle build files with the release build type to build and
sign a release version of your app. For more information, see Build and run
your app.
Before you distribute your app, you should thoroughly test the release version
on at least one target handset device and one target tablet device. Firebase
Test Lab is useful for testing across a variety of devices and configurations.
Make sure that all app resources, such as multimedia files and graphics, are
updated and included with your app or staged on the proper production
servers.
Prepare remote servers and services that your app depends on.
If your app depends on external servers or services, make sure they are secure
2) Signing of Application
Application signing allows developers to identify the author of the application and
to update their application without creating complicated interfaces and
permissions.
Every application that is run on the Android platform must be signed by the
developer. Applications that attempt to install without being signed will be rejected
by either Google Play or the package installer on the Android device.
1) App signing
All APKs must be signed with a certificate whose private key is held by their
developer. The certificate does not need to be signed by a certificate authority. It's
allowable, and typical, for Android apps to use self-signed certificates. The purpose
of certificates in Android is to distinguish app authors. This lets the system grant or
deny apps access to signature-level permissions and grant or deny an app's request to
Starting in Android 12 (API level 31), the knownCerts attribute for signature-level
permissions lets you refer to the digests of known signing certificates at declaration
time.
You can declare the knownCerts attribute and use the knownSigner flag in your
system grants that permission to a requesting app if any signer in the requesting app's
signing lineage, including the current signer, matches one of the digests that's
The knownSigner flag lets devices and apps grant signature permissions to other
apps without having to sign the apps at the time of device manufacturing and
shipment.
At install time, Android gives each package a distinct Linux user ID. The identity
remains constant for the duration of the package's life on that device. On a different
device, the same package might have a different UID—what matters is that each
Because security enforcement happens at the process level, the code of any two
packages can't normally run in the same process, since they need to run as different
Linux users.
Any data stored by an app is assigned that app's user ID and isn't normally accessible
to other packages.
For example, an app that needs to control which other apps can start one of its
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp" >
<permission
android:name="com.example.myapp.permission.DEADLY_ACTIVITY"
android:label="@string/permlab_deadlyActivity"
android:description="@string/permdesc_deadlyActivity"
android:permissionGroup="android.permission-group.COST_MONEY"
android:protectionLevel="dangerous" />
...
</manifest>