MAD Winter

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 42

MAD Winter 23 Question Paper

1.Attempt any FIVE of the following: 10


a) List all tools and softwares required for developing an android application.
Ans. To develop an Android application, several tools and software components are required to
ensure a smooth development process. Here's a comprehensive list:
1. Integrated Development Environment (IDE)
Android Studio: The official IDE for Android development, provided by Google. It
supports Java, Kotlin, and C++ languages. Android Studio includes features like code
editing, debugging, and an Android Emulator.
Download Link: Android Studio

2. Java Development Kit (JDK)


JDK (Java Development Kit): Required for developing Android apps if you are using
Java. Android Studio automatically includes a bundled JDK, but you can install it
separately if needed.
Download Link: Java SE Development Kit

3. Kotlin
Kotlin: Android now officially supports Kotlin as a first-class language. You don’t need
to install it separately because Android Studio has built-in Kotlin support, but you can
use Kotlin plugins for external IDEs.
Learn More: Kotlin Language

4. Android SDK (Software Development Kit)


Android SDK: It includes all necessary tools to build and test Android apps, including
libraries, APIs, the emulator, and platform tools like adb and fastboot. Android SDK is
bundled with Android Studio.
Download Link: Android SDK

5. Gradle
Gradle: Android Studio uses Gradle as the build system. Gradle automates tasks like
building, testing, packaging, and deployment of Android apps. It is integrated into
Android Studio and automatically installed.
6. Emulators and Physical Devices
Android Virtual Device (AVD): The Android Emulator allows you to test your
applications on various Android device configurations directly from your development
environment.
Physical Device: For real-time testing, an actual Android device with USB Debugging
enabled is recommended.
7. Version Control System
Git: Used for version control. It helps in managing your codebase, handling
collaboration, and tracking changes. Git is often integrated with Android Studio.
Git Hosting Services:
GitHub: GitHub

GitLab: GitLab

Bitbucket: Bitbucket

8. Command-Line Tools
ADB (Android Debug Bridge): A command-line tool that allows developers to
communicate with a device (physical or virtual) for tasks like app installation, debugging,
and performance analysis. It is part of the Android SDK.
Fastboot: A protocol used for flashing devices or modifying the Android file system. It is
also part of the Android SDK.
9. Code Libraries and Dependencies
Jetpack Libraries: Android Jetpack is a set of libraries that help in simplifying Android
development, including components for UI, architecture, and performance.
Learn More: Android Jetpack

Google Play Services: Includes APIs like Maps, Location, Firebase, and others that are
essential for integrating Google services into your Android apps.
10. Database Tools
SQLite: Built-in relational database in Android, commonly used for data storage.
Room Library: Part of Android Jetpack, provides a higher-level database abstraction over
SQLite.
Realm: A modern database alternative to SQLite for Android apps.
Download Link: Realm Database

11. Design and UI Tools


XML (for Layout): Used to design the User Interface (UI) of the Android app. Android
Studio provides visual design tools for managing layouts.
Adobe XD / Figma / Sketch: UI/UX design tools to design app prototypes and
wireframes.
Figma: Figma

Adobe XD: Adobe XD

12. Testing and Debugging Tools


Android Profiler: Built into Android Studio for analyzing app performance (memory,
CPU, network, and energy consumption).
Espresso: Android’s official testing framework for UI testing.
Download Link: Espresso Testing Framework

JUnit: Used for writing unit tests for Android applications.


Firebase Test Lab: A cloud-based app-testing platform.
13. Backend Services
Firebase: A platform by Google offering real-time databases, authentication, crash
reporting, analytics, cloud messaging, and more.
Firebase Console: Firebase

14. Other Useful Tools


Android Asset Studio: A web-based tool to create launcher icons, notification icons, and
other assets required for Android apps.
Link: Android Asset Studio
ProGuard: Tool used for code shrinking, obfuscation, and optimization, helping to reduce
the size of APK files and improve security.
Crashlytics: Part of Firebase, helps in tracking and fixing crashes in production apps.
15. Miscellaneous
API Libraries: RESTful APIs or GraphQL APIs for backend interaction.
Retrofit: A popular library for making network requests.
OkHttp: HTTP client for networking.
IDE Plugins:
Lombok: Simplifies Java code writing by generating methods like getters, setters,
equals(), etc.
SonarLint: Code quality tool for static analysis.

b) Define emulator.
Ans.It helps us in testing the applications without the need of using the
application on an actual device.

c) List any four attributes of layout.


