Mad Notes
Mad Notes
UNIT-1 10 Hrs
Introduction to Android ,open headset alliance, Android Ecosystem, Need of Android ,
Features of Android, Tools and software required for developing an Application, Android
architecture
UNIT-2 12 Hrs
operating system, java JDK, Android SDK, Android development tools, Android virtual
devices, steps to install and configure Android studio and sdk
UNIT-3 14 Hrs
control flow, directory structure, components of a screen, fundamental UI design, linear
layout, absolute layout , table layout, relative layout, text view, edit text, button, image
button, radio button, toggle button, radio group, check box, and progress bar, list view , grid
view, image view , scroll view, time and date picker
UNIT-4 12 Hrs
android platform services, Android system Architecture, Android Security model,
Applications development: creating small application
UNIT-5 12 Hrs
Introduction of MIT App Inventor,Application Coding 5.3Programming Basics & Dialog, More
Programming Basics, Alarm Clock Application, Audio & Video, Drawing Application File
Game, Device Location,Web Browsing
Text Books:
1. Erik Hellman, “Android Programming – Pushing the Limits”, 1st Edition, Wiley India
Pvt Ltd, 2014.
2. App Inventor : create your own Android apps by Wolber, David (David Wayne)
MOBILE APPLICATION DEVELOPMENT
Mobile phones have changed the way we live our lives providing voice calling, text
messaging and mobile Internet access. The very first mobile phones were two-way
radios that allowed taxi drivers and the emergency services to communicate. Motorola,
on 3 April 1973 was first company to mass produce the first handheld mobile phone.
Mobile Ecosystem is a collection of multiple devices (mobile phones, Tablet, Phablet etc),
software (operating system, development tools, testing tools etc), companies(device
manufacturers, carrier, apps stores, development/testing companies) etc.. and the process
by which data (sms, bank-transactions etc.) is
transferred/ shared by a user from one device to
another device or by the device itself based on some
programs(Birthday, Wedding Messages, Calendar).
UNIT-1 10 Hrs
Introduction to Android ,open headset alliance, Android Ecosystem, Need of Android ,
Features of Android, Tools and software required for developing an Application, Android
architecture
1. What is Android?
Android is an open source software package that was developed primarily to improve the
mobile user experience and has now become the best-selling operating system for mobile
devices. Android is now a part of Google and the Open Handset Alliance, and the current
version of the Android operating system is Oreo (version 8.0), which was released in August
2017.
ANDROID1.5 CUPCAKE
ANDROID1.6 DONUT
ANDROID2.0-2.1 ÉCLAIR
ANDROID2.2 FROYO
ANDROID2.3 GINGERBREAD
ANDROID3.0 HONEYCOMB
ANDROID4.0 ICECREAMSANDWICH
ANDROID4.1-4.3 JELLYBEAN
ANDROID4.4 KITKAT
ANDROID5.0 LOLLIPOP
ANDROID6.0 MARSHMALLOW
ANDROID7.0 NOUGAT
ANDROID8.0 OREO
ANDROID9.0 PIE ANDROID10 Q
The Open Handset Alliance (OHA) is a business alliance that was created for the purpose of
developing open mobile device standards. The OHA has approximately 80 member
companies, including HTC, Dell, Intel, Motorola, Qualcomm and Google. The OHA's main
product is the Android platform - the world's most popular smartphone platform.
OHA member companies back the open platform concept for a number of reasons, as follows:
Lower overall handset costs: Opens up resources, which facilitates the focus on creating
innovative applications, solutions and services.
Following are the 7 reasons that state why we need an android app development
company:
It is good to have a mobile application for your business. People nowadays use smartphones
because smartphones are handy and less time-consuming. Smartphones offer multiple
benefits like users can buy products online, compare various products, find places using
Google Maps, find instant solutions, get knowledge and more.
Businesses are taking their business online using an Android or iOS application to make the
shopping experience of their customers very easy. There is a greater chance to increase sales
by offering a smoother shopping experience to their customers.
a. Android Studio
Android Studio is an excellent IDE for developing Android applications . It is fast and
efficient. Using Android Studio, Android developers can easily set up a new Android project
for different types of Android apps within seconds.
b. Java
This powerful programming language is used on a wide range of devices and operating
systems. To develop an iPhone application, the iPhone developer should know objective C
or Swift programming language that is used for iOS development only.
4. Ease of accessibility
Nowadays, owing to the popularity that the Android operating system has gained, many
manufacturers opt for Android devices. Besides, customers can purchase and download
various Android apps for their Android devices from the Play Store. While it takes a few hours
for an Android app to be available for download, it takes a few weeks for an iOS app to be
available for download in the App Store. An
application can be updated multiple times in
a day on the Google Play Store.
There are some portability issues with iOS as it is close sourced while Android is fully open
source and can easily port to other operating systems like Ubuntu, Blackberry, Symbian,
and Chrome OS.
Google, LG, Samsung, HTC, Sony, Asus, Motorola, and many other device manufacturing
companies are using Android.
As the community is quite extensive and Android is open source, it is easy to develop such
exciting apps without any difficulty.
1. linux kernel
2. native libraries (middleware),
3. Android Runtime
4. Application
Framework
5. Applications
1) Linux kernel
Linux Kernel carries all the drivers for the low-level devices like Audio Driver, Wi-Fi Driver,
Flash Memory Driver, Bluetooth driver, Camera Driver, Keypad Driver, etc. It is also the
abstract layer of android.
2) Native Libraries
On the top of linux kernel, their are Native libraries such as WebKit, OpenGL, FreeType,
SQLite, Media, C runtime library (libc) etc.
The WebKit library is responsible for browser support, SQLite is for database, FreeType for
font support, Media for playing and recording audio and video formats.
There are several libraries to provide various functionality for purposes like android
development. These libraries are written in C/C++ and are an essential part of architecture.
3) Android Runtime
In android runtime, there are core libraries and DVM (Dalvik Virtual Machine) which is
responsible to run android application. DVM is like JVM but it is optimized for mobile
devices. It consumes less memory and provides fast performance.
It provides us with an environment for executing and debugging our android applications.
4) Android Framework
On the top of Native libraries and android runtime, there is android framework. Android
framework includes Android API's such as UI (User Interface), telephony, resources,
locations, Content Providers (data) and package managers. It provides a lot of classes and
interfaces for android application development.
5) Applications
On the top of android framework, there are applications. All applications such as home,
contact, settings, games, browsers are using android framework that uses android runtime
and libraries. Android runtime and native libraries are using linux kernal.
7.Explain the various tools and software required to develop android applications.
Here are the top favorite tools currently being used for Android application development.
1. Android Studio
As the official integrated development environment for all Android applications, Android
Studio always seems to top the list of preferred tools for developers.
Google created Android Studio back in 2013. It replaced – or should we say it eclipsed? –
Eclipse Android Development Tools (ADT) as the primary IDE for native Android app
development.
Android Studio provides code editing, debugging, and testing tools all within an easy-to-use
drag-and-drop interface. It is free to download and is supported not only by Google, but also
by a large and actively engaged community of Android developers.
3. AVD Manager
Another useful feature of Android Studio is the AVD Manager, the short form for Android
Virtual Device. The AVD Manager is an emulator used to run Android apps on a computer.
This allows developers the ability to work with all types of Android devices to test
responsiveness and performance on different versions, screen sizes, and resolutions.
4. Eclipse
As we mentioned above, there was Eclipse before there was Android Studio. For a long time,
Eclipse was the officially preferred IDE for all Android application development.
Even though Google no longer offers support for Eclipse, many developers still use it to create
Android and other cross-platform apps, as it works very well with many different
programming languages.
5. FlowUp
FlowUp allows us to monitor the performance of all our production apps. Handy dashboards
let you keep track of your stats and metrics, including CPU and disk usage, memory usage,
frames per second, bandwidth, and more.
6. GameMaker: Studio
For Android game app developers, one of the most popular development tools is GameMaker:
Studio. GameMaker provides everything you need to create 2D games using very little code.
It is an extremely user-friendly application with a simple drag-and-drop interface.
7. Genymotion
Another Android emulator, Genymotion helps developers test and preview an application on
over 3,000 device scenarios. Genymotion is popular among gaming developers because it
comes with pre-installed standard Android images and graphics that are quite useful in the
testing process. It also provides greater speed than testing an app on an actual Android
device.
8. LeakCanary
LeakCanary is an open-source Java library that makes it easier to detect and correct
memory leaks in your application. Whenever a leak happens, LeakCanary immediately
notifies you. Then you can utilize the built-in stack trace to fix the problem or issues.
9. Unity 3D
Unity 3D is a cross-platform game development environment used for creating complicated,
graphics-intensive mobile games such as those containing virtual or augmented reality.
You can still use Unity 3D to create simpler 2D-based gaming experiences, but it is more
typically used for advanced gaming development.
Important questions:
1. What is Android
2. Android Ecosystem
3. Features of Android
4. Need of Android.
Unit –II
operating system, java JDK, Android SDK, Android development tools, Android virtual
devices, steps to install and configure Android studio and sdk
• Memory Management
• Processor Management
• Device Management
• File Management
• Network Management
• Security
• Control over system performance
• Job accounting
• Error detecting aids
• Coordination between other software and users
Memory Management
Memory management refers to management of Primary Memory or Main Memory. Main
memory provides a fast storage that can be accessed directly by the CPU. For a program to
be executed, it must in the main memory.
Processor Management
An Operating System does the following activities for processor management −
• Keeps tracks of processor and status of process. The program responsible for this task
is known as traffic controller.
• Allocates the processor (CPU) to a process.
• De-allocates processor when a process is no longer required.
Device Management
An Operating System manages device communication via their respective drivers. It does the
following activities for device management −
• Keeps tracks of all devices. Program responsible for this task is known as the I/O
controller.
• Decides which process gets the device when and for how much time.
• Allocates the device in the efficient way.
• De-allocates devices.
File Management
A file system is normally organized into directories for easy navigation and usage. These
directories may contain files and other directions.
An Operating System does the following activities for file management −
• Keeps track of information, location, uses, status etc. The collective facilities are often
known as file system.
• Decides who gets the resources.
• Allocates the resources.
• De-allocates the resources.
It is a core package used in Java, along with the JVM (Java Virtual Machine) and the
JRE (Java Runtime Environment). if you need in running Java programs on your machine
then you can easily do it using Java Runtime Environment.
However, if you would like to develop a Java-based software application then along with
JRE you may need some
additional necessary tools, which is called JDK.
JDK=JRE+Development Tools
Contents of JDK
The JDK has a private Java Virtual Machine (JVM) and a few other resources necessary for
the development of a Java Application.
JDK contains:
• Java Runtime Environment (JRE),
• An interpreter/loader (Java),
• A compiler (javac),
• An archiver (jar) and many more.
• Java
class Hello{
System.out.println("Hello Geek!");
After that just simply use the javac command, which is used for the compilation purpose
in Java.
C:\Users\Pinaki\Documents>java hello_world
(Output:) Hello Geek!
JDK contains many useful tools and among them, the most popular after javac is the jar
tool. The jar file is nothing but a full pack of Java classes. After creating the .class files,
you can put them together in a .jar, which compresses and structures them in a predictable
fashion.
Below there is a comprehensive list of mostly used components of Jdk which are very useful
during the development of a java application.
Component Use
Jdb Debugger,
Android SDK is a collection of libraries and Software Development tools that are essential
for Developing Android Applications. Whenever Google releases a new version or update of
Android Software, a corresponding SDK also releases with it. In the updated or new version
of SDK, some more features are included which are not present in the previous version.
Android SDK consists of some tools which are very essential for the development of Android
Application. These tools provide a smooth flow of the development process from developing
and debugging. Android SDK is compatible with all operating systems such as Windows,
Linux, macOS, etc.
Components of Android SDK
Android SDK Components play a major role in the Development of Android applications.
Below are the important components:
1. Android SDK Tools
Android SDK tool is an important component of Android SDK. It consists of a complete set
of development and debugging tools. Below are the SDK developer tools:
• Android SDK Build tool.
• Android Emulator.
• Android SDK Platform-tools.
• Android SDK Tools.
These are shown below :
2. Android SDK Build-Tools
Android SDK build tools are used for building actual binaries of Android App. The main
functions of Android SDK Build tools are built, debug, run and test Android applications.
3. Android Emulator
An Android Emulator is a device that simulates an Android device on your system. Suppose
we want to run our android application that we code. One option is using Android
Emulator. In Android Emulator the virtual android device is shown on our system on which
we run the Android application that we code.
In Android Virtual Emulator all functions that are feasible on real Android mobile is works
on virtual Device like:
• phone calls, text messages.
• stimulate different network speeds.
• specify the location of a device
• access on google play store and lot’s more.
Android has Gradle-base support that has features like visual layout editor,
intelligent code editor, real-time profilers and APK analyzer. It acts just like any
other Java IDE in terms of error investigating and file hierarchy.
2. Visual Studio – Xamarin
Xamarin was launched in 2011 which is the best free IDE for delivering an
enterprise- quality, cross-platform approach. Xamarin supplies add-ins to
Microsoft Visual Studio that allows developers to build Android, iOS, and
Windows apps within the IDE
3. IntelliJ IDEA
4. Eclipse IDE
It is one of the most popular IDES of Android apps. The open-source software
is free to use. Released under the Eclipse Public License, it holds a large
community having plenty of plugins and configurations. Highly customizable
offers full support for Java programming language and XML.
1. Explain the Steps to install and configure android Studio and SDK
Installation
Follow steps below for complete installation and configuration of Android Studio.
Pre-requirements
• Microsoft windows 7/8/10 (32 or 64 bits)
• Minimum 3GB RAM (recommended 8GB)
• 2GB disk space
• 1280 x 800 minimum screen resolution size
• Intel processor for accelerated emulator
• Android SDK
Note: If you don’t have Android SDK, you can download with Android studio.
Go to the end of download’s page and find android-studio-bundle-
162.4069837-windows.exe it includes SDK also.
Step 2) Run .exe file
Now the next step is to launch .exe file you just download. Following screen will appear
Step 6: Finish
This informs you installation has completed. Click Finish. Make sure
Start Android Studio is checked. Following splash screen of Android
Studio will appear.
The android project contains different types of app modules, source code files, and resource
files. We will explore all the folders and files in the android app.
1. Manifests Folder
2. Java Folder
3. res (Resources) Folder
• Drawable Folder
• Layout Folder
• Mipmap Folder
• Values Folder
4. Gradle Scripts
1. Manifests Folder
Manifests folder contains AndroidManifest.xml for creating our android application. This
file contains information about our application such as the Android version, metadata,
states package for Kotlin file, and other application components. It acts as an intermediator
between android OS and our application.
Following is the manifests folder structure in the android application.
AndroidManifest.xml
2. Java folder
The Java folder contains all the java and Kotlin source code (.java) files that we create
during the app development, including other Test files. If we create any new project using
Kotlin, by default the class file MainActivity.kt file will create automatically under the
package name “com.geeksforgeeks.myfirstkotlinapp” as shown below.
res/layout folder
The layout folder contains all XML layout files which we used to define the user interface
of our application. It contains the activity_main.xml file.
res/mipmap folder
This folder contains launcher.xml files to define icons that are used to show on the home
screen.
res/values folder
Values folder contains a number of XML files like strings, dimensions, colors, and style
definitions. One of the most important files is the strings.xml file which contains the
resources.
1. 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 {
}
2. 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 {
}
3. 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 BroadcastReceiver class and each
message is broadcaster as an Intent object.
public class MyReceiver extends BroadcastReceiver {
public void onReceive(context,intent){}
}
4. 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 ContentProvider 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
There are additional components which will be used in the construction of above mentioned
entities, their logic, and wiring between them. These components are −
S.No Components & Description
1
Fragments
Represents a portion of user interface in an Activity.
2
Views
UI elements that are drawn on-screen including buttons, lists forms etc.
3
Layouts
View hierarchies that control screen format and appearance of the views.
4
Intents
Messages wiring components together.
5
Resources
External elements, such as strings, constants and drawable pictures.
6
Manifest
Configuration file for the application.
UI screen components
A typical user interface of an android application consists of action bar and the application
content area.
• Main Action Bar
• View Control
• Content Area
• Split Action Bar
Types of layout
There are many types of layout. Some of which are listed below −
• Linear Layout
• Absolute Layout
• Table Layout
• Frame Layout
• Relative Layout
Linear Layout
Linear layout is further divided into horizontal and vertical layout. It means it can arrange
views in a single column or in a single row. Here is the code of linear layout(vertical) that
includes a text view.
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”vertical” >
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”@string/hello” />
</LinearLayout>
AbsoluteLayout
The AbsoluteLayout enables you to specify the exact location of its children. It can be
declared like this.
<AbsoluteLayout
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
xmlns:android=”http://schemas.android.com/apk/res/android” >
<Button
android:layout_width=”188dp”
android:layout_height=”wrap_content”
android:text=”Button”
android:layout_x=”126px”
android:layout_y=”361px” />
</AbsoluteLayout>
TableLayout
The TableLayout groups views into rows and columns. It can be declared like this.
<TableLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_height=”fill_parent”
android:layout_width=”fill_parent” >
<TableRow>
<TextView
android:text=”User Name:”
android:width =”120dp”
/>
<EditText
android:id=”@+id/txtUserName”
android:width=”200dp” />
</TableRow>
</TableLayout>
RelativeLayout
The RelativeLayout enables you to specify how child views are positioned relative to each
other.It can be declared like this.
<RelativeLayout
android:id=”@+id/RLayout”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
xmlns:android=”http://schemas.android.com/apk/res/android” >
</RelativeLayout>
FrameLayout
The FrameLayout is a placeholder on screen that you can use to display a single view. It can
be declared like this.
<?xml version=”1.0” encoding=”utf-8”?>
<FrameLayout
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignLeft=”@+id/lblComments”
android:layout_below=”@+id/lblComments”
android:layout_centerHorizontal=”true” >
<ImageView
android:src = “@drawable/droid”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />
</FrameLayout>
<TextView android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".HelloWorldAppActivity"
android:typeface="serif" android:textColor
="#0F0" android:textSize="25dp"
android:textStyle="italic"
android:gravity="center_horizontal" />
This code makes the text of the TextView control appear in serif font, green color, 25dp
size, italic, and at the horizontal center of the container
EditText is a user interface (UI) used to retrieve and modify text data from a user in an
Android app. EditText is a subclass of TextView that inherit all the property of TextView.
Nowadays, EditText is represented with the PlainText element in UI, which displays an
empty text field while designing the app. EditText (or PlainText) is used in the app whenever
you need input from the user side and proceed with its text (or value) in your app.
EditText (or PlainText) is not only used to get plain text in your application, but even you can
use it to get values such as email, number, password, etc. To get the value of each type in
EditText, you must specify its input type in its inputType attribute. For example, to input
plain text, set the inputType attribute to "text", and to input only numeric values, set
the inputType attribute to "number".
Syntax of EditText
1. <Layout>
2. ...
3. ...
4. <EditText
5. android: someAttribute1 = "value of attribute1"
6. android: someAttribute2 = "value of attribute2"
7. ...
8. ...
9. android: someAttributeN = "value of attributeN"
10. </EditText>
11. ...
12. ...
13. </Layout>
Android radio button is a widget that can have more than one option to choose from. The
user can choose only one option at a time. Each option here refers to a radio button and
all the options for the topic are together referred to as Radio Group. Hence, Radio Buttons
are used inside a RadioGroup.
For Example:
This image shows 4 options of the subjects for a question. In this, each mentioned subject
is a Radio Button and all the 4 subjects together are enclosed in a Radio Group.
Android Toggle Button can be used to display checked/unchecked (On/Off) state on the
button.
It is beneficial if user have to change the setting between two states. It can be used to On/Off
Sound, Wifi, Bluetooth etc.
Since Android 4.0, there is another type of toggle button called switch that provides slider
control.
Android ToggleButton and Switch both are the subclasses of CompoundButton class.
There can be a lot of usage of checkboxes. For example, it can be used to know the hobby of
the user, activate/deactivate the specific action etc.
There are many inherited methods of View, TextView, and Button classes in the CheckBox
class. Some of them are as follows:
Method Description
We can display the android progress bar dialog box to display the status of work being done
e.g. downloading file, analyzing status of work etc.
In this example, we are displaying the progress dialog for dummy file download operation.
Here we are using android.app.ProgressDialog class to show the progress bar. Android
ProgressDialog is the subclass of AlertDialog class.
The ProgressDialog class provides methods to work on progress bar like setProgress(),
setMessage(), setProgressStyle(), setMax(), show() etc. The progress range of Progress Dialog
is 0 to 10000.
11. Write about List view in android studio.
Android ListView is a view which contains the group of items and displays in a scrollable
list. ListView is implemented by importing android.widget.ListView class. ListView is a
default scrollable which does not use other scroll view.
ListView uses Adapter classes which add the content from data source (such as string array,
array, database etc) to ListView. Adapter bridges data between an AdapterViews and other
Views (ListView, ScrollView etc).
12. Write about Grid view in android studio
Android GridView shows items in two-dimensional scrolling grid (rows & columns) and the
grid items are not necessarily predetermined but they automatically inserted to the layout
using a ListAdapter
Grid view
An adapter actually bridges between UI components and the data source that fill data into
UI Component. Adapter can be used to supply the data to like spinner, list view, grid view
etc.
The ListView and GridView are subclasses of AdapterView and they can be populated by
binding them to an Adapter, which retrieves data from an external source and creates a View
that represents each data entry.
13. Write about image view in android.
ImageView class is used to display any kind of image resource in the android application
either it can be android.graphics.Bitmap or android.graphics.drawable.Drawable (it is a
general abstraction for anything that can be drawn in Android). ImageView class
or android.widget.ImageView inherits the android.view.View class which is the subclass
of Kotlin. AnyClass.Application of ImageView is also in applying tints to an image in order
to reuse a drawable resource and create overlays on background images. Moreover,
ImageView is also used to control the size and movement of an image.
After that you have to create an object of TimePicker class and get a reference of the above
defined xml component. Its syntax is given below.
import android.widget.TimePicker;
private TimePicker timePicker1;
timePicker1 = (TimePicker) findViewById(R.id.timePicker1);
In order to get the time selected by the user on the screen, you will use getCurrentHour() and
getCurrentMinute() method of the TimePicker Class. Their syntax is given below.
int hour = timePicker1.getCurrentHour();
int min = timePicker1.getCurrentMinute();
Android Date Picker allows you to select the date consisting of day, month and year in your
custom user interface. For this functionality android provides DatePicker and
DatePickerDialog components.
In this tutorial, we are going to demonstrate the use of Date Picker through DatePickerDialog.
DatePickerDialog is a simple dialog containing DatePicker.
In order to show DatePickerDialog , you have to pass the DatePickerDialog id
to showDialog(id_of_dialog) method. Its syntax is given below −
showDialog(999);
In the last step, you have to register the DatePickerDialog listener and override its onDateSet
method. This onDateSet method contains the updated day, month and year. Its syntax is
given below −
private DatePickerDialog.OnDateSetListener myDateListener = new
DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) {
// arg1 = year
// arg2 = month
// arg3 = day
}
};
UNIT-4
Android platform services, Android system Architecture, Android Security model,
Applications development: creating small application
1. Explain Android platform service
The Android platform provides and runs predefined system services and every Android
application can use them, given the right permissions. These system services are usually
exposed via a specific Manager class. Access to them can be gained via the
getSystemService() method.
Permission
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.
Add permissions to the manifest
On all versions of Android, to declare that your app needs a permission, put a <uses-
permission> element in your app manifest, as a child of the top-level <manifest> element. For
example, an app that needs to access the internet would have this line in the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.snazzyapp">
<uses-permission android:name="android.permission.INTERNET"/>
<application ...>
...
</application>
</manifest>
There can be two forms of a service. The lifecycle of service can follow two different paths:
started or bound.
1. Started
2. Bound
1) Started Service
A service is started when component (like activity) calls startService() method, now it runs
in the background indefinitely. It is stopped by stopService() method. The service can stop
itself by calling the stopSelf() method.
2) Bound Service
A service is bound when another component (e.g. client) calls bindService() method. The
client can unbind the service by calling the unbindService() method.
The service cannot be stopped until all clients unbind the service.
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
your custom service would help you in performing the right operation in the right state.
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.
onStartCommand()
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.
onBind()
This is invoked when any component starts the service by calling onBind.
onUnbind()
This is invoked when all the clients are disconnected from the service.
onRebind()
This is invoked when new clients are connected to the service. It is called after onUnbind
onDestroy()
This is a final clean up call from the system. This is invoked just before the service is being
destroyed. Could be very useful to cleanup any resources such as threads, registered
listeners, or receivers.
3. Native C Libraries. In Native C library layer, it consists of many C/C++ libraries. And the
core functions of android are implemented by those libraries. Some typical core libraries
are as follows: Bionic C lib, OpenCore, SQLite, Surface Manager, WebKit, 3D library.
4. Android Runtime Environment. Runtime environment consists of Dalvik Java virtual
machine and some implementations of Java core libraries.
5. HAL. This layer abstracts different kinds of hardwares and provides an unified program
interface to Native C libraries. HAL can make Android port on different platforms more
easily.
6. Linux Kernel. Android’s core system functions (e.g., safety management, RAM
management, process management, network stack) depend on Linux kernels.
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 Can not
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. (2)
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 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
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 has to 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.
The following ate the steps required for building an adroid application.
• Application name
• Company domain (this gets reversed into com.domain) to keep applications
partitioned even if they have the same Application name.
• Project Location – where to store the files
• The Package name is suggested from the Application Name and Company
domain
• By default, Android applications are written in Java. If you want to support
alternate languages, such as C++ (for native code) or Kotlin, select the
appropriate check boxes.
Then, click Next.
On the Add an Activity to Mobile dialog, select the Empty Activity type. Then, click Next.
This will create a default application ready to be built and run directly from Android
Studio.
Resources in Android are organized into a subdirectory of the project named res, as described
previously. Resources fall into a number of categories. Three of these categories are:
• Drawables - This folder contains graphics files, such as icons and bitmaps
• Layouts - This folder contains XML files that represent the layouts and views of the
application. These will be examined in detail below.
• Values - This folder contains a file named strings.xml. This is the primary means for
string localization for the application. The file colors.xml is useful for defining color
codes used by the application. This file is analogous to a css style sheet for those
familiar with web programming techniques.
Now that the application has compiled successfully, it's time to run the sample application.
To setup an emulator, or more properly, an Android Virtual Device (AVD), select Tools > AVD
Manager. Or, simply click on the Play (Run) icon.
Finally, click OK to launch the application on the selected deployment target. The AVD or
emulator launches with our sample application running on it.
Now that the application is running on the emulator, let's have a look at what is happening
behind the scenes. Within Android Studio, select View > Tool Windows.
UNIT-5
Introduction of MIT App Inventor,Application Coding 5.3Programming Basics & Dialog, More
Programming Basics, Alarm Clock Application, Audio & Video, Drawing Application File
Game, Device Location,Web Browsing
App Inventor is a free, cloud-based service that allows you to make your own mobile apps
using a blocks-based programming language. You access App Inventor using a web browser
(Chrome, Firefox, Safari).
MIT App Inventor uses drag-and-drop style code building blocks, similar to those used by
the Scratch coding language. This makes it easy to pick up from a young age and also helps
take the otherwise potentially overwhelming complexity out of getting started.
The use of bright colors, clear buttons, and plenty of tutorial guidance all add up to a tool
that helps get even the more tech-troubled learners get up and running. That includes
students being guided by a teacher in class as well as those wishing to get started, alone,
from home.
,Application Coding 5.3Programming Basics & Dialog, More Programming Basics, Alarm
Clock Application, Audio & Video, Drawing Application File Game, Device Location,Web
Browsing
When you are done you and your friends will be able to use this app to play a fun game of
pop the balloon!
• The player will have to “pop”—that is, click on—the balloons before they reach the bottom
of the screen
Step1: Click “Start a new project” give it a name and click “Ok” to get started!
Step2 : Add components! To build this app you will need five components—a canvas, three
image sprites, and a clock. Find these components in the Palette and drag and drop them
onto the Viewer
Step 3: Upload media files, To complete this app you will need to download a picture of a
balloon, Then you will need to upload it to the App Inventor server by clicking the upload file
buBon under “Media”
1. Click on Canvas1 and set both the Height and Width to “Fill parent…”
2. 2. Click on Clock1 and set TimerInterval to 500
3. Now lets set the properites of our Image Sprites, Set the X value of ImageSprite1 to 10;
the X value of ImageSprite2 to 100; and the X value of ImageSprite3 to 190
Set Heading to 270
• Set Height to 80 pixels
• Set Width to 80 pixels
• Set Picture to Balloon.png
• Set Speed to 25
• Uncheck the boxes for Enabled, Rotates, and Visible
Every half a second (or 500 milliseconds), Clock1’s timer will go off—that’s because we set
the TimerInterval property to 500! When this happens, we would like one of our three Image
Sprites to appear and begin falling to the bottom of the screen. To do this, we have to choose
a Sprite, and we would like that choice to be random. App Inventor lets us do this!
1. First, click on Variables in the Blocks menu and drag out a block
4. Change “0” to “1” and then click it onto the “initialize global name” block
8. Click on Math again and drag out, Change “100” to “3” and lock the block into place with
the “set global randomNumber”
9. Snap these two into place inside the “when Clock1.Timer” block
Step 6 : We would like the app to do different things depending on which number was chosen
by App Inventor —because we asked it for a random number between one and three, it could
have given us a 1,2, or 3.
Now we need to fill in our “if, then” block. If App Inventor has given us the number 1, we
want to make ImageSprite1 appear; if it has given us the number 2, we want to make
ImageSprite2 appear; otherwise, it must have given us the number 3, and so we want to
make ImageSprite3 appear
3. Choose “global randomNumber” from the dropdown list and then click this block into
place in the Logic block’s first space.
5. Change “0” to “1” and click it into place in the Logic block’s second space
You have written code that checks if the randomNumber variable is equal to 1. With just a
small tweak it will be able to check if randomNumber is equal to 2.
1. Copy and paste the block of code you just created. To do so, right click on it and choose
“Duplicate from the drop-down list”
2. On the duplicate block, change the “1” to a “2”
Now, click the two blocks you’ve just made into place in the “if, then” block,
Now we will tell the app what to do, depending on the random number that is selected.
2. Click on Logic and drag out a True block. Click it into place with the “set
ImageSprite1.Enabled”
3. Duplicate the block as you did before, by right clicking. For the duplicated block, replace
“Enabled” with “Visible” by clicking on the second dropdown list.
4. Lock the two blocks together.
5.Take the group of two blocks and duplicate it twice (so that you get three copies).
6. Keep the original as it was, but change “ImageSprite1” to “ImageSprite2” in one of the
copies, and to “ImageSprite3” in the other
Step 7 : Okay, great, we have balloons that appear randomly and fall to the bottom of the
phone, but we would like for something to happen when we touch them.
3. Duplicate it twice to get three copies, and click them together to form a stack:
When each balloon is touched, we want to return it to its original state. This means resetting
its Y, Visible, and Enabled properties.
1. Grab the stack of blocks you made in the last slide. Change the Y of one block to Visible
using the dropdown menu, and the other Y to Enabled.
The app should do the same thing when ImageSprite2 or ImageSprite3 are touched. That
means we can reuse the same stack of blocks and just change the sprite name.
1. Duplicate the when ImageSprite1.Touched group of blocks twice (to get three copies)
2. For one of the group of blocks, change all mention of “ImageSprite1” to “ImageSprite2”
In order to test your app, you will need an Android phone with the MIT AI2 Companion app
installed. To download the Companion from the app store, scan the QR code below or search
directly for “MIT AI2 Companion” on the Google Play Store.
Open the AI2 Companion app. You can then either input the 6-letter code or scan the QR
code to connect.
This example will show you how to add a media file (a sound in this case) to your Screen and
play it by clicking a button.
DESIGNER SECTION
BLOCKS SECTION
We have created the visual part of our app, now let’s include the blocks of code to play the
sound when the button is clicked. Click on Button on the right side of the screen and drag
the following block:
when Button1.Click
do
call Sound1.Play
Now, run the app with Emulator and listen to your song.