0% found this document useful (0 votes)
71 views24 pages

UNIT - 1 - Introduction To Android & Android Application Design

The document provides an overview of mobile computing using the Android platform, covering topics such as the Open Handset Alliance, Android SDK, application development, and the architecture of Android. It details the history of Android, its features, and the structure of Android applications, including essential components like Activities and the Android Manifest File. Additionally, it discusses the Android SDK, Android Emulator, and various categories of Android applications.

Uploaded by

mirajoshi.1107
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views24 pages

UNIT - 1 - Introduction To Android & Android Application Design

The document provides an overview of mobile computing using the Android platform, covering topics such as the Open Handset Alliance, Android SDK, application development, and the architecture of Android. It details the history of Android, its features, and the structure of Android applications, including essential components like Activities and the Android Manifest File. Additionally, it discusses the Android SDK, Android Emulator, and various categories of Android applications.

Uploaded by

mirajoshi.1107
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

CS-31: Mobile Computing using Android and iPhone

BCA Sem. - 6
UNIT - 1
 The Open Handset Alliance
 The Android Platform, Android SDK
 Building a sample Android application
 Anatomy of an Android applications
 Android terminologies
 Application Context, Activities, Services, Intents
 Receiving and Broadcasting Intents
 Android Manifest File and its common settings
 Using Intent Filter, Permissions
 Managing Application resources in a hierarchy
 Working with different types of resources

Dr. Virambhai R. Godhaniya I. T. College


B/h. Amar Polyfills, Rajkot- National Highway, Opp. New Airport, Porbandar - 360 578 (Gujarat)
www.drvrgit.com
Unit-1 CS-31 : Introduction to Android & Android Application Design

Introduction to Android
Android is basically an open-source and Linux-based Operating system and this operating system is
mainly designed for touchscreen mobile devices like smartphones, tablets, etc.

There are millions of apps available for android that can help you manage your life one or another
way and are available at low cost due to which android has got so much popularity in the market.

Android was developed by the Open Handset Alliance, led by Google, and other companies. Java
language is mainly used to write the android code even though other languages can be used.

The goal of android project is to create a successful real-world product that improves the mobile
experience for end users.

Android offers a unified approach to application development for mobile devices which means
developers need only develop for Android, and their applications should be able to run on different
devices powered by Android.

History of Android
The first beta version of the Android Software Development Kit (SDK) was released by Google in 2007
where as the first commercial version, Android 1.0, was released in September 2008.

On June 27, 2012, at the Google I/O conference, Google announced the next Android version, 4.1 Jelly
Bean. Jelly Bean is an incremental update, with the primary aim of improving the user interface, both
in terms of functionality and performance.

The source code for Android is available under free and open source software licenses. Google
publishes most of the code under the Apache License version 2.0 and the rest, Linux kernel changes,
under the GNU General Public License version 2.

The history and versions of android are interesting to know. The code names of android ranges from A
to J currently, such
as Aestro, Blender, Cupcake, Donut, Eclair, Froyo, Gingerbread, Honeycomb, Ice Cream
Sandwitch, Jelly Bean, KitKat and Lollipop. Let's understand the android history in a sequence.

1) Initially, Andy Rubin founded Android Incorporation in Palo Alto, California, United States in
October, 2003.

2) In 17th August 2005, Google acquired android Incorporation. Since then, it is in the subsidiary of
Google Incorporation.

3) The key employees of Android Incorporation are Andy Rubin, Rich Miner, Chris White and Nick
Sears.

4) Originally intended for camera but shifted to smart phones later because of low market for camera
only.

5) Android is the nick name of Andy Rubin given by co-workers because of his love to robots.

6) In 2007, Google announces the development of android OS.

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 1 of 24


Unit-1 CS-31 : Introduction to Android & Android Application Design

7) In 2008, HTC launched the first android mobile.

Features of Android
As an open source and freely available software, manufacturers and developers do customization as
per their needs, so there is no specific hardware and software configurations required for Android.
Android itself offers some features as below,