Ans.
android:layout_width
Defines the width of the view or layout.
Common values: match_parent (fills the parent), wrap_content (adjusts to the content), or
a specific size (e.g., 200dp).
Example: android:layout_width="match_parent"
android:layout_height
Defines the height of the view or layout.
Similar to layout_width, with values like match_parent, wrap_content, or a specific size.
Example: android:layout_height="wrap_content"
android:padding
Specifies the space between the content of the view and its boundary.
Can be applied to all sides (padding), or individually (e.g., paddingLeft, paddingRight,
etc.).
Example: android:padding="16dp"
android:orientation
Used in layouts like LinearLayout to define the direction of the arrangement of child
views.
Values: vertical or horizontal.
Example: android:orientation="vertical"
android:gravity
Controls the alignment of the content inside a view, such as text or child views.
Values: center, left, right, top, bottom, etc.
Example: android:gravity="center"
android:layout_margin
Defines the space outside the view's boundary, pushing it away from other views.
Like padding, margin can be applied to all sides (layout_margin), or individually (e.g.,
layout_marginLeft, layout_marginTop, etc.).
Example: android:layout_margin="8dp"

d) Define Geocoding and Reverse Geocoding.


Ans.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.
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.

e) State intent. List types of intent.


Ans.an Intent is a messaging object used to request an action from another component of the
application (or even from another application). It allows communication between different
components like activities, services, and broadcast receivers. Intents are used for:
Starting activities.
Starting services.
Delivering broadcasts.
Types of Intents
There are two main types of intents in Android:
1. Explicit Intent
Definition: An explicit intent is used to launch a specific activity or service within the
same application or a different one. In this type of intent, the target component (e.g., an
activity or service) is explicitly specified by its class name.
Use Case: Used when you know the exact component (activity, service, etc.) that should
handle the intent.
Example:
Intent intent = new Intent(this, TargetActivity.class);
startActivity(intent);
2. Implicit Intent
Definition: An implicit intent does not specify the target component explicitly. Instead, it
declares a general action to perform, and the Android system decides which component
(inside or outside the app) can best handle the request. It relies on the Android system to
match the intent with components that have registered for the specified action via an
intent filter.
Use Case: Used when you want an action to be handled by any application capable of
performing it (e.g., opening a web page, sharing content, etc.).
Example
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.example.com"));
startActivity(intent);
f) Write difference between toggle button and radio button.
Ans.

g) Define :
i) Fragment
ii) Broadcast receiver
Ans.i) Fragment
A Fragment in Android is a reusable portion of an application's user interface (UI) or behavior
that can be embedded in an activity. It represents a modular section of an activity, allowing for
flexible and dynamic UI designs. Fragments are often used for multi-pane layouts or when
different sections of the UI need to be updated independently. A fragment must be hosted within
an activity, and it has its own lifecycle that is closely related to the host activity’s lifecycle.
Key Characteristics of a Fragment:
Reusable UI Component: Can be reused in multiple activities.
Lifecycle: Has its own lifecycle methods (onCreate(), onStart(), etc.) that interact with
the activity's lifecycle.
Can Handle Input: Fragments can handle their own user input and can be updated
independently of other parts of the UI.
Dynamic UI: Fragments can be added, removed, or replaced dynamically during runtime.
ii) Broadcast Receiver
A Broadcast Receiver in Android is a component that responds to system-wide or application-
specific broadcast messages (also known as intents). Broadcasts can be sent by the Android
system (e.g., battery low, connectivity change) or by apps. A broadcast receiver does not display
a user interface but can initiate actions such as showing a notification, starting a service, or
updating the UI.
Key Characteristics of a Broadcast Receiver:
Responds to Broadcasts: Listens for broadcasted messages (intents) and reacts to specific
system or app events.
No UI: A broadcast receiver is not designed to display a UI, but it can initiate actions like
notifications or services.
Registered in Manifest or Dynamically: Broadcast receivers can be registered statically in
the AndroidManifest.xml file or dynamically at runtime via code.

2.Attempt any THREE of the following: 12


