Unit 1
Unit 1
UNIT-1
1.1 Introduction
Talking about the mobile applications, the first thing that comes to mind are the apps like WhatsApp,
Instagram, swigy, etc that we use in our everyday life.
Ever thought about how these apps are made? Which technology is used? Let’s discuss what technologies or
frameworks can be used to develop a mobile application.
Example:
Here’s an example of a 1st party native app:
A retail company wants to improve the in-store shopping experience for its customers. They develop
a 1st party native app that allows customers to:
Browse the store’s inventory and product information
Create a shopping list
Scan barcodes to view product information and reviews
Locate items in the store using an interactive map
Pay for items directly through the app, without having to wait in line at the register
The app is only available to the company’s customers and can only be used in their physical
stores. The app is designed to integrate with the company’s existing systems, such as inventory
management and point-of-sale systems.
This app is developed by the retail company for their own use, to improve the in-store customer
experience, increase sales and gain insights from the customer’s behaviour.
Mobile Computing and App Development
In this example, the retail company is the 1st party, and the app is a native app, because it is developed
for the specific platform (iOS or Android) and can take full advantage of the device’s capabilities and
features.
2. Progressive web Application: Progressive web apps are essentially a website which runs locally on
your device. The technologies used are Microsoft Blazor, React, Angular JS, Native Script, Iconic.
These technologies normally used for web development propose. The apps’ UI is developed the same
way as they are developed while developing the website. This category has many ups and downs let’s
start with the advantages of Progressive web apps.
Example:
Here’s an example of a Progressive Web App:
A news website wants to provide its users with a better mobile experience. They develop a Progressive
Web App that:
Allows users to access the website offline by storing content on the user’s device
Sends push notifications to users to alert them of breaking news
Can be installed on the user’s home screen like a native app
Provides a fast and smooth browsing experience
Has a responsive design that adapts to different screen sizes
Users can access the PWA by visiting the website on their mobile browser. They are prompted
to install the PWA on their home screen, which allows them to access the website offline and
receive push notifications.
In this example, the news website is the 1st party and the app is a Progressive web app, because it can
be accessed through a web browser and can be installed on the user’s device like a native app. It also
allows users to access the content offline and have a fast and smooth experience.
3. Cross-Platform Application: These are frameworks that allow developing total native applications
which have access to all the native features of IOS and Android but with the same code base. These
apps run on both Android and IOS. So normally the development speeds of these apps are very fast
and the maintenance cost is low. The performance speed is comparatively low to 1st party native apps
but faster than PWA.
Xamarin is Microsoft cross-platform solution that uses the programming languages like .NET, C#, F#.
The IDE preferred is Visual Studio. The UI/UX is totally native giving access to all features. This
technology is having a wide community. And whenever an update is released by Android and IOS the
same updates are released by Microsoft through Visual Studio.
React Native is Facebook’s cross-platform solution which uses the language JavaScript And the
preferred IDE is WebStrome & Visual Studio Code. Same like Xamarin React Native has totally native
UI/UX and gives access to all features. And the updates are released the same day by Facebook as
Android and IOS.
Flutter is Google’s cross-platform solution which uses the language, Dart. The IDE preferred is
Android Studio, IntelliJ IDE, and Visual Studio Code. The UI/UX is bespoke and Flutters has to come
up with their new libraries whenever Android and IOS comes up with an update to mimic those update.
The community is fast growing.
Mobile Computing and App Development
Example:
Here’s an example of a cross-platform application:
A project management company wants to create a project management tool that can be used by teams
on different platforms. They develop a cross-platform application that Can be used on Windows, Mac,
iOS, and Android devices:
Allows users to create and assign tasks, set deadlines, and track progress
Integrates with popular tools such as Google Calendar and Trello
Has a user-friendly interface that works seamlessly across all platforms
The application can be downloaded from the company’s website or from different app stores
such as App Store, Google Play Store, Microsoft Store, and Mac App Store, depending on the
platform.
This example illustrates how the company developed a project management tool that can be used by
teams on different platforms, Windows, Mac, iOS and Android, which is a cross-platform application.
It allows teams to collaborate and manage their projects seamlessly, regardless of the platform they
use.
Native Apps: A Native App is an application specifically designed for a particular platform or
device.
Mobile Computing and App Development
Web Apps: A Web App is concerned with an application that is designed to deliver web pages on
different web platforms for any device.
Hybrid Apps: A Hybrid App is a combination of both native & web applications. It can be
developed for any platform from a single code base.
The entire feature-set of the Android OS is available to you through APIs written in the Java language.
These APIs form the building blocks you need to create Android apps by simplifying the reuse of core,
modular system components and services, which include the following:
A rich and extensible view system you can use to build an app’s UI, including lists, grids, text boxes,
buttons, and even an embeddable web browser
A resource manager, providing access to non-code resources such as localized strings, graphics, and
layout files
A notification manager that enables all apps to display custom alerts in the status bar
An activity manager that manages the lifecycle of apps and provides a common navigation back
stack
Content providers that enable apps to access data from other apps, such as the Contacts app, or to
share their own data
Developers have full access to the same framework APIs that Android system apps use.
System apps
Android comes with a set of core apps for email, SMS messaging, calendars, internet browsing, contacts,
and more. Apps included with the platform have no special status among the apps the user chooses to install.
So, a third-party app can become the user's default web browser, SMS messenger, or even the default
keyboard. Some exceptions apply, such as the system's Settings app.
The system apps function both as apps for users and to provide key capabilities that developers can access
from their own app. For example, if you want your app to deliver SMS messages, you don't need to build
that functionality yourself. You can instead invoke whichever SMS app is already installed to deliver a
message to the recipient you specify.
There are some necessary building blocks that an Android application consists of. These loosely coupled
components are bound by the application manifest file which contains the description of each component
and how they interact. The manifest file also contains the app’s metadata, its hardware configuration, and
platform requirements, external libraries, and required permissions. There are the following main
components of an android app:
1. Activities:
Activities are said to be the presentation layer of our applications. The UI of our application is built around
one or more extensions of the Activity class. By using Fragments and Views, activities set the layout and
display the output and also respond to the user’s actions. An activity is implemented as a subclass of class
Activity.
class MainActivity : AppCompatActivity() {
}
Mobile Computing and App Development
2. Services:
Services are like invisible workers of our app. These components run at the backend, updating your data
sources and Activities, triggering Notification, and also broadcast Intents. They also perform some tasks when
applications are not active. A service can be used as a subclass of class Service:
class ServiceName : Service() {
}
3. Content Providers:
It is used to manage and persist the application data also typically interacts with the SQL database. They are
also responsible for sharing the data beyond the application boundaries. The Content Providers of a particular
application can be configured to allow access from other applications, and the Content Providers exposed by
other applications can also be configured.
A content provider should be a sub-class of the class ContentProvider.
class contentProviderName : ContentProvider() {
override fun onCreate(): Boolean {}
}
4. Broadcast Receivers:
They are known to be intent listeners as they enable your application to listen to the Intents that satisfy the
matching criteria specified by us. Broadcast Receivers make our application react to any received Intent
thereby making them perfect for creating event-driven applications.
5. Intents:
It is a powerful inter-application message-passing framework. They are extensively used throughout
Android. Intents can be used to start and stop Activities and Services, to broadcast messages system-wide or
to an explicit Activity, Service or Broadcast Receiver or to request action be performed on a particular piece
of data.
6. Widgets:
These are the small visual application components that you can find on the home screen of the devices. They
are a special variation of Broadcast Receivers that allow us to create dynamic, interactive application
components for users to embed on their Home Screen.
7. Notifications:
Notifications are the application alerts that are used to draw the user’s attention to some particular app event
without stealing focus or interrupting the current activity of the user. They are generally used to grab user’s
attention when the application is not visible or active, particularly from within a Service or Broadcast
Receiver. Examples: E-mail popups, Messenger popups, etc.
Mobile Computing and App Development
Every project in Android includes a Manifest XML file, which is AndroidManifest.xml, located in the root
directory of its project hierarchy. The manifest file is an important part of our app because it defines the
structure and metadata of our application, its components, and its requirements. This file includes nodes for
each of the Activities, Services, Content Providers, and Broadcast Receivers that make the application, and
using Intent Filters and Permissions determines how they coordinate with each other and other applications.
The manifest file also specifies the application metadata, which includes its icon, version number, themes,
etc., and additional top-level nodes can specify any required permissions, and unit tests, and define hardware,
screen, or platform requirements. The manifest comprises a root manifest tag with a package attribute set to
the project’s package. It should also include an xmls:android attribute that will supply several system attributes
used within the file. We use the versionCode attribute is used to define the current application version in the
form of an integer that increments itself with the iteration of the version due to update. Also, the versionName
attribute is used to specify a public version that will be displayed to the users.
We can also specify whether our app should install on an SD card of the internal memory using the
installLocation attribute. A typical manifest file looks as:
Example: XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.application"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="preferExternal">
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="27" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Mobile Computing and App Development
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication"
tools:targetApi="31">
<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>
A manifest file includes the nodes that define the application components, security settings, test classes, and
requirements that make up the application. Some of the manifest sub-node tags that are mainly used are:
1. manifest
The main component of the AndroidManifest.xml file is known as manifest. Additionally, the packaging field
describes the activity class’s package name. It must contain an <application> element with the xmlns:android
and package attribute specified.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.application">
<!-- manifest nodes -->
<application>
</application>
</manifest>
2. uses-sdk:
It is used to define a minimum and maximum SDK version by means of an API Level integer that must be
available on a device so that our application functions properly, and the target SDK for which it has been
designed using a combination of minSdkVersion, maxSdkVersion, and targetSdkVersion attributes,
respectively. It is contained within the <manifest> element.
Mobile Computing and App Development
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="27" />
3. uses-permission
It outlines a system permission that must be granted by the user for the app to function properly and is
contained within the <manifest> element. When an application is installed (on Android 5.1 and lower devices
or Android 6.0 and higher), the user must grant the application permissions.
<uses-permission
android:name="android.permission.CAMERA"
android:maxSdkVersion="18" />
4. application
A manifest can contain only one application node. It uses attributes to specify the metadata for your application
(including its title, icon, and theme). During development, we should include a debuggable attribute set to true
to enable debugging, then be sure to disable it for your release builds. The application node also acts as a
container for the Activity, Service, Content Provider, and Broadcast Receiver nodes that specify the application
components. The name of our custom application class can be specified using the android:name attribute.
<application
android:name=".Application"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@drawable/gfgIcon"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@android:style/Theme.Light"
android:debuggable="true"
tools:targetApi="31">
<!-- application nodes -->
</application>
5. uses-library
It defines a shared library against which the application must be linked. This element instructs the system to
add the library’s code to the package’s class loader. It is contained within the <application> element.
<uses-library
Mobile Computing and App Development
android:name="android.test.runner"
android:required="true" />
6. activity
The Activity sub-element of an application refers to an activity that needs to be specified in the
AndroidManifest.xml file. It has various characteristics, like label, name, theme, launchMode, and others. In
the manifest file, all elements must be represented by <activity>. Any activity that is not declared there won’t
run and won’t be visible to the system. It is contained within the <application> element.
<activity
android:name=".MainActivity"
android:exported="true">
</activity>.
7. intent-filter
It is the sub-element of activity that specifies the type of intent to which the activity, service, or broadcast
receiver can send a response. It allows the component to receive intents of a certain type while filtering out
those that are not useful for the component. The intent filter must contain at least one <action> element.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>.
8. action
It adds an action for the intent-filter. It is contained within the <intent-filter> element.
<action android:name="android.intent.action.MAIN" />
9. category
It adds a category name to an intent-filter. It is contained within the <intent-filter> element.
<category android:name="android.intent.category.LAUNCHER" />
.
10. uses-configuration
The uses-configuration components are used to specify the combination of input mechanisms that are
supported by our application. It is useful for games that require particular input controls.
<uses-configuration
android:reqTouchScreen=”finger”
android:reqNavigation=”trackball”
android:reqHardKeyboard=”true”
Mobile Computing and App Development
android:reqKeyboardType=”qwerty”/>
<uses-configuration
android:reqTouchScreen=”finger”
android:reqNavigation=”trackball”
android:reqHardKeyboard=”true”
android:reqKeyboardType=”twelvekey”/>
11. uses-features
It is used to specify which hardware features your application requires. This will prevent our application
from being installed on a device that does not include a required piece of hardware such as NFC hardware,
as follows
<uses-feature android:name=”android.hardware.nfc” />
12. permission
It is used to create permissions to restrict access to shared application components. We can also use the
existing platform permissions for this purpose or define your own permissions in the manifest.
<permission
android: name=”com.paad.DETONATE_DEVICE”
android:protectionLevel=“dangerous”
android:label=”Self Destruct”
android:description=”@string/detonate_description”>
</permission>
If you decide that your app must access restricted data or perform restricted actions to fulfill a use case, declare
the appropriate permissions. Some permissions, known as install-time permissions, are automatically granted
when your app is installed. Other permissions, known as runtime permissions, require your app to go a step
further and request the permission at runtime.
Mobile Computing and App Development
Types of permission:
1. Install-time permissions
Install-time permissions give your app limited access to restricted data or let your app perform restricted
actions that minimally affect the system or other apps. When you declare install-time permissions in your app,
an app store presents an install-time permission notice to the user when they view an app's details page, as
shown in figure 2. The system automatically grants your app the permissions when the user installs your app.
2.Normal permissions
These permissions allow access to data and actions that extend beyond your app's sandbox but present very
little risk to the user's privacy and the operation of other apps.
3. Signature permissions
The system grants a signature permission to an app only when the app is signed by the same certificate as the
app or the OS that defines the permission.
Applications that implement privileged services, such as autofill or VPN services, also make use of signature
permissions. These apps require service-binding signature permissions so that only the system can bind to the
services.
4. Runtime permissions
Runtime permissions, also known as dangerous permissions, give your app additional access to restricted data
or let your app perform restricted actions that more substantially affect the system and other apps. Therefore,
you need to request runtime permissions in your app before you can access the restricted data or perform
restricted actions. Don't assume that these permissions have been previously granted—check them and, if
needed, request them before each access.
When your app requests a runtime permission, the system presents a runtime permission prompt.
Mobile Computing and App Development
Many runtime permissions access private user data, a special type of restricted data that includes potentially
sensitive information. Examples of private user data include location and contact information.
5.Special permissions
Special permissions correspond to particular app operations. Only the platform and OEMs can define special
permissions. Additionally, the platform and OEMs usually define special permissions when they want to
protect access to particularly powerful actions, such as drawing over other apps.
The Special app access page in system settings contains a set of user-toggleable operations. Many of these
operations are implemented as special permissions.
6. Permission groups
Permissions can belong to permission groups. Permission groups consist of a set of logically related
permissions. For example, permissions to send and receive SMS messages might belong to the same group,
as they both relate to the application's interaction with SMS.
Permission groups help the system minimize the number of system dialogs that are presented to the user when
an app requests closely related permissions. When a user is presented with a prompt to grant permissions for
an application, permissions belonging to the same group are presented in the same interface. However,
permissions can change groups without notice, so don't assume that a particular permission is grouped with
any other permission.
Code templates and GitHub integration to help you build common app features and import sample
code
Extensive testing tools and frameworks
Lint tools to catch performance, usability, version compatibility, and other problems
C++ and NDK support
Built-in support for Google Cloud Platform, making it easy to integrate Google Cloud Messaging and
App Engine.
1. Toolbar: Carry out a wide range of actions, including running your app and launching Android tools.
2. Navigation bar: Navigate through your project and open files for editing. It provides a more compact
view of the structure visible in the Project window.
3. Editor window: Create and modify code. Depending on the current file type, the editor can change.
For example, when viewing a layout file, the editor displays the Layout Editor.
4. Tool window bar: Use the buttons on the outside of the IDE window to expand or collapse individual
tool windows.
Mobile Computing and App Development
5. Tool windows: Access specific tasks like project management, search, version control, and more. You
can expand them and collapse them.
6. Status bar: Display the status of your project and the IDE itself, as well as any warnings or messages.
Tool windows
To expand or collapse a tool window, click the tool’s name in the tool window bar. You can
also drag, pin, unpin, attach, and detach tool windows.
To return to the default layout of the current tool window, click Window > Restore Default
Layout. To customize your default layout, click Window > Store Current Layout as Default.
To show or hide the entire tool window bar, click the window in the bottom left-hand
corner of the Android Studio window.
To locate a specific tool window, hover over the window icon and select the tool window
from the menu.
Depending on the size of your screen, consider resizing the pane on the left showing the project
folders to take up less space.
Mobile Computing and App Development
Double-click the app (1) folder to expand the hierarchy of app files. (See (1) in the screenshot.)
If you click Project (2), you can hide or show the Project view.
The current Project view selection is Project > Android.
Create a virtual device (emulator)
In Android Studio, select Tools > AVD Manager, or click the AVD Manager icon in the toolbar.
1ef215721ed1bd47.png
Click +Create Virtual Device. (If you have created a virtual device before, the window shows
all of your existing devices and the +Create Virtual Device button is at the bottom.) The Select
Hardware window shows a list of pre-configured hardware device definitions.
Choose a device definition, such as Pixel 2, and click Next. (For this codelab, it really doesn't
matter which device definition you pick).
In the System Image dialog, from the Recommended tab, choose the latest release. (This does
matter.)
If a Download link is visible next to a latest release, it is not installed yet, and you need to
download it first. If necessary, click the link to start the download, and click Next when it's
done. This may take a while depending on your connection speed.
In the next dialog box, accept the defaults, and click Finish.
The AVD Manager now shows the virtual device you added.
If the Your Virtual Devices AVD Manager window is still open, go ahead and close it.
In Android Studio, select Run > Run ‘app', or click the Run icon in the toolbar. The icon
changes once your app is running
In Run > Select Device, under Available devices, select the virtual device that you just
configured. A dropdown menu also appears in the toolbar.
Once your app builds and the emulator is ready, Android Studio uploads the app to the
emulator and runs it. You should see your app as shown in the following screenshot.
Mobile Computing and App Development