1. Storage: Uses SQLite, a light weight relational database storage for data storage (really helpful
when limited mobile memory storage is to be considered).

2. Media Support: Include support for large number of media formats for Images, Audio as well
as for Video, like: H.263, H.264, MPEG-4 SP, AMR, AMR WB, AAC, MP3, MIDI, WAV, JPEG, PNG,
GIF & BMP.

3. Messaging: Both SMS and MMS are supported.

4. Web Browser: Based on Open Source WebKit, now known as Chrome.

5. Connectivity: Supports large group of networks like: GSM/EDGE, IDEN, CDMA, EV-DO, UMTS,
Bluetooth, WiFi, LTE and WiMAX.

6. Hardware Support: Accelerometer Sensor, Camera, Digital Compass, Proximity Sensor & GPS
and a lot more.
Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 2 of 24
Unit-1 CS-31 : Introduction to Android & Android Application Design

7. Multi-Touch: Supports multi-touch screen.

8. Multi-Task: Supports application multi-tasking.

9. Flash Support: Supports Flash.

10. Tethering: Supports sharing of Internet as wired or wireless hotspots.

Architecture of Android (Android Software stack)


Android operating system is a stack of software components which is roughly divided into five
sections and four main layers as shown below in the architecture diagram.

Linux kernel

At the bottom of the layers is Linux - Linux 3.6 with approximately 115 patches. This provides a level
of abstraction between the device hardware and it contains all the essential hardware drivers like
camera, keypad, display etc. Also, the kernel handles all the things that Linux is really good at such as
networking and a vast array of device drivers, which take the pain out of interfacing to peripheral
hardware.

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 3 of 24


Unit-1 CS-31 : Introduction to Android & Android Application Design

Libraries

On top of Linux kernel there is a set of libraries including open-source Web browser engine WebKit,
well known library libc, SQLite database which is a useful repository for storage and sharing of
application data, libraries to play and record audio and video, SSL libraries responsible for Internet
security etc.

Android Libraries

This category encompasses those Java-based libraries that are specific to Android development.
Examples of libraries in this category include the application framework libraries in addition to those
that facilitate user interface building, graphics drawing and database access. A summary of some key
core Android libraries available to the Android developer is as follows −

 android.app − Provides access to the application model and is the cornerstone of all Android
applications.

 android.content − Facilitates content access, publishing and messaging between applications


and application components.

 android.database − Used to access data published by content providers and includes SQLite
database management classes.

 android.opengl − A Java interface to the OpenGL ES 3D graphics rendering API.

 android.os − Provides applications with access to standard operating system services


including messages, system services and inter-process communication.

 android.text − Used to render and manipulate text on a device display.

 android.view − the fundamental building blocks of application user interfaces.

 android.widget − A rich collection of pre-built user interface components such as buttons,


labels, list views, layout managers, radio buttons etc.

 android.webkit − A set of classes intended to allow web-browsing capabilities to be built into


applications.

Android Runtime

This is the third section of the architecture and available on the second layer from the bottom. This
section provides a key component called Dalvik Virtual Machine which is a kind of Java Virtual
Machine specially designed and optimized for Android.

The Dalvik VM makes use of Linux core features like memory management and multi-threading, which
is intrinsic in the Java language. The Dalvik VM enables every Android application to run in its own
process, with its own instance of the Dalvik virtual machine.

The Android runtime also provides a set of core libraries which enable Android application
developers to write Android applications using standard Java programming language.

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 4 of 24


Unit-1 CS-31 : Introduction to Android & Android Application Design

Application Framework

The Application Framework layer provides many higher-level services to applications in the form of
Java classes. Application developers are allowed to make use of these services in their applications.

The Android framework includes the following key services −

 Activity Manager − Controls all aspects of the application lifecycle and activity stack.

 Content Providers − Allows applications to publish and share data with other applications.

 Resource Manager − Provides access to non-code embedded resources such as strings, color
settings and user interface layouts.

 Notifications Manager − Allows applications to display alerts and notifications to the user.

 View System − an extensible set of views used to create application user interfaces.