a) Explain relative layout with all its attributes.
Ans.RelativeLayout in Android
A RelativeLayout is a type of ViewGroup in Android that allows child views to be positioned
relative to each other or relative to the parent container. It's a versatile layout because you can
arrange UI components (buttons, text, etc.) in relation to sibling elements or to the parent without
worrying about absolute positions.
Key Characteristics of RelativeLayout:
Flexible Positioning: UI components can be positioned relative to each other or to the
parent container.
Overlapping Views: Views can overlap if required.
Efficiency: Reduces the need for nested layouts by allowing complex UI designs to be
achieved with fewer views.
Attributes of RelativeLayout
RelativeLayout has a number of attributes that define how child views are positioned. Here are
some important ones:
1. android:layout_alignParentTop
Aligns the top edge of the view with the top edge of the parent.
Value: true or false.
Example:
android:layout_alignParentTop="true"
2. android:layout_alignParentBottom
Aligns the bottom edge of the view with the bottom edge of the parent.
Value: true or false.
Example:
android:layout_alignParentBottom="true"
3. android:layout_alignParentLeft
Aligns the left edge of the view with the left edge of the parent.
Value: true or false.
Example:
android:layout_alignParentLeft="true"
4. android:layout_alignParentRight
Aligns the right edge of the view with the right edge of the parent.
Value: true or false.
Example:
android:layout_alignParentRight="true"
5. android:layout_centerHorizontal
Centers the view horizontally within the parent.
Value: true or false.
Example:
android:layout_centerHorizontal="true"
6. android:layout_centerVertical
Centers the view vertically within the parent.
Value: true or false.
Example:
android:layout_centerVertical="true"
7. android:layout_centerInParent
Centers the view both horizontally and vertically within the parent.
Value: true or false.
Example:
android:layout_centerInParent="true"
8. android:layout_toLeftOf
Positions the view to the left of another view (specified by the view's ID).
Value: Reference to another view’s ID (e.g., @id/view_id).
Example:
android:layout_toLeftOf="@id/another_view"
9. android:layout_toRightOf
Positions the view to the right of another view (specified by the view's ID).
Value: Reference to another view’s ID (e.g., @id/view_id).
Example:
android:layout_toRightOf="@id/another_view"
10. android:layout_above
Positions the view above another view (specified by the view's ID).
Value: Reference to another view’s ID (e.g., @id/view_id).
Example:
android:layout_above="@id/another_view"
11. android:layout_below
Positions the view below another view (specified by the view's ID).
Value: Reference to another view’s ID (e.g., @id/view_id).
Example:
android:layout_below="@id/another_view"
12. android:layout_alignTop
Aligns the top edge of the view with the top edge of another view (specified by the view's
ID).
Value: Reference to another view’s ID (e.g., @id/view_id).
Example:
android:layout_alignTop="@id/another_view"
13. android:layout_alignBottom
Aligns the bottom edge of the view with the bottom edge of another view (specified by
the view's ID).
Value: Reference to another view’s ID (e.g., @id/view_id).
Example:
android:layout_alignBottom="@id/another_view"
14. android:layout_alignLeft
Aligns the left edge of the view with the left edge of another view (specified by the
view's ID).
Value: Reference to another view’s ID (e.g., @id/view_id).
Example:
android:layout_alignLeft="@id/another_view"
15. android:layout_alignRight
Aligns the right edge of the view with the right edge of another view (specified by the
view's ID).
Value: Reference to another view’s ID (e.g., @id/view_id).
Example:
android:layout_alignRight="@id/another_view"
16. android:layout_margin
Specifies extra space outside the view's boundary.
Value: Dimension value (e.g., 10dp).
Example:
android:layout_margin="10dp"
17. android:layout_alignBaseline
Aligns the baseline of the view with the baseline of another view.
Value: Reference to another view’s ID (e.g., @id/view_id).
Example:
android:layout_alignBaseline="@id/another_view"
Example of a RelativeLayout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First TextView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button Below"
android:layout_below="@id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />

</RelativeLayout>

b) Explain all steps to install Android studio and SDK.


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

c) Explain the need of Android Operating System. Also describe any four features of
android.
Ans.The Android operating system (OS) was developed by Google to meet the growing need for
a flexible, open-source, and user-friendly platform for mobile devices. As mobile technology
advanced, there was a significant demand for an OS that could support:
Smartphones and tablets with touch interfaces, making it easier for users to interact with
devices.
Application development by providing a common framework for developers to build
diverse applications (apps) for different types of devices and manufacturers.
Customization by device manufacturers and developers, which allows for innovation and
device differentiation.
Scalability across different types of hardware, including smartphones, tablets, smart TVs,
watches, and cars.
Cost-effectiveness by being open-source and royalty-free, allowing manufacturers to
adopt the OS without licensing fees.
High-quality user experience, given the increase in expectations for features like
multitasking, multimedia, internet access, and mobile computing.
6 Key Features of Android OS in Detail
Open-Source Platform
Android is based on the Linux kernel and is an open-source platform, which means its
source code is available to developers for free. This openness allows:
Manufacturers and developers to customize and modify the OS to suit their needs.
Innovation from a wide community of developers and device makers.
A rich ecosystem of third-party apps, devices, and services.
Support for Multiple Connectivity Options Android supports various connectivity
standards such as:
Wi-Fi: Allows devices to connect to the internet through wireless networks.
Bluetooth: Enables devices to communicate over short distances for file sharing, wireless
headphones, and IoT devices.
NFC (Near Field Communication): Supports wireless communication over short ranges,
used for payments and data exchanges.
USB: For wired data transfer, device charging, and peripheral connections.
This flexibility makes Android devices versatile for different connectivity needs, whether for
personal use, IoT, or enterprise applications.
Rich Application Ecosystem (Google Play Store) Android has a vast marketplace for
apps, primarily through the Google Play Store, which:
Provides access to millions of apps across categories such as productivity, gaming,
communication, and entertainment.
Allows third-party developers to easily publish apps to a global audience.
Enables frequent updates to apps and system components, ensuring security and
functionality improvements.
This robust app ecosystem is one of the key strengths of the Android platform.
Multitasking and Multi-Window Support Android provides true multitasking capabilities,
allowing users to run multiple applications simultaneously, such as:
Listening to music while browsing the web or using a productivity app.
Switching between apps quickly using the task manager.
Multi-window support (available in recent versions) allows users to run apps side by side
or in split-screen mode, boosting productivity, especially on tablets and larger devices.
Customization and Widgets One of Android’s standout features is the high degree of
customization available to both users and developers:
Home Screen Widgets: Android allows users to place interactive widgets directly on the
home screen, such as weather updates, music controls, and calendar events, providing
quick access to important information.
Launchers: Users can install custom launchers to change the overall look and feel of their
device's interface.
Themes: Android provides the ability to change themes, wallpapers, and icons easily,
making the device truly personalized.
Customization options empower users to tailor their Android experience to their preferences.
Google Integration and Cloud Support Android tightly integrates with Google services,
including:
Google Drive: For cloud storage and file synchronization across devices.
Google Photos: For automatic photo backups.
Gmail: For email services.
Google Assistant: For voice-controlled tasks, reminders, and search.
Google Maps: For navigation and location services.
This deep integration with Google’s ecosystem enhances the user's experience by providing
seamless access to services across devices. It also ensures that users can easily synchronize their
data and apps across different Android devices.

d) Develop a program to add “Hello World” marker at (10,10) co-ordinates. Write only .
java file.
Ans.package com.example.helloworldmarker;

import android.os.Bundle;
import androidx.fragment.app.FragmentActivity;
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;

public class MainActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

// Define the coordinates for the marker


LatLng helloWorldLocation = new LatLng(10, 10); // Coordinates (10, 10)
// Add a marker at the specified coordinates and set the title
mMap.addMarker(new MarkerOptions().position(helloWorldLocation).title("Hello World"));

// Move the camera to the marker


mMap.moveCamera(CameraUpdateFactory.newLatLng(helloWorldLocation));
}
}

3.Attempt any THREE of the following: 12


a) Describe service life cycle with its diagram.
Ans.he user in the background.
â— Services are used for repetitive and potentially long running operations, i.e.,
Internet downloads, checking for new data, data processing, updating content
providers and the like.
â— Service can either be started or bound we just need to call either startService() or
bindService() from any of our android components. Based on how our service
was started it will either be “started†or “boundâ€

Service Lifecycle
1. Started
a. A service is started when an application component, such as an activity,
starts it by calling startService().
b. Now the service can run in the background indefinitely, even if the
component that started it is destroyed.
2. Bound
a. A service is bound when an application component binds to it by calling
bindService().
b. A bound service offers a client-server interface that allows components to
interact with the service, send requests, get results, and even do so across
processes with InterProcess Communication (IPC).
c. Like any other components service also has callback methods. These will
be invoked while the service is running to inform the application of its
state. Implementing these in our custom service would help you in
performing the right operation in the right state. •
d. There is always only a single instance of service running in the app. If you
are calling startService() for a single service multiple times in our
application it just invokes the onStartCommand() on that service. Neither
is the service restarted multiple times nor are its multiple instances created
1. onCreate():
This is the first callback which will be invoked when any component starts the
service. If the same service is called again while it is still running this method
wont be invoked. Ideally one time setup and intializing should be done in this
callback.
2. onStartCommand() /startSetvice()
This callback is invoked when service is started by any component by calling
startService(). It basically indicates that the service has started and can now run
indefinetly.
3. onBind()
To provide binding for a service, you must implement the onBind() callback
method. This method returns an IBinder object that defines the programming
interface that clients can use to interact with the service.
4. onUnbind()
This is invoked when all the clients are disconnected from the service.
5. onRebind()
This is invoked when new clients are connected to the service. It is called after
onRebind
6. onDestroy()
This is a final clean up call from the system. This is invoked just before the
service is being destroyed.

b) Elaborate Android Security Model.