Applications

You will find all the Android application at the top layer. You will write your application to be installed
on this layer only. Examples of such applications are Contacts Books, Browser, and Games etc.

Open Handset Alliance (OHA)

It's a consortium of 84 companies such as google, samsung, AKM, synaptics, KDDI, Garmin, Teleca,
Ebay, Intel etc.

It was established on 5th November, 2007, led by Google. It is committed to advance open standards,
provide services and deploy handsets using the Android Platform.

Categories of Android applications

There are many android applications in the market. The top categories are:

o Entertainment
o Tools
o Communication
o Productivity
o Personalization
o Music and Audio

o Social
o Media and Video
o Travel and Local etc.

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 5 of 24


Unit-1 CS-31 : Introduction to Android & Android Application Design

The Android SDK


Android SDK. It contains libraries, debugger, an emulator, documentations, sample codes and tutorials
for each API level of the released versions of Android.

Before the release of Android Studio, SDK was a standalone part of the Android Application development
tools that could be integrated with other IDE's like Eclipse with the help of Android ADT Bundle. Later on,
Google made Android SDK as a part of the Android Studio, which is the official IDE for Android
development.

The Android SDK Manager, manages various Android SDK versions, tools and various other useful
packages that you can select and download, to keep your development environment up-to-date.

Generally when you launch the Android Studio for the first time, it will open the Android SDK Manager
window, to prompt you to install the required packages for android development. But if that does not
happen, you can open the SDK Manager by going to Tools → Android → SDK Manager.

 SDK Tools and Build-tools contain packages to build your Android Application and several
updates/patches from Google for better Application Development.

 SDK Platform: Android SDK platform contains packages/libraries to develop & build Android
Application for specific versions. To compile your Application against specific version, to load
specific widgets, views and tools for compilation, is done by SDK Platform.

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 6 of 24


Unit-1 CS-31 : Introduction to Android & Android Application Design

Android Virtual Device (AVD) – Android Emulator


The Android emulator is an Android Virtual Device (AVD), which represents a specific Android
device. We can use the Android emulator as a target device to execute and test our Android
application on our PC. The Android emulator provides almost all the functionality of a real device.

We can get the incoming phone calls and text messages. It also gives the location of the device and
simulates different network speeds. Android emulator simulates rotation and other hardware
sensors. It accesses the Google Play store, and much more.

Testing Android applications on emulator are sometimes faster and easier than doing on a real device.
For example, we can transfer data faster to the emulator than to a real device connected through USB.

The Android emulator comes with predefined configurations for several Android phones, Wear OS,
tablet, Android TV devices.

An Android Virtual Device (AVD) is a device configuration that runs on the Android Emulator. It
provides virtual device-specific Android Environment in which we can install & test our Android
Application. AVD Manager is a part of SDK Manager to create and manage the virtual devices created.
To open AVD manager, go to Tools → Android → AVD Manager.

Anatomy of an Android applications

In Android Studio, the modern day Android App package structure has changed a little bit, but the
change is very subtle.

Here is a list of folders created, when you create an Android App project in Android Studio and see it
in Project View Mode:

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 7 of 24


Unit-1 CS-31 : Introduction to Android & Android Application Design

src folder
The src folder holds two most important folders on any Android project, namely, android Test and
main. The android Test package is created to hold Test cases for testing the application code and
running.

While the main folder, has 2 folders and 1 file. They are:
 java directory
This folder contains .java (JAVA) files. Here, you can create interface(s), activity(s), fragment(s) or
adapter(s) for your application. This folder contains java code only. You can create separate packages
for each of these and create classes inside them to give your application project a well-defined
structure.
 AndroidManifest.xml
This file is a mandatory file for any android application. In this file we provide information about all
the application's Activities, Services, Broadcast Receivers etc. and all the permissions like Internet,
Contacts, and Camera etc. that our application will require when it is installed on any device. Just keep
in mind that this file is the heart of any Android Application.
 res directory