Ans.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. Terms are required of an application, in the installation process should be
user-based or interactive Check with the signature of the application.
Declaring and Using Permissions
The purpose of a permission is to protect the privacy of an Android user. Android apps must
request permission to access sensitive user data (such as contacts and SMS), as well as certain
system features (such as camera and internet). Depending on the feature, the system might grant
the permission automatically or might prompt the user to approve the request.
Permissions are divided into several protection levels. The protection level affects whether
runtime permission requests are required. There are three protection levels that affect third
party apps: normal, signature, and dangerous permissions.
Normal permissions: Normal permissions cover areas where your app needs to access data or
resources outside the app’s sandbox, but where there’s very little risk to the user’s
privacy or
the operation of other apps. For example, permission to set the time zone is a normal
permission. If an app declares in its manifest that it needs a normal permission, the system
automatically grants the app that permission at install time. The system doesn’t prompt the
user
to grant normal permissions, and users cannot revoke these permissions.
Signature permissions: The system grants these app permissions at install time, but only when
the app that attempts to use permission is signed by the same certificate as the app that defines
the permission.
Dangerous permissions: Dangerous permissions cover areas where the app wants data or
resources that involve the user’s private information, or could potentially affect the
user’s
stored data or the operation of other apps. For example, the ability to read the user’s contacts
is
a dangerous permission. If an app declares that it needs a dangerous permission, the user must
explicitly grant the permission to the app. Until the user approves the permission, your app
cannot provide functionality that depends on that permission. To use a dangerous permission,
your app must prompt the user to grant permission at runtime. For more details about how the
user is prompted, see Request prompt for dangerous permission