This folder contains all the resources like icons, images etc. related to our application project and it
contains the following sub-folders:
o Drawable
This folder contains xml, png, and jpg and jpeg files. In this folder you can store images which are used
in your app and other .xml files which are used for many purposes like creating button background, or
shadow effect etc.

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 8 of 24


Unit-1 CS-31 : Introduction to Android & Android Application Design

o Layout
This folder contain only the layout .xml files for different screens and parts of your application.
o Values
This folder contains default files like strings.xml, dimens.xml, colors.xml, styles.xml.
 In strings.xml, you can specify all the string constants like title of screen or any
other tag which are constantly used in your app.
 In dimens.xml, you can create different .xml files to define dimensions as per
resolution of screen and dimension of it and give any dimensions for padding,
height, width, margin in this file.
 In color.xml you can mention the list of colors using their hash codes, used in
your application. If this is not created by default, you can create this yourself.
 In styles.xml you can define different readymade styles to use them directly
anywhere in your Android App.

Build Folder
This folder contain R.java file, which is an auto generated file. This file indexes all the resources of the
android application project like layout xml, strings xml etc. and it is auto generated.
In build folder, you will have application's debug and release apk files, created when you build your
project.

Libs folder
If you want to use any external library, all you have to do is copy-paste the .jar file into the libs folder
and then you can directly use it in you .java code files.

Gradle folder
In this folder there are files related to gradle which can be modified to alter the project building
process. For example: If you wish to run all the available test cases before building the .apk file, you
can do so by mentioning it in the gradle file.

Android terminologies

Application components are the essential building blocks of an Android application. These
components are loosely coupled by the application manifest file AndroidManifest.xml that describes
each component of the application and how they interact.

Activities
An activity represents a single screen with a user interface, in-short Activity performs actions on the
screen. For example, an email application might have one activity that shows a list of new emails,
another activity to compose an email, and another activity for reading emails. If an application has
more than one activity, then one of them should be marked as the activity that is presented when the
application is launched.

An activity is implemented as a subclass of Activity class as follows −


public class MainActivity extends Activity {
}

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 9 of 24


Unit-1 CS-31 : Introduction to Android & Android Application Design

Services
A service is a component that runs in the background to perform long-running operations. For
example, a service might play music in the background while the user is in a different application, or it
might fetch data over the network without blocking user interaction with an activity.
A service is implemented as a subclass of Service class as follows −

public class MyService extends Service {


}

Broadcast Receivers
Broadcast Receivers simply respond to broadcast messages from other applications or from the
system. For example, applications can also initiate broadcasts to let other applications know that some
data has been downloaded to the device and is available for them to use, so this is broadcast receiver
who will intercept this communication and will initiate appropriate action.

A broadcast receiver is implemented as a subclass of Broadcast Receiver class and each message is
broadcaster as an Intent object.

Public class MyReceiver extends BroadcastReceiver {


public void onReceive (context,intent){}
}

Content Providers
A content provider component supplies data from one application to others on request. Such requests
are handled by the methods of the ContentResolver class. The data may be stored in the file system, the
database or somewhere else entirely.

A content provider is implemented as a subclass of Content Provider class and must implement a
standard set of APIs that enable other applications to perform transactions.

public class MyContentProvider extends ContentProvider {


public void onCreate(){}
}

Additional Components

Fragments
Represents a portion of user interface in an Activity.
Views
UI elements that are drawn on-screen including buttons, lists forms etc.
Layouts
View hierarchies that control screen format and appearance of the views.
Intents
Messages wiring components together.
Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 10 of 24
Unit-1 CS-31 : Introduction to Android & Android Application Design

Resources
External elements, such as strings, constants and drawable pictures.
Manifest
Configuration file for the application.

Context in Android
It’s the context of current state of the application/object. It lets newly-created objects understand
what has been going on. Typically, you call it to get information regarding another part of your
program (activity and package/application). In the below program you will see that we have created a
textView dynamically and passed context. This context is used to get the information about the
environment.

Few more points about the context:

 It is the context of the current state of the application.

 It can be used to get information regarding the activity and application.

 It can be used to get access to resources, databases, and shared preferences, and etc.

 Both the Activity and Application classes extend the Context class.

Mainly two types of context:

 Application Context: It is the application and we are present in Application. For example -
MyApplication(which extends Application class). It is an instance of MyApplication only.

 Activity Context: It is the activity and we are present in Activity. For example - MainActivity. It
is an instance of MainActivity only.

Application Context
It is an instance that is the singleton and can be accessed in activity via getApplicationContext(). This
context is tied to the lifecycle of an application. The application context can be used where you need a
context whose lifecycle is separate from the current context or when you are passing a context beyond
the scope of activity.

Example Use: If you have to create a singleton object for your application and that object needs a
context, always pass the application context.

If you pass the activity context here, it will lead to the memory leak as it will keep the reference to the
activity and activity will not be garbage collected.

In case, when you have to initialize a library in an activity, always pass the application context, not the
activity context.

You only use getApplicationContext() when you know you need a Context for something that may
live longer than any other likely Context you have at your disposal.

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 11 of 24


Unit-1 CS-31 : Introduction to Android & Android Application Design

Activity Context

This context is available in an activity. This context is tied to the lifecycle of an activity. The activity
context should be used when you are passing the context in the scope of an activity or you need the
context whose lifecycle is attached to the current context.

Example Use: If you have to create an object whose lifecycle is attached to an activity, you can use the
activity context.

https://www.oodlestechnologies.com/dev-blog/context-in-android-:-application-context-vs-activity-
context/

https://medium.com/@banmarkovic/what-is-context-in-android-and-which-one-should-you-use-
e1a8c6529652

 getContext() — returns the Context which is linked to the Activity from which is called,

 getApplicationContext() — returns the Context which is linked to Application which holds all
activities running inside it,

 getBaseContext() —is related to ContextWrapper, which is created around existing Context


and let us change its behavior. With getBaseContext() we can fetch the existing Context inside
ContextWrapper class.

Activity Life cycle in Android


The Activity class is a crucial component of an Android app, and the way activities are launched and
put together is a fundamental part of the platform's application model. Unlike programming
paradigms in which apps are launched with a main () method, the Android system initiates code in
an Activity instance by invoking specific call back methods that correspond to specific stages of its
lifecycle.

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 12 of 24


To use activities in your app, you must register information about them in the app’s manifest, and you
must manage activity lifecycles appropriately.

There are seven callback methods:-


Unit-1 CS-31 : Introduction to Android & Android Application Design

onCreate():- This callback method must be created by you, this is fired when your activity is created
by the system. For example, when you open the app it will call onCreate(), onStart(), and onResume()
methods. These three methods are initiated when you open an app.

onStart():- There should always be an onStart() callback after onCreate() finishes. In the started state
users will be able to see the activity but they are not ready for user interaction.

onResume():- In this, activities will be in the foreground and ready for user interaction. You can
understand the use of this callback from this example: “when the user presses the phone’s answer
button it will give onPause() after you end up calling it will again give onResume()”.

onPause():- This callback occurs when there is a case of another activity starting in front of the
current activity. It is the opposite of onResume(). An example for this callback can be “when you open
the app, that is another app from the notification bar, or open settings then it will call onPause() and
onStop()”.

onStop():- It is the opposite of onStart(). In this case, activity will no longer be visible to the users.

onRestart():- This occurs when the activity is stopped and before the activity starts again. It is a less
common callback.

onDestroy():- It is opposite of onCreate(). This starts when the system needs to free memory or when
finish() is called. It is used for cleanup which is a very common activity.

Intent
Android Intent is the message that is passed between components such as activities, content
providers, broadcast receivers, services etc.

It is generally used with startActivity() method to invoke activity, broadcast receivers etc.

The dictionary meaning of intent is intention or purpose. So, it can be described as the intention to do
action.

The Labeled Intent is the subclass of android.content.Intent

class. Android intents are mainly used to:

o Start the service

o Launch an activity
o Display a web page
o Display a list of contacts
o Broadcast a message
o Dial a phone call etc.

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 14 of 24