c) Write an xml file to create login page using Table Layout.


Ans.<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">

<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">

<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username:"
android:layout_marginEnd="8dp"
android:gravity="end"/>

<EditText
android:id="@+id/editTextUsername"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Enter Username" />
</TableRow>

<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password:"
android:layout_marginEnd="8dp"
android:gravity="end"/>

<EditText
android:id="@+id/editTextPassword"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Enter Password"
android:inputType="textPassword" />
</TableRow>

<TableRow>
<Button
android:id="@+id/buttonLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_span="2"
android:layout_gravity="center" />
</TableRow>
</TableLayout>
</RelativeLayout>

d) Develop an application to display analog Time Picker. Also display the selected time. (Write
only . java file)
Ans.package com.example.analogtimepicker;

import android.app.TimePickerDialog;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Calendar;

public class MainActivity extends AppCompatActivity {

private TextView selectedTimeTextView;


private Button pickTimeButton;

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

selectedTimeTextView = findViewById(R.id.selectedTimeTextView);
pickTimeButton = findViewById(R.id.pickTimeButton);

pickTimeButton.setOnClickListener(view -> showTimePicker());


}

private void showTimePicker() {


// Get the current time
Calendar calendar = Calendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
int minute = calendar.get(Calendar.MINUTE);

// Create TimePickerDialog
TimePickerDialog timePickerDialog = new TimePickerDialog(this,
(view, selectedHour, selectedMinute) -> {
// Display the selected time
String selectedTime = String.format("%02d:%02d", selectedHour, selectedMinute);
selectedTimeTextView.setText("Selected Time: " + selectedTime);
},
hour,
minute,
true); // true for 24-hour format, false for 12-hour format

timePickerDialog.setTitle("Select Time");
timePickerDialog.show();
}
}

4.Attempt any THREE of the following: 12


a) Differentiate between JVM and DVM. (Any four points)
Ans.

b) Explain components of android directory structure.


Ans.

c) Develop an android application using radio button.


Ans.<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select your favorite fruit:"
android:textSize="18sp" />

<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<RadioButton
android:id="@+id/radioApple"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Apple" />

<RadioButton
android:id="@+id/radioBanana"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Banana" />

<RadioButton
android:id="@+id/radioCherry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cherry" />

</RadioGroup>

<Button
android:id="@+id/submitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_marginTop="20dp" />

<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textSize="18sp" />
</LinearLayout>
package com.example.radiobuttonexample;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private RadioGroup radioGroup;


private Button submitButton;
private TextView resultTextView;

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

radioGroup = findViewById(R.id.radioGroup);
submitButton = findViewById(R.id.submitButton);
resultTextView = findViewById(R.id.resultTextView);

// Set an OnClickListener on the submit button


submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Get the selected radio button
int selectedId = radioGroup.getCheckedRadioButtonId();
RadioButton selectedRadioButton = findViewById(selectedId);

if (selectedRadioButton != null) {
// Display the selected option
String selectedText = selectedRadioButton.getText().toString();
resultTextView.setText("Selected Option: " + selectedText);
} else {
resultTextView.setText("No option selected.");
}
}
});
}
}