Unit-1 CS-31 : Introduction to Android & Android Application Design

Context.startActivity() This is to launch a new activity or get an existing activity to be action.

This is to start a new service or deliver instructions for an existing


Context.startService() service.

Context.sendBroadcast() This is to deliver the message to broadcast receivers.

Types of Android Intents

There are two types of intents in android: implicit and explicit.

1) Implicit Intent

Implicit Intent doesn't specify the component. In such case, intent provides information of available
components provided by the system that is to be invoked.

For example, you may write the following code to view the webpage.

Intent intent=new Intent (Intent.ACTION_VIEW);

intent.setData(Uri.parse("http://www.drvrgit.ac.in"));

startActivity(intent);

2) Explicit Intent

Explicit Intent specifies the component. In such case, intent provides the external class to be invoked.

Intent i = new Intent(getApplicationContext(), ActivityTwo.class);


startActivity(i);

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 15 of 24


Unit-1 CS-31 : Introduction to Android & Android Application Design

Following are some of the important system wide generated intents.

1. android.intent.action.BATTERY_LOW : Indicates low battery condition on the device.

2. android.intent.action.BOOT_COMPLETED : This is broadcast once, after the system has


finished booting

3. android.intent.action.CALL : To perform a call to someone specified by the data

4. android.intent.action.DATE_CHANGED : The date has changed

5. android.intent.action.REBOOT : Have the device reboot

6. android.net.conn.CONNECTIVITY_CHANGE : The mobile network or Wi-Fi connection is


changed(or reset)

Broadcast Receivers
A broadcast receiver (receiver) is an Android component which allows you to register for system or
application events. All registered receivers for an event are notified by the Android runtime once this
event happens.

Broadcast intents are Intent objects that are broadcast via a call to the sendBroadcast(),
sendStickyBroadcast() or sendOrderedBroadcast() methods of the Activity class.

When a broadcast intent is created, it must include an action string in addition to optional data and a
category string. As with standard intents, data is added to a broadcast intent using key-value pairs in
conjunction with the putExtra() method of the intent object. The optional category string may be
assigned to a broadcast intent via a call to the addCategory() method.

For example, applications can register for the ACTION_BOOT_COMPLETED system event which is fired
once the Android system has completed the boot process.

There are mainly two types of Broadcast Receivers:

 Static Broadcast Receivers: These types of Receivers are declared in the manifest file and
works even if the app is closed.

 Dynamic Broadcast Receivers: These types of receivers work only if the app is active or
minimized.

There are following two important steps to make BroadcastReceiver works for the system
broadcasted intents −

 Creating the Broadcast Receiver.

 Registering Broadcast Receiver

Creating the Broadcast Receiver

A broadcast receiver is implemented as a subclass of BroadcastReceiver class and overriding the


onReceive() method where each message is received as a Intent object parameter.

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 16 of 24


Unit-1 CS-31 : Introduction to Android & Android Application Design

Registering Broadcast Receiver

An application listens for specific broadcast intents by registering a broadcast receiver in


AndroidManifest.xml file.

Intent Filter
An intent filter declares the capabilities of its parent component — what an activity or service can do
and what types of broadcasts a receiver can handle. It opens the component to receiving intents of the
advertised type, while filtering out those that are not meaningful for the component.

Intent Filter are the components which decide the behavior of an intent.

Intent filters specify the type of intents that an Activity, service or Broadcast receiver can respond to.
It declares the functionality of its parent component (i.e. activity, services or broadcast receiver). It
declares the capability of any activity or services or a broadcast receiver.

Most of the contents of the filter are described by its <action>, <category>, and <data> sub elements.

Intent filters are used to

 Implicit intent uses the intent filter to serve the user request.

 The intent filter specifies the types of intents that an activity, service, or broadcast receiver can
respond.

 Intent filters are declared in the Android manifest file.

 Intent filter must contain <action>


<intent-filter

android:icon="drawable resource"

android:label="string resource"

android:priority="integer" >

. . .
</intent-filter>

<action>