d) Develop an application to send and receive SMS.(Write only . java and permission tag in
manifest file)(S22,5c)
Ans.Permissions and <receiver> tag required in AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<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>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="81dp"
android:layout_height="41dp"
android:layout_marginEnd="268dp"
android:layout_marginBottom="576dp"
android:text="To :"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="@+id/textView2"
android:layout_width="70dp"
android:layout_height="43dp"
android:layout_marginEnd="276dp"
android:layout_marginBottom="512dp"
android:text="Sms Text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<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;
public class MainActivity extends AppCompatActivity {
SmsReceiver sms= new SmsReceiver();
EditText et1,et2;
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=findViewById(R.id.etPhno);
et2=findViewById(R.id.etmsg);
b1=findViewById(R.id.btnSms);
if(ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.SEN
D_SMS)!=
PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(MainActivity.this,new
String[]{Manifest.permission.SEND_SMS},100);
}
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String phno= et1.getText().toString();
String msg=et2.getText().toString();
SmsManager smsManager= SmsManager.getDefault();
smsManager.sendTextMessage(phno,null,msg,null,null);
Toast.makeText(MainActivity.this,"Sms sent successfully",
Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(MainActivity.this,"Sms failed to send... try again",
Toast.LENGTH_LONG).show();
}
}
});
}
@Override
protected void onStart() {
super.onStart();
IntentFilter filter=new
IntentFilter("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(sms,filter);
}
@Override
protected void onStop() {
super.onStop();
unregisterReceiver(sms);
}
}
SmsReceiver.java
package com.example.testreceivesms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class SmsReceiver extends BroadcastReceiver {
SmsReceiver(){}
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
// Retrieve the SMS Messages received
Object[] sms = (Object[]) bundle.get("pdus");
// For every SMS message received
for (int i=0; i < sms.length; i++) {
// Convert Object array
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);
String phone = smsMessage.getOriginatingAddress();
String message = smsMessage.getMessageBody().toString();
Toast.makeText(context, “Received from “+ phone + ": " + message,
Toast.LENGTH_SHORT).show();
}
}
}
}

e) Draw and explain activity life cycle.


Ans.

Activities have a predefined life-cycle methods as follows:


onCreate (): Called then the activity is created. Used to initialize the activity, for
example create the user interface.
onStart ():called when activity is becoming visible to the user.
onResume (): Called if the activity get visible again and the user starts interacting
with the activity again. Used to initialize fields, register listeners, bind
to services, etc.
onPause (): Called once another activity gets into the foreground. Always called
before the activity is not visible anymore. Used to release resources or
save application data. For example you unregister listeners, intent
receivers, unbind from services or remove system service listeners.
onStop (): Called once the activity is no longer visible. Time or CPU intensive shutdown
operations, such as writing information to a database should be down in the onStop() method.
This method is guaranteed to be called as
of API 11.
onDestroy (): called before the activity is destroyed

5.Attempt any TWO of the following: 12

a) Develop a program to perform addition, subtraction, division, multiplication of two numbers


and display the result. (Use appropriate UI controls)
Ans.<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculator"
android:textSize="24sp"
android:layout_gravity="center"
android:layout_marginBottom="16dp"/>

<EditText
android:id="@+id/number1EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter first number"
android:inputType="numberDecimal"
android:layout_marginBottom="8dp"/>

<EditText
android:id="@+id/number2EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter second number"
android:inputType="numberDecimal"
android:layout_marginBottom="16dp"/>

<Button
android:id="@+id/addButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add"
android:layout_marginBottom="8dp"/>

<Button
android:id="@+id/subtractButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subtract"
android:layout_marginBottom="8dp"/>

<Button
android:id="@+id/multiplyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Multiply"
android:layout_marginBottom="8dp"/>

<Button
android:id="@+id/divideButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Divide"
android:layout_marginBottom="16dp"/>

<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_gravity="center" />
</LinearLayout>
package com.example.calculator;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private EditText number1EditText;


private EditText number2EditText;
private TextView resultTextView;
private Button addButton, subtractButton, multiplyButton, divideButton;

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

number1EditText = findViewById(R.id.number1EditText);
number2EditText = findViewById(R.id.number2EditText);
resultTextView = findViewById(R.id.resultTextView);

addButton = findViewById(R.id.addButton);
subtractButton = findViewById(R.id.subtractButton);
multiplyButton = findViewById(R.id.multiplyButton);
divideButton = findViewById(R.id.divideButton);

// Set OnClickListener for Add button


addButton.setOnClickListener(view -> performOperation("add"));

// Set OnClickListener for Subtract button


subtractButton.setOnClickListener(view -> performOperation("subtract"));

// Set OnClickListener for Multiply button


multiplyButton.setOnClickListener(view -> performOperation("multiply"));

// Set OnClickListener for Divide button


divideButton.setOnClickListener(view -> performOperation("divide"));
}

private void performOperation(String operation) {


// Get the input numbers
double number1 = Double.parseDouble(number1EditText.getText().toString());
double number2 = Double.parseDouble(number2EditText.getText().toString());
double result;

// Perform the chosen operation


switch (operation) {
case "add":
result = number1 + number2;
break;
case "subtract":
result = number1 - number2;
break;
case "multiply":
result = number1 * number2;
break;
case "divide":
// Check for division by zero
if (number2 == 0) {
resultTextView.setText("Cannot divide by zero.");
return;
}
result = number1 / number2;
break;
default:
result = 0;
break;
}

// Display the result


resultTextView.setText("Result: " + result);
}
}

b) Develop an application to display a Google Map.(Write JAVA and Manifest file)


Ans.<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googlemapexample">

<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.GoogleMapExample">

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY_HERE"/> <!-- Replace with your actual API Key -->

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

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


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

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
package com.example.googlemapexample;

import android.os.Bundle;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {

private MapView mapView;


private GoogleMap googleMap;

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

// Initialize the MapView


mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}
@Override
public void onMapReady(@NonNull GoogleMap map) {
googleMap = map;

// Set a marker on a specific location


LatLng location = new LatLng(-34, 151); // Example coordinates for Sydney
googleMap.addMarker(new MarkerOptions().position(location).title("Marker in Sydney"));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(location));
}
@Override
protected void onResume() {
super.onResume();
mapView.onResume();
}
@Override
protected void onPause() {
super.onPause();
mapView.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
}

c) Develop an application to convert “thanks” text to speech as given in the following


GUI.TextToSpeechDemo
Android Text to Speech (TTS)
Demo
thanks|
CLICK TO CONVERT TEXT TO SPEECH
Ans.<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.texttospeechdemo">

<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.TextToSpeechDemo">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="thanks"
android:textSize="24sp"
android:layout_gravity="center" />

<Button
android:id="@+id/speakButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CLICK TO CONVERT TEXT TO SPEECH"
android:layout_marginTop="20dp"/>
</LinearLayout>
package com.example.texttospeechdemo;

import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Locale;

public class MainActivity extends AppCompatActivity {

private TextToSpeech textToSpeech;


private TextView textView;
private Button speakButton;

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

textView = findViewById(R.id.textView);
speakButton = findViewById(R.id.speakButton);

// Initialize TextToSpeech
textToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = textToSpeech.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA || result ==
TextToSpeech.LANG_NOT_SUPPORTED) {
// Handle the error if language is not supported
}
}
}
});

// Set OnClickListener on the button


speakButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
speakOut();
}
});
}

private void speakOut() {


String text = textView.getText().toString();
textToSpeech.speak(text, TextToSpeech.QUEUE_FLUSH, null, null);
}

@Override
protected void onDestroy() {
// Shutdown the TextToSpeech engine
if (textToSpeech != null) {
textToSpeech.stop();
textToSpeech.shutdown();
}
super.onDestroy();
}
}

6.Attempt any TWO of the following: 12


a) Develop an application to update a record of an employee whose emp.id is ‘E101’ in SQlite
database. Change employee name from “PQR” to “XYZ”. Also display the updated record.
(Write .java and .xml files)
Ans.<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<Button
android:id="@+id/updateButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Update Employee Record" />

<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textSize="18sp" />
</LinearLayout>
package com.example.employeedatabase;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "EmployeeDB.db"


private static final int DATABASE_VERSION = 1;
private static final String TABLE_NAME = "employees"
private static final String COLUMN_ID = "emp_id"
private static final String COLUMN_NAME = "emp_name"

public DatabaseHelper(Context context) {


super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
String createTable = "CREATE TABLE " + TABLE_NAME + " (" +
COLUMN_ID + " TEXT PRIMARY KEY, " +
COLUMN_NAME + " TEXT)"
db.execSQL(createTable);
// Insert initial record
ContentValues values = new ContentValues();
values.put(COLUMN_ID, "E101");
values.put(COLUMN_NAME, "PQR");
db.insert(TABLE_NAME, null, values);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}

// Update employee name


public boolean updateEmployeeName(String empId, String newName) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(COLUMN_NAME, newName);

int rowsAffected = db.update(TABLE_NAME, values, COLUMN_ID + " = ?", new String[]


{empId});
return rowsAffected > 0; // Return true if update is successful
}

// Get employee record


public Cursor getEmployee(String empId) {
SQLiteDatabase db = this.getReadableDatabase();
return db.query(TABLE_NAME, null, COLUMN_ID + " = ?", new String[]{empId}, null, null,
null);
}
}
package com.example.employeedatabase;

import android.database.Cursor;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


private DatabaseHelper databaseHelper;
private TextView resultTextView;
private Button updateButton;

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

databaseHelper = new DatabaseHelper(this);


resultTextView = findViewById(R.id.resultTextView);
updateButton = findViewById(R.id.updateButton);

updateButton.setOnClickListener(v -> updateEmployeeRecord());


}