It defines the name of an intended action to be accepted and it must be a literal string value of an
action, not the class constant.

<category>

It defines the name of an intent category to be accepted and it must be the literal string value of an
action, not the class constant.

<data>

It defines the type of data to be accepted and by using one or more attributes we can specify various
aspects of the data URI (scheme, host, port, path) and MIME type.

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 17 of 24


Unit-1 CS-31 : Introduction to Android & Android Application Design

MAIN - It indicates the app’s main entry point that means it starts the activity which defines with
the MAIN action when the user initially launches the app with a launcher icon.

LAUNCHER - It indicates that this activity icon should be placed on the home screen list of apps. In
case if the <activity> element doesn’t specify an icon with icon, then the system uses the icon from
the <application> element.

These two (MAIN, LAUNCHER) elements must be paired together in order for the activity to appear
in the app launcher.

Permissions in Android

App permissions help support user privacy by protecting access to the following:

 Restricted data, such as system state and users' contact information


 Restricted actions, such as connecting to a paired device and recording audio

Every Android app runs in a limited-access sandbox. If your app needs to use resources or information
outside of its own sandbox, you can declare a permission and set up a permission request that
provides this access.

Types of Permissions

1. Install-Time Permissions: If the Android 5.1.1 (API 22) or lower, the permission is requested at
the installation time at the Google Play Store.

If the user accepts the permissions, the app is installed. Else the app installation is cancelled.

2. Run-Time Permissions: If the Android 6 (API 23) or higher, the permission is requested at the
run time during the running of the app.

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 18 of 24


Unit-1 CS-31 : Introduction to Android & Android Application Design

If the user accepts the permissions, then that feature of the app can be used. Else to use the feature,
the app requests permission again.

 By default, an Android app starts with zero permissions granted to it.


 When the app needs to use any of the protected features of the device (sending network
requests, accessing the camera, sending an SMS, etc.) it must obtain the appropriate permission
from the user to do so.
 Before Marshmallow, permissions were handled at install-time and specified in the
AndroidManifest.xml within the project.
 After Marshmallow, permissions must now be requested at runtime before being used.
 For an app developer, permissions were very simple. To request one of the many permissions,
simply specify it in the AndroidManifest.xml:
 For example, an application that needs to read the user's contacts would add the following to
its AndroidManifest.xml:

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 19 of 24


Unit-1 CS-31 : Introduction to Android & Android Application Design

The Android Manifest file

Every app project must have an AndroidManifest.xml file at the root of the project source set. The
manifest file describes essential information about your app to the Android build tools, the Android
operating system, and Google Play.

Among many other things, the manifest file is required to declare the following:

 The components of the app, which include all activities, services, broadcast receivers, and
content providers. Each component must define basic properties such as the name of its
Kotlin or Java class. It can also declare capabilities such as which device configurations it
can handle, and intent filters that describe how the component can be started.
 The permissions that the app needs in order to access protected parts of the system or
other apps. It also declares any permissions that other apps must have if they want to
access content from this app.
 The hardware and software features the app requires, which affects which devices can
install the app from Google Play.

If you're using Android Studio to build your app, the manifest file is created for you, and most of the
essential manifest elements are added as you build your app.

Elements of the AndroidManifest.xml file

The elements used in the above xml file are described below.

<manifest>

manifest is the root element of the AndroidManifest.xml file. It has package attribute that describes
the package name of the activity class.

<application>

application is the subelement of the manifest. It includes the namespace declaration. This element
contains several subelements that declares the application component such as activity etc.

The commonly used attributes are of this element are icon, label, theme etc.

android:icon represents the icon for all the android application components.

android:label works as the default label for all the application components.

android:theme represents a common theme for all the android activities.

<activity>

activity is the subelement of application and represents an activity that must be defined in the
AndroidManifest.xml file. It has many attributes such as label, name, theme, launchMode etc.

android:label represents a label i.e. displayed on the screen.

android:name represents a name for the activity class. It is required attribute.

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 20 of 24


Unit-1 CS-31 : Introduction to Android & Android Application Design