private void updateEmployeeRecord() {


String empId = "E101"
String newName = "XYZ"

// Update employee name


boolean isUpdated = databaseHelper.updateEmployeeName(empId, newName);
if (isUpdated) {
// Fetch and display updated record
Cursor cursor = databaseHelper.getEmployee(empId);
if (cursor != null && cursor.moveToFirst()) {
String id = cursor.getString(cursor.getColumnIndex("emp_id"));
String name = cursor.getString(cursor.getColumnIndex("emp_name"));
resultTextView.setText("Employee ID: " + id + "\nEmployee Name: " + name);
cursor.close();
}
} else {
resultTextView.setText("Update failed");
}
}
}

b) i) Describe all steps in application deployment on google playstore.


ii) Write steps for customized permissions.
Ans.I. Application Deployment on Google Play Store
Create a Google Play Developer Account:
Go to the Google Play Console.
Sign in with your Google account.
Pay the one-time registration fee (currently $25).
Fill out your account details and agree to the Developer Distribution Agreement.
Prepare Your Application:
Ensure your app is complete and thoroughly tested.
Generate a signed APK or App Bundle using Android Studio.
In Android Studio, go to Build > Generate Signed Bundle / APK.
Follow the prompts to sign your app with a release key.
Prepare Store Listing:
Go to your Google Play Console.
Click on All apps > Create app.
Fill out the required information:
App name
Default language
App or game (choose between these two categories)
Free or paid (choose your pricing model)
Complete the Store Listing:
Provide details about your app, including:
Description: A short and long description of your app.
Screenshots: Upload screenshots of your app.
App icon: Create and upload a high-resolution app icon.
Feature graphic: Create and upload a feature graphic (recommended size: 1024x500
pixels).
Promo video (optional): Link to a YouTube video showcasing your app.
Set Content Rating:
Complete the content rating questionnaire to determine your app’s rating.
The Play Store will assign a rating based on your responses.
Select Distribution Options:
Choose the countries where you want your app to be available.
Decide whether to make your app available for specific devices or Android versions.
Upload APK or App Bundle:
In the App releases section, select Production > Create Release.
Upload your signed APK or App Bundle.
You can also add release notes for users.
Set Up Pricing and Distribution:
If your app is paid, set the price and confirm your distribution options.
For free apps, you can skip this step.
Publish Your App:
After reviewing all the details, go to the App release section and click Review.
If everything looks good, click Start rollout to production.
Confirm your action, and your app will be submitted for review by Google.
Monitor Your App:
Once your app is live, you can track its performance through the Play Console.
Monitor user feedback, reviews, crashes, and other metrics.

II. Steps for Customized Permissions


Define the Permission in the AndroidManifest.xml:
To create a custom permission, define it within the <manifest> tag of your
AndroidManifest.xml file. For example:
Request the Permission in Your App:
Declare the custom permission that your app requires in the AndroidManifest.xml file.
For example:
Check for Permission (if applicable):
If your app is targeting Android 6.0 (API level 23) or higher, you need to check and
request the permission at runtime. You can do this as follows:
Handle the Permission Request Response:
Override onRequestPermissionsResult() in your Activity to handle the user's response to
the permission request.
Use the Custom Permission:
Implement the functionality that requires this permission in your app. For example, you
might need to access certain resources or perform actions based on the granted
permission.
Test the Permission:
Test your app to ensure that it correctly requests, checks, and uses the custom permission.

c) Develop a program to TURN ON and OFF bluetooth. Write .java file and permission tags.
Ans.<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bluetoothtoggle">

<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:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.BluetoothToggle">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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


</intent-filter>
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">

<Button
android:id="@+id/buttonTurnOn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn On Bluetooth" />

<Button
android:id="@+id/buttonTurnOff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn Off Bluetooth" />

<TextView
android:id="@+id/statusTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_marginTop="20dp" />
</LinearLayout>
package com.example.bluetoothtoggle;
import android.bluetooth.BluetoothAdapter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private BluetoothAdapter bluetoothAdapter;


private TextView statusTextView;

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

bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
statusTextView = findViewById(R.id.statusTextView);

// Update the status


updateStatus();

Button buttonTurnOn = findViewById(R.id.buttonTurnOn);


Button buttonTurnOff = findViewById(R.id.buttonTurnOff);

buttonTurnOn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
turnOnBluetooth();
}
});

buttonTurnOff.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
turnOffBluetooth();
}
});
}

private void turnOnBluetooth() {


if (bluetoothAdapter != null && !bluetoothAdapter.isEnabled()) {
bluetoothAdapter.enable();
updateStatus();
}
}

private void turnOffBluetooth() {


if (bluetoothAdapter != null && bluetoothAdapter.isEnabled()) {
bluetoothAdapter.disable();
updateStatus();
}
}

private void updateStatus() {


if (bluetoothAdapter == null) {
statusTextView.setText("Bluetooth not supported");
} else if (bluetoothAdapter.isEnabled()) {
statusTextView.setText("Bluetooth is ON");
} else {
statusTextView.setText("Bluetooth is OFF");
}
}
}

You might also like