<intent-filter>

intent-filter is the sub-element of activity that describes the type of intent to which activity, service
or broadcast receiver can respond to.

<action>

It adds an action for the intent-filter. The intent-filter must have at least one action element.

<category>

It adds a category name to an intent-filter.

https://data-flair.training/blogs/android-manifest-file/

Managing Application resources in a hierarchy

Resources are the additional files and static content that your code uses, such as bitmaps, layout
definitions, user interface strings, animation instructions, and more.

You should always externalize app resources such as images and strings from your code, so that you
can maintain them independently. For example, you might want to provide a different UI layout
depending on the screen size or different strings depending on the language setting.

Once you externalize your app resources, you can access them using resource IDs that are generated
in your project's R class.

You should place each type of resource in a specific subdirectory of your project's res/ directory. For
example, here's the file hierarchy for a simple project:

As you can see in this example, the res/ directory contains all the resources (in subdirectories): an
image resource, two layout resources, mipmap/ directories for launcher icons, and a string resource
file.

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 21 of 24


Animation Resources
Define pre-determined animations.
Tween animations are saved in res/anim/ and accessed from the R.anim class.
Frame animations are saved in res/drawable/ and accessed from the R.drawable class.

Color State List Resource


Define a color resources that changes based on the View state.
Saved in res/color/ and accessed from the R.color class.

Drawable Resources
Define various graphics with bitmaps or XML.
Saved in res/drawable/ and accessed from the R.drawable class.

Layout Resource
Define the layout for your application UI.
Saved in res/layout/ and accessed from the R.layout class.

Menu Resource
Define the contents of your application menus.
Saved in res/menu/ and accessed from the R.menu class.

String Resources
Define strings, string arrays, and plurals (and include string formatting and styling).
Saved in res/values/ and accessed from the R.string, R.array, and R.plurals classes.

Style Resource
Define the look and format for UI elements.
Saved in res/values/ and accessed from the R.style class.

Font Resources
Define font families and include custom fonts in XML.
Saved in res/font/ and accessed from the R.font class.

More Resource Types


Define other primitive values as static resources, including the following:
Bool
XML resource that carries a boolean value.
Color
XML resource that carries a color value (a hexadecimal color).
Dimension
XML resource that carries a dimension value (with a unit of measure).
ID
XML resource that provides a unique identifier for application resources and components.
Integer
XML resource that carries an integer value.
Integer Array
XML resource that provides an array of integers.
Unit-1 CS-31 : Introduction to Android & Android Application Design

Typed Array
XML resource that provides a TypedArray (which you can use for an array of drawables).

https://apprize.best/google/android_3/7.html

Working with different types of resources

Here's a brief summary of each resource type:


 Animation Resources. Define pre-determined animations. Tween animations are saved in
res/anim/ and accessed from the R.anim class. Frame animations are saved in
res/drawable/ and accessed from the R.drawable class.
 Color State List Resource. Define a color resources that changes based on the View state.
Saved in res/color/ and accessed from the R.color class.
 Drawable Resources. Define various graphics with bitmaps or XML. Saved in
res/drawable/ and accessed from the R.drawable class.
 Layout Resource. Define the layout for your application UI. Saved in res/layout/ and
accessed from the R.layout class.
 Menu Resource. Define the contents of your application menus. Saved in res/menu/ and
accessed from the R.menu class.
 String Resources. Define strings, string arrays, and plurals (and include string formatting
and styling). Saved in res/values/ and accessed from the R.string, R.array, and R.plurals
classes.
 Style Resource. Define the look and format for UI elements. Saved in res/values/ and
accessed from the R.style class.
 Font Resources. Define font families and include custom fonts in XML. Saved in res/font/
and accessed from the R.font class.
 More Resource Types. Define values such as booleans, integers, dimensions, colors, and
other arrays. Saved in res/values/ but each accessed from unique R sub-classes (such as
R.bool, R.integer, R.dimen, etc.).

Dr. Virambhai R. Godhaniya I.T. College, Porbandar. Page 23 of 24

You might also like