Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
47 views

Android

Android is the world's most popular mobile operating system, powering billions of devices globally. It was developed by Android Inc. which was acquired by Google in 2005. It is an open-source, Linux-based operating system designed primarily for touchscreen devices. At its core is the Linux kernel, upon which sits libraries and APIs. Android applications are built using the Android software development kit and run on the Android runtime in a sandboxed environment.

Uploaded by

R K
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Android

Android is the world's most popular mobile operating system, powering billions of devices globally. It was developed by Android Inc. which was acquired by Google in 2005. It is an open-source, Linux-based operating system designed primarily for touchscreen devices. At its core is the Linux kernel, upon which sits libraries and APIs. Android applications are built using the Android software development kit and run on the Android runtime in a sandboxed environment.

Uploaded by

R K
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 57

Android (operating system)

Introduction:
Android is the world’s most popular mobile operating system(os). Ever
since it was launched in the year 2008.android began as a simple smart
phone and now it is power house for countless no of devices. With an
estimate 1.5 billion android users across the globe that is 1/7 of entire
world population. This is the right time to start exploring this amazing os.

About:
Android is a mobile operating system based on a modified version of the
linux kernel and other open-source software, designed primarily for
touchscreen mobile devices such as smartphones and tablets.
What is the history of Android?
Android began in 2003 as a project of the American technology
company Android Inc., to develop an operating system for digital
cameras. In 2004 the project changed to become an operating system
for smartphones. Android Inc., was bought by the American search
engine company Google Inc., in 2005.

Current version:
In this various versions are passed away now Android 11 is the
eleventh major release and 18th version of Android. The mobile
operating system developed by the Open Handset Alliance led by
Google.

11.0.0_r62
Latest
(RSV1.210329.071) /
release
December 5, 2022
Why Android:
Basically, Android is thought of as a mobile operating system. But it is
not limited to mobile-only. It is currently used in various devices such as
mobiles, tablets, televisions, etc.
Android provides a rich application framework that allows us to build
innovative apps and games for mobile devices in a Java language
environment.
And also.

 Android provides an extensive developer's community support.


 It uses the core Java language for developing applications.
 It also provides high marketing.
 Application development cost is less.
Android (operating system)

 Good storage and uses a lightweight relational database, SQLite


 It provides good security.

Features of Android
Android is a powerful operating system competing with Apple 4GS and
supports great features which makes it popular in the world. These are:

 Android is an open-source platform or application.


 Android is a customizable operating system, so any one
customized by itself only.
 It has an opening screen, quick notification option, stylish yet
straightforward UI, etc.
 A many range of applications can be chosen to install and use
from the Android Play Store. The consumers have the facility to
choose from the multiple options of mobile applications available in
the market
 Features like weather details, opening screen, live RSS (Really
Simple Syndication) feeds, etc, are interesting to have and are
thus supported and facilitated by Android.
 Vital features like messaging services(SMS and MMS), web
browser, storage (SQLite), connectivity (GSM, CDMA, BlueTooth,
Wi-Fi, etc.), media, handset layout, etc are also supported and
facilitated by Android.
 It supports Touch-based keyboards.
 It has a Customized Home screen.
 It provides custom ROMs.

Categories of Android applications:


The top categories of android applications available in the market are
listed below:

 Entertainment
 Tools
 Communication
 Productivity
 Personalization
 Music and Audio
 Social
 Media and Video
Android (operating system)

 Travel and Local


There are many more categories available in the market .

Overview:
Android is a mobile operating system based on a modified version of the
Linux kernel and other open-source software, designed primarily for
touchscreen mobile devices such as smartphones and tablets. Android
is developed by a partnership of developers known as the Open
Handset Alliance and commercially sponsored by Google. It was
disclosed in November 2007, with the first commercial Android device,
the HTC Dream, launched in September 2008.

It is free and open-source software. Its source code is Android Open


Source Project (AOSP), primarily licensed under the Apache License.
However, most Android devices dispatch with additional proprietary
software pre-installed, mainly Google Mobile Services (GMS), including
core apps such as Google Chrome, the digital distribution platform
Google Play and the associated Google Play Services development
platform.

o About 70% of Android Smartphone runs Google's ecosystem,


some with vendor-customized user interface and some with
software suite, such as TouchWizard later One UI by Samsung,
and HTC Sense.
o Competing Android ecosystems and forksinclude Fire OS
(developed by Amazon) or LineageOS. However, the "Android"
name and logo are trademarks of Google which impose standards
to restrict "uncertified" devices outside their ecosystem to use
android branding.

Android - Environment Setup


Set-up Java Development Kit (JDK):
You can download the latest version of Java JDK from Oracle's Java site
− You will find instructions for installing JDK in downloaded files, follow
the given instructions to install and configure the setup. Finally set PATH
and JAVA_HOME environment variables to refer to the directory that
contains java and javac.
If you are running Windows and installed the JDK
Android (operating system)

Android – Architecture

Android architecture is categorized into five parts and it’s a layered


architecture and these layers interact with each other

1. Linux kernel
2. Libraries (middleware),
3. Android Runtime
4. Application Framework
5. Applications
Android (operating system)

Linux kernel:
It is the heart of android architecture that exists at the root of android
architecture. Linux kernel is responsible for device drivers, power
management, memory management, device management and resource
access comes under the responsibility of the Linux Kernel.

The lowest layer is the kernel layer which is basically a hardware layer it
is the layer which is going to interact with the hardware so here we have
drivers for example display driver camera driver flash driver and IPC
binder right so this is going to manage the power so lets say the
phone's battery is low so this kernel layer is gonna detect that status.
The linux kernel is written in C

Libraries:
On top of Linux kernel there is a set of libraries is written in C++
including open-source Web browser engine such as WebKit, OpenGL
(graphical interface), FreeType, SQLite(relational data base),
Media(audio,video and music files), and 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.

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 (Java Virtual Machine)but it is optimized for mobile devices. It
consumes less memory and provides fast performance.

the runtime of Android based on dalvik virtual machine and the core
libraries from Java itself nothing but JVM.
Android (operating system)

Application Framework:
The Application Framework is written in java.The Application Framework
layer provides many higher-level services to applications in the form of
Java. Application developers are allowed to make use of these services
in their applications.
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.
Applications:
On the top of android framework, there are applications. Applications are
also written in java. 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 linuxkernal.

Android - Application Components

An android component is simply a piece of code that has a well-defined


life cycle e.g. Activity, Receiver, Service etc.
Application components are the essential building blocks of an Android
application or fundamental components of android. Mainly they are
Activities:
They dictate the UI and handle the user interaction to the smart phone
screen.
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 −
publicclassMainActivityextendsActivity
{
}
Android (operating system)

Services:
They handle background processing associated with an application.
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 −
publicclassMyServiceextendsService
{
}

Broadcast Receivers:
They handle communication between Android OS and applications.
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.
publicclassMyReceiverextendsBroadcastReceiver
{
publicvoidonReceive(context,intent){}
}

Content Providers:
They handle data and database management issues.
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.
Android (operating system)

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.
publicclassMyContentProviderextendsContentProvider
{
publicvoidonCreate(){}
}

Core Building Blocks

The core building blocks or fundamental components of android are


activities, views, intents, services, content providers, fragments and
AndroidManifest.xml.

Activity:
An activity is a class that represents a single screen. It is like a Frame in
AWT.(Abstract Window Toolkit)
View:
A view is the UI element such as button, label, text field etc. Anything
that you see is a view.
Intent:
Intent is used to invoke components. It is 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.

Service:
Service is a background process that can run for a long time.

There are two types of services local and remote. Local service is
accessed from within the application whereas remote service is
accessed remotely from other applications running on the same device.
Android (operating system)

Content Provider:

Content Providers are used to share data between the applications.

Fragment:

Fragments are like parts of activity. An activity can display one or more
fragments on the screen at the same time.
AndroidManifest.xml:
It contains informations about activities, content providers, permissions
etc. It is like the web.xml file in Java EE.
Android Virtual Device (AVD):
It is used to test the android application without the need for mobile or
tablet etc. It can be created in different configurations to emulate
different types of real devices.
Broadcast Receivers:
They handle communication between Android OS and applications.
Layouts:
View hierarchies that control screen format and appearance of the
views.
Resources:
External elements, such as strings, constants and drawable pictures.

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
Android (operating system)

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.

Requirements
s for Install the emulator:
The Android emulator takes additional requirements beyond the b
basic
system requirement for Android Studio. These requirements are given
below:

o SDK Tools 26.1.1 or higher


o 64-bit processor
o Windows: CPU with UG (unrestricted guest) support
o HAXM 6.2.1 or later (recommended HAXM 7.2.0 or later)

Install the emulator:


The Android emulator is installed while installing the Android Studio.
However some components of emulator may or may not be installed
while installing Android Studio. To install the emulator component, select
the Android Emulator component in the SDK Tools tab of the SDK
Manager.
Android (operating system)

How to setup Android for Eclipse IDE:

To Develop Android Applications


Let's see the list of software required to setup android for eclipse IDE
manually.
1. Install the JDK(Java Development Kit)
2. Download and install the Eclipse for developing android application
3. Download and Install the android SDK(Software Development Kit)
4. Install the ADT plugin for eclipse
5. Configure the ADT plugin(Android Development Tools)
6. Create the AVD(Android Virtual Device)
7. Create the hello android application

Android - Hello World Example


Let us start actual programming with Android Framework. Before you
start writing your first example using Android SDK, you have to make
sure that you have set-up your Android development environment
properly as explained in Android - Environment Set-up .

The Android SDK is a software development kit that includes a


comprehensive set of development tools. These include a debugger,
libraries, a handset emulator based on documentation and sample code

So let us proceed to write a simple Android Application which will print


"Hello World!".
Android (operating system)

Create the New Android project:


For creating the new android studio project:

1) Select Start a new Android Studio project


Android (operating system)

2) Provide the following information: Application name, Company


domain, Project location and Package name of application and click
next.
Android (operating system)

3) Select the API level of application and click next.


Android (operating system)

4) Select the Activity type (Empty Activity).


Android (operating system)

5) Provide the Activity Name and click finish.

After finishing the Activity configuration, Android Studio auto generates


the activity class and other required configuration files.

Now an android project has been created. You can explore the android
project and see the simple program, it looks like this:
Android (operating system)

To run the android application, click the run icon on the toolbar or simply
press Shift + F10.

The android emulator might take 2 or 3 minutes to boot. So please have


patience. After booting the emulator, the android studio installs the
application and launches the activity. You will see something like this:
Android (operating system)

Android - UI Layouts:
The basic building block for user interface is a View object which is
created from the View class and occupies a rectangular area on the
screen and is responsible for drawing and event handling. View is the
base class for widgets, which are used to create interactive UI
components like buttons, text fields, etc.
The ViewGroup is a subclass of View and provides invisible container
that hold other Views or other ViewGroups and define their layout
properties.
At third level we have different layouts which are subclasses of
ViewGroup class and a typical layout defines the visual structure for an
Android user interface and can be created either at run time
using View/ViewGroup objects or you can declare your layout using
simple XML file main_layout.xml which is located in the res/layout
folder of your project.

Android Widgets (or)UI Controls


In computing, a widget is an element of a graphical user interface
that displays information or provides a specific way for a user to
interact with the operating system (OS) or an application.

There are given a lot of android widgets with simplified examples such
as Button, EditText, AutoCompleteTextView, ToggleButton, DatePicker,
TimePicker, ProgressBar etc.

Android widgets are easy to learn. The widely used android widgets with
examples are given below:

Android Button:
Let's learn how to perform event handling on button click.

Handling here means managing. In the whole Android Event Handling,


all we do is manage the actions. These actions are related to the user's
interaction. These Events collect data about the user's interaction using
interactive components. For example, when you click on some button,
onClick() is invoked.
Android (operating system)

Android Toast:
Displays information for the short duration of time.

A toast provides simple feedback about an operation in a small


popup. It only fills the amount of space required for the message and
the current activity remains visible and interactive. Toasts automatically
disappear after a timeout.

Custom Toast:

We are able to customize the toast, such as we can display image on


the toast

ToggleButton:
It has two states ON/OFF.

ToggleButton allows users to change settings between two states from


your phone's Settings menu such as turning your WiFi, Bluetooth,
etc. on / off.

CheckBox:
Checkboxes allow the user to select one or more options from a
set.

Let's see the application of simple food ordering.

AlertDialog:

AlertDialog displays a alert dialog containing the message with OK and


Cancel buttons.

Spinner:

Spinner displays the multiple options, but only one can be selected at a
time.

AutoCompleteTextView:
AutoCompleteTextView is a component used to show suggestions
while writing in an editable text field.
Android (operating system)

Let's see the simple example of AutoCompleteTextView.

RatingBar:
RatingBar displays the rating bar.

DatePicker:

Datepicker displays the datepicker dialog that can be used to pick the
date.

TimePicker:

TimePicker displays the timepicker dialog that can be used to pick the
time.

ProgressBar:
ProgressBar displays progress task.

Android - Event Handling


Events are a useful way to collect data about a user's interaction
with interactive components of Applications. Like button presses or
screen touch etc. The Android framework maintains an event queue as
first-in, first-out (FIFO) basis. You can capture these events in your
program and take appropriate action as per requirements.
There are following three concepts related to Android Event
Management
 Event Listeners − An event listener is an interface in the
View class that contains a single callback method. These
methods will be called by the Android framework when the
View to which the listener has been registered is triggered by
user interaction with the item in the UI.

An event listener is a procedure or function in a computer


program that waits for an event to occur. Examples of an
event are the user clicking or moving the mouse,
pressing a key on the keyboard, disk I/O, network
activity, or an internal timer or interrupt.
Android (operating system)

 Event Listeners Registration − Event Registration is the


process by which an Event Handler gets registered with an
Event Listener so that the handler is called when the Event
Listener fires the event.

 Event Handlers − When an event happens and we have


registered an event listener for the event, the event listener
calls the Event Handlers, which is the method that actually
handles the event.

Example:

Event Event Listener & Description


Handler

OnClickListener()
This is called when the user either clicks or touches or focuses
onClick() upon any widget like button, text, image etc. You will use
onClick() event handler to handle such event.

Android - Styles and Themes


Styles and themes on Android allow you to separate the details of your
app design from the UI structure and behavior, similar to stylesheets in
web design.

A style is a collection of attributes that specify the appearance for a


single View. A style can specify attributes such as font color, font size,
background color, and much more.

A theme is a collection of attributes that's applied to an entire app,


activity, or view hierarchy—not just an individual view. When you apply a
theme, every view in the app or activity applies each of the theme's
attributes that it supports. Themes can also apply styles to non-view
elements, such as the status bar and window background.

Styles and themes are declared in a style resource file in res/values/,


usually named styles.xml.
Android (operating system)

Theme != Style
Both themes and styles use the same <style> syntax but serve very
different purposes. You can think of both as key-value stores where the
keys are attributes and the values are resources. Let’s take a look at
each.

What’s in a style?
A style is a collection of view attribute values. You can think of a style as
a Map<view attribute, resource>. That is the keys are all view attributes
i.e. attributes that a widget declares and you might set in a layout file.
Styles are specific to a single type of widget because different widgets
support different sets of attributes:

Styles are a collection of view attributes; specific to a single type of


widget.

Scope
A style applied to a view only applies to that view, not to any of its
children. For example,( textbook) if you have a ViewGroup with three
buttons, setting the InlineAction style on the ViewGroup will not apply that
style to the buttons. The values provided by the style are combined with
those set directly in the layout

What’s a theme?
A theme is a collection of named resources which can be referenced
later by styles, layouts etc. They provide semantic names to Android
resources so you can refer to them later e.g. colorPrimary is a semantic
name for a given color.

These named resources are known as theme attributes, so a theme


is Map<theme attribute, resource>. Theme attributes are different from
view attributes because they’re not properties specific to an individual
view type but semantically named pointers to values which are applicable
more broadly in an app. A theme provides concrete values for these
named resources. In the example above the colorPrimary attribute
specifies that the primary color for this theme is teal. By abstracting
Android (operating system)

the resource with a theme, we can provide different concrete values


(such as colorPrimary=orange) in different themes.

Themes are a collection of named resources, useful broadly across an


application.

Themes versus Styles


Themes and styles have many similarities, but they are used for different
purposes. Themes and styles have the same basic structure—a key-
value pair which maps attributes to resources.

A style specifies attributes for a particular type of view. For example, one
style might specify a button's attributes. Every attribute you specify in a
style is an attribute you could set in the layout file. By extracting all the
attributes to a style, it's easy to use and maintain them across multiple
widgets.

A theme defines a collection of named resources which can be


referenced by styles, layouts, widgets, and so on. Themes assign
semantic names, like colorPrimary, to Android resources.

Styles and themes are meant to work together. For example, you might
have a style that specifies that one part of a button should
be colorPrimary, and another part should be colorSecondary. The actual
definitions of those colorsis provided in the theme. When the device
goes into night mode, your app can switch from its "light" theme to its
"dark" theme, changing the values for all those resource names. You
don't need to change the styles, since the styles are using the semantic
names and not specific colordefinitions
Android (operating system)

Create and apply a style


To create a new style or theme, open your
project's res/values/styles.xml file. For each style you want to create,
follow these steps:

1. Add a <style> element with a name that uniquely identifies the


style.
2. Add an <item> element for each style attribute you want to define.
The name in each item specifies an attribute you would otherwise
use as an XML attribute in your layout. The value in
the <item> element is the value for that attribute.

For example, if you define the following style:


<?xml version="1.0" encoding
encoding="utf-8"?>
<resources>
<stylename="GreenText
GreenText"parent="TextAppearance.AppCompa
TextAppearance.AppCompat">
<item name="android:textColor
android:textColor">#00FF00</item>
</style>
</resources>
Android (operating system)
Android (operating system)

Android - Custom Components


Android offers a great list of pre-built widgets like Button, TextView,
EditText, ListView, CheckBox, RadioButton, Gallery, Spinner,
AutoCompleteTextView etc. which you can use directly in your Android
application development, but there may be a situation when you are not
satisfied with existing functionality of any of the available widgets.
Android provides you with means of creating your own custom
components which you can customized to suit your needs.
If you only need to make small adjustments to an existing widget or
layout, you can simply subclass the widget or layout and override its
methods which will give you precise control over the appearance and
function of a screen element.
In android, creating a custom view component is something similar to
defining a class in Java. Following is the high-level overview of what we
need to know to get started in creating our own View components in
android applications.

 We need to extend an existing View class or subclass with our


own class.
 Need to override some of the methods from superclass based on
our requirements. The superclass methods which we are going to
override should start with 'on' like onDraw() or onKeyDown().
This is similar to on... events in Activity or ListActivity that we
want to override for lifecycle and other functionality hooks.
 Once we are done with creation of our new extension class, we
need to use it in the place of View.

While creating a custom component, we need to remember that it should


provide an easy interface to use it in our applications and allow users to
configure custom style attributes from android XML layouts.
Android (operating system)

Android - Drag and Drop


In android, the Drag and Drop framework allows users to move data
from one view to another using a graphical drag and drop gesture.

The Drag and Drop framework will include the following functionalities
to support the data movement in android applications
applications.

 Drag Event Class


 Drag Listeners
 Helper Methods and Classes

Generally, the Drag and Drop process starts when users making
gestures recognized as a signal to start dragging data and the
application tells the system that the drag is starting.

Once the drag is starting, the system call


call-back
back to our application to get
the state of data being dragged and it sends drag even
events
ts to the drag
event listeners or call-back
back methods of each View in the layout.

In android, the Drag and Drop process contains 4 steps or states, those
are
Android (operating system)

 Started
 Continuing
 Dropped
 Ended

Started:
This event will occur when we start dragging an item in layout and our
application will call the startDrag() method to tell the system to start a
drag. The startDrag() method arguments will provide data to be
dragged, metadata for this data and a call-back for drawing the drag
shadow.

The system will respond back to our application to get a drag shadow
and it will display the drag shadow on the device.

Continuing:
When the user continues to drag, the drag shadow intersects with the
bounding box of a View object and the system sends one or more drag
events to the View object's drag event listener (In case if it is registered
to receive events).

The user continues the drag. System sends ACTION_DRAG_ENTERED


action followed by ACTION_DRAG_LOCATION action to the registered
drag event listener for the View where dragging point enters.

Dropped:
The user releases the dragged item within the bounding box of a View.
The system sends the View object's listener a drag event with action
type ACTION_DROP.

Ended:
Just after the action type ACTION_DROP, the system sends out a drag
event with action type ACTION_DRAG_ENDED to indicate that the drag
operation is over.
Android (operating system)

The DragEvent Class


The DragEvent represents an event that is sent out by the system at
various times during a drag and drop operation. This class provides few
Constants and important methods which we use during Drag/Drop
process.
Following are the different actoins available as a part of DragEvent
class.
ACTION_DRAG_STARTED
Signals the start of a drag and drop operation.
ACTION_DRAG_ENTERED
Signals to a View that the drag point has entered the bounding box of
the View.
ACTION_DRAG_LOCATION
Sent to a View after ACTION_DRAG_ENTERED if the drag shadow is
still within the View object's bounding box.
ACTION_DRAG_EXITED
Signals that the user has moved the drag shadow outside the bounding
box of the View.
ACTION_DROP
Signals to a View that the user has released the drag shadow, and the
drag point is within the bounding box of the View.
ACTION_DRAG_ENDED
Signals to a View that the drag and drop operation has concluded.

Drag Listeners
The combination of the onDragEvent(DragEvent) method
and View.OnDragListener is analogous to the combination of
the onTouchEvent() and View.OnTouchListener used with touch
events in Android.
Android (operating system)

The following sections of this guide refer to the method that receives
drag events as the drag event listener;

Helper Methods and Classes


Classes:

A helper method is used to perform a particular repetitive task common


across multiple classes. This keeps us from repeating the same piece of
code in different classes again n again. Whereas the class
class-specific
methods define its behaviour, the helper methods assist in that process.

Output of Android Drag and Drop Example


Android (operating system)

Android – Notifications
In android, Notification is a message which is used to alert the users
about some events that happening in our app.

Generally, the android Notifications will be displayed outside of our app’s


normal UI and alert the users without interrupting their current activities.
When you tell the system to issue a notification, it first appears as an
icon in the notification area. To see the details of the notification, the
user opens the notification drawer. Both the notification area and the
notification drawer are system-controlled areas that the user can view at
any time.

Android Toast class provides a handy way to show users alerts but
problem is that these alerts are not persistent which means alert flashes
on the screen for a few seconds and then disappears.
When we tell the system to issue a notification, first it will display an icon
in notification bar like as shown below.

To see the details of our android app notification, we need to open the
notification drawer like as shown below.
Android (operating system)

Here we are going to use NotificationCompat class to implement


notification in our android application. The NotificationCompat class
supports different types of notification views, such as normal view, big
view and it provides the best support for a wide range of platforms.
Android (operating system)

Output of Android Notification Example

Android - Sending Email


Email is messages distributed by electronic means from one system
user to one or more recipients via a network.
Before starting Email Activity, You must know Email functionality with
intent, Intent is carrying data from one component to another component
with-in
in the application or outside the application.
To send an email from your application, you don’t have to implement an
email client from the beginning, but you can use an existing one like the
default Email app provided from Android, Gmail, Outlook, K K-9 Mail etc.
For this purpose, we need to write an Activity that launches an email
client, using an implicit Intent with the right action and data
data. In this
example, we are going to send an email from our app by using an Intent
object that launches existing email clients.
Following section explains different parts of our Intent object required to
send an email.
Android (operating system)

You will use ACTION_SEND action to launch an email client installed on


your Android device. Following is simple syntax to create an intent with
ACTION_SEND action.
Intent emailIntent = new Intent(Intent.ACTION_SEND);
To send an email you need to specify mailto: as URI using setData()
method and data type will be to text/plain using setType() method as
follows −
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");

Output of Android Send Email Example


Android (operating system)

Android - Sending SMS


In android, we can send SMS from our android application in two ways
either by using SMSManager API or Intents based on our requirements.

If we use SMSManager API, it will directly send SMS from our


application. In case if we use Intent with proper action (ACTION_VIEW),
it will invoke a built-in SMS app to send SMS from our application.

SmsManager API
SmsManagersmsManager = SmsManager.getDefault();
smsManager.sendTextMessage("phoneNo", null, "sms message", null,
null);
Built-in SMS application
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "default content");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
Of course, both need SEND_SMS permission.
<uses-permission android:name="android.permission.SEND_SMS" />

Android - Phone Calls


Android provides Built-in applications for phone calls, in some occasions
we may need to make a phone call through our application. This could
easily be done by using implicit Intent with appropriate actions. Also, we
can use PhoneStateListener and TelephonyManager classes, in order to
monitor the changes in some telephony states on the device.
Generally, the Intent object in android with proper action
(ACTION_CALL) and data will help us to launch a built-in phone calls
app to make a phone calls in our application.

In android, Intent is a messaging object which is used to request an


action from another app component such
as activities, services, broadcast receivers, and content providers. To
know more about an Intent object in android check this Android Intents
with Examples.
Android (operating system)

To make a phone call using Intent object in android application,


cation, we need
to write the code like as shown below.

Intent callIntent = new Intent(Intent.


Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse(
callIntent.setData(Uri.parse("tel:" + txtPhone.getText().toString()));
.getText().toString()));
startActivity(callIntent);
If you observe above code, we are
using Intent object ACTION_CALL action to make a phone call based
on our requirements.

Output of Android Phone Call Example


Example:
Android (operating system)

Android - Alert Dialog


In android, Dialog is a small window that prompt messages to the user
to make a decision or enter additional details. Generally, the Dialogs are
used with modals event and these useful to prompt users to perform a
particular action to proceed further in the application.

Following is the pictorial representation of using dialogs in android


applications.

In android, we have a different type of Dialogs available, those are

Dialog Description

AlertDialog This dialog is used to display prompt to the user with title, upto

three buttons, list of selectable items or a custom layout.

DatePickerDialog This dialog is a predefined UI control and it allows a user to

select Date.

TimePickerDialog It’s a predefined UI control and it allows a user to select Time.


Android (operating system)

Output of Android AlertDialog Example:

Android - Animations
In android, Animations are used to change the appearance and
behavior of the objects over a particular interval of time. The animations
will provide a better look and feel high
high-quality
quality user interface for our
applications.

Generally, the animations are useful when we want to notify users about
the changes happening in our app, such as new content loaded or new
actions available, etc.

We have a different type of animations available in android, here we will


discuss the most commonly used android animations such as zoom in /
zoom out, fade in / fade out
out, slide up / slide down and rotate clockwise or
anti-clockwise, etc. with examples.
Android (operating system)

In order to perform animation in android , we are goin


goingg to call a static
function loadAnimation() of the class AnimationUtils. We are going to
receive the result in an instance of Animation Object. Its syntax is as
follows −
Animationanimation=AnimationUtils
AnimationUtils.loadAnimation(getApplicationContex
getApplicationContex
t(),
R.anim.myanimation);

Output of Android Slide Up / Down Animation


Example:
When we run above program in android studio we will get the result like
as shown below.
Android (operating system)

Output of Android Fade In / Out Animations


Example:
When we run above program in android studio we will get the result like
as shown below.
Android (operating system)

Output of Android Zoom In / Out Animations


Example:
When we run the above program in android studio we will get the result
as shown below.
Android (operating system)

Output of Android Rotate Animation Example


Example:
Android (operating system)

Android Proramming Examples


Program1:
The activity_main.xml is a layout file available in res/layout directory, that is referenced by your
application when building its interface. You will modify this file very frequently to change the layout
of your application. For your "Hello World!" application, this file will have following content related
to default layout –

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
tools:context=".MainActivity"/>

</RelativeLayout>

Program2:
Consider a layout res/layout/activity_main.xml with the following definition −
?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<TextViewandroid:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView"/>

<Buttonandroid:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a Button"/>

</LinearLayout>
This application code will load this layout for an Activity, in the onCreate() method as
follows −
Android (operating system)

publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

Program3:
Consider a layout res/layout/activity_main.xml with the following definition −
<?xml version="1.0" encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<TextViewandroid:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView"/>

<Buttonandroid:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a Button"/>

</LinearLayout>
This application code will load this layout for an Activity, in the onCreate() method as
follows −
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

Program4:
Following is the content of the modified main activity file src/MainActivity.java.
packagecom.example.sairamkrishna.myapplication;

importandroid.app.ProgressDialog;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.os.Handler;
importandroid.view.View;
importandroid.widget.Button;

publicclassMainActivityextendsActivity{
Button b1;
privateProgressDialogprogressBar;
privateintprogressBarStatus=0;
Android (operating system)

privateHandlerprogressBarbHandler=newHandler();
privatelongfileSize=0;

@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button)findViewById(R.id.button);

b1.setOnClickListener(newView.OnClickListener(){
@Override
publicvoidonClick(View v){
progressBar=newProgressDialog(v.getContext());
progressBar.setCancelable(true);
progressBar.setMessage("File downloading ...");
progressBar.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.show();
progressBarStatus=0;

fileSize=0;
newThread(newRunnable(){
publicvoidrun(){
while(progressBarStatus<100){
progressBarStatus=downloadFile();

try{
Thread.sleep(1000);
}catch(InterruptedException e){
e.printStackTrace();
}

progressBarbHandler.post(newRunnable(){
publicvoidrun(){
progressBar.setProgress(progressBarStatus);
}
});
}

if(progressBarStatus>=100){
try{
Thread.sleep(2000);
}catch(InterruptedException e){
e.printStackTrace();
}
progressBar.dismiss();
}
}
}).start();
Android (operating system)

}
});
}

publicintdownloadFile(){
while(fileSize<=1000000){
fileSize++;

if(fileSize==100000){
return10;
}elseif(fileSize==200000){
return20;
}elseif(fileSize==300000){
return30;
}elseif(fileSize==400000){
return40;
}elseif(fileSize==500000){
return50;
}elseif(fileSize==700000){
return70;
}elseif(fileSize==800000){
return80;
}
}
return100;
}
}

Program5:
Following is the content of the modified MainActivity.java.
packagecom.example.sairamkrishna.myapplication;

importandroid.app.Activity;
importandroid.hardware.SensorManager;
importandroid.os.Bundle;

importandroid.util.Log;

importandroid.view.Menu;
importandroid.view.MenuItem;
importandroid.view.View;

importandroid.widget.TextView;

importjava.util.List;
importandroid.hardware.Sensor;
importandroid.hardware.SensorManager;

publicclassMainActivityextendsActivity{
Android (operating system)

TextView tv1=null;
privateSensorManagermSensorManager;
@Override

protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tv1 =(TextView)findViewById(R.id.textView2);
tv1.setVisibility(View.GONE);

mSensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);
List<Sensor>mList=mSensorManager.getSensorList(Sensor.TYPE_ALL);

for(inti=1;i<mList.size();i++){
tv1.setVisibility(View.VISIBLE);

tv1.append("\n"+mList.get(i).getName()+"\n"+mList.get(i).getVendor()+"\n"+mList.get(i).
getVersion());
}
}

@Override
publicbooleanonCreateOptionsMenu(Menu menu){
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
returntrue;
}

@Override
publicbooleanonOptionsItemSelected(MenuItem item){
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.

int id =item.getItemId();

//noinspectionSimplifiableIfStatement
if(id ==R.id.action_settings){
returntrue;
}
returnsuper.onOptionsItemSelected(item);
}
}

Program6:
Following is the content of the modified main activity
file src/com.example.helloworld/MainActivity.java. This file includes each of the
fundamental life cycle methods. The Log.d() method has been used to generate log messages

Android (operating system)

packagecom.example.helloworld;

importandroid.os.Bundle;
importandroid.app.Activity;
importandroid.util.Log;

publicclassMainActivityextendsActivity{
Stringmsg="Android : ";

/** Called when the activity is first created. */


@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(msg,"The onCreate() event");
}

/** Called when the activity is about to become visible. */


@Override
protectedvoidonStart(){
super.onStart();
Log.d(msg,"The onStart() event");
}

/** Called when the activity has become visible. */


@Override
protectedvoidonResume(){
super.onResume();
Log.d(msg,"The onResume() event");
}

/** Called when another activity is taking focus. */


@Override
protectedvoidonPause(){
super.onPause();
Log.d(msg,"The onPause() event");
}

/** Called when the activity is no longer visible. */


@Override
protectedvoidonStop(){
super.onStop();
Log.d(msg,"The onStop() event");
}

/** Called just before the activity is destroyed. */


@Override
publicvoidonDestroy(){
super.onDestroy();
Log.d(msg,"The onDestroy() event");
Android (operating system)

}
}

Program7:The below example demonstrates the use of TextureView class. It crates a


basic application that allows you to view camera inside a texture view and change its angle ,
orientation e.t.c.
Here is the content of src/com.example.textureview/MainActivity.java.
packagecom.example.textureview;

importjava.io.IOException;

importandroid.annotation.SuppressLint;
importandroid.app.Activity;
importandroid.graphics.SurfaceTexture;
importandroid.hardware.Camera;
importandroid.os.Bundle;

importandroid.view.Gravity;
importandroid.view.Menu;
importandroid.view.TextureView;
importandroid.view.TextureView.SurfaceTextureListener;
importandroid.view.View;
importandroid.widget.FrameLayout;

publicclassMainActivityextendsActivityimplementsSurfaceTextureListener{
privateTextureViewmyTexture;
privateCameramCamera;

@SuppressLint("NewApi")
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

myTexture=newTextureView(this);
myTexture.setSurfaceTextureListener(this);
setContentView(myTexture);
}

@Override
publicbooleanonCreateOptionsMenu(Menu menu){
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
returntrue;
}

@SuppressLint("NewApi")
@Override
publicvoidonSurfaceTextureAvailable(SurfaceTexture arg0,int arg1,int arg2){
Android (operating system)

mCamera=Camera.open();
Camera.SizepreviewSize=mCamera.getParameters().getPreviewSize();

myTexture.setLayoutParams(newFrameLayout.LayoutParams(
previewSize.width,previewSize.height,Gravity.CENTER));

try{
mCamera.setPreviewTexture(arg0);
}catch(IOException t){
}

mCamera.startPreview();
myTexture.setAlpha(1.0f);
myTexture.setRotation(90.0f);
}

@Override
publicbooleanonSurfaceTextureDestroyed(SurfaceTexture arg0){
mCamera.stopPreview();
mCamera.release();
returntrue;
}

@Override
publicvoidonSurfaceTextureSizeChanged(SurfaceTexture arg0,int arg1,
int arg2){
// TODO Auto-generated method stub
}

@Override
publicvoidonSurfaceTextureUpdated(SurfaceTexture arg0){
// TODO Auto-generated method stub
}
}
Here is the content of activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<TextureView
android:id="@+id/textureView1"
android:layout_width="wrap_content"
Android (operating system)

android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
Here is the default content of AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.textureview">

<uses-permissionandroid:name="android.permission.CAMERA"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">

<activity
android:name="com.example.textureview.MainActivity"
android:label="@string/app_name">

<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>

</activity>

</application>
</manifest>

Program8:
The below example is a complete example of connecting your android application with
MYSQL database via PHP page. It creates a basic application that allows you to login using
GET and POST method.
PHP - MYSQL part
In this example a database with the name of temp has been created at 000webhost.com. In
that database, a table has been created with the name of table1. This table has three fields.
(Username, Password, Role). The table has only one record which is
("admin","admin","administrator").
<?php
$con=mysqli_connect("mysql10.000webhost.com","username","password","db_name");

if(mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: ".mysqli_connect_error();
}
Android (operating system)

$username = $_POST['username'];
$password = $_POST['password'];
$result =mysqli_query($con,"SELECT Role FROM table1 where
Username='$username' and Password='$password'");
$row =mysqli_fetch_array($result);
$data = $row[0];

if($data){
echo $data;
}

mysqli_close($con);
?>

Program9:Here is an example demonstrating the use of SensorManager class. It


creates a basic application that allows you to view the list of sensors on your device.
Following is the content of the modified MainActivity.java.
packagecom.example.sairamkrishna.myapplication;

importandroid.app.Activity;
importandroid.hardware.SensorManager;
importandroid.os.Bundle;

importandroid.util.Log;

importandroid.view.Menu;
importandroid.view.MenuItem;
importandroid.view.View;

importandroid.widget.TextView;

importjava.util.List;
importandroid.hardware.Sensor;
importandroid.hardware.SensorManager;

publicclassMainActivityextendsActivity{
TextView tv1=null;
privateSensorManagermSensorManager;
@Override

protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tv1 =(TextView)findViewById(R.id.textView2);
tv1.setVisibility(View.GONE);

mSensorManager=(SensorManager)getSystemService(SENSOR_SERVICE);
Android (operating system)

List<Sensor>mList=mSensorManager.getSensorList(Sensor.TYPE_ALL);

for(inti=1;i<mList.size();i++){
tv1.setVisibility(View.VISIBLE);

tv1.append("\n"+mList.get(i).getName()+"\n"+mList.get(i).getVendor()+"\n"+mList.get(i).
getVersion());
}
}

@Override
publicbooleanonCreateOptionsMenu(Menu menu){
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
returntrue;
}

@Override
publicbooleanonOptionsItemSelected(MenuItem item){
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.

int id =item.getItemId();

//noinspectionSimplifiableIfStatement
if(id ==R.id.action_settings){
returntrue;
}
returnsuper.onOptionsItemSelected(item);
}
}
Following is the modified content of the xml activity_main.xml.
In the below code abc indicates about the logo of tutorialspoint.com

<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"
android:layout_height="match_parent"android:paddingLeft="@dimen/activity_horizontal_
margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:transitionGroup="true">

<TextViewandroid:text="Sensor "android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview"
android:textSize="35dp"
android:layout_alignParentTop="true"
Android (operating system)

android:layout_centerHorizontal="true"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tutorials point"
android:id="@+id/textView"
android:layout_below="@+id/textview"
android:layout_centerHorizontal="true"
android:textColor="#ff7aff24"
android:textSize="35dp"/>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/abc"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:theme="@style/Base.TextAppearance.AppCompat"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView2"
android:layout_below="@+id/imageView"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>

</RelativeLayout>
Following is the content of the res/values/string.xml.
<resources>
<stringname="app_name">My Application</string>
<stringname="hello_world">Hello world!</string>
<stringname="action_settings">Settings</string>
</resources>
Following is the content of AndroidManifest.xml file.
<?xml version="1.0" encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sairamkrishna.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Android (operating system)

android:theme="@style/AppTheme">

<activity
android:name=".MainActivity"
android:label="@string/app_name">

<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>

</activity>

</application>
</manifest>

Program10:
Here is an example demonstrating the use of GoogleMap class. It creates a basic M
application that allows you to navigate through the map.
To experiment with this example , you can run this on an actual device or in an emulator.
Create a project with google maps activity as shown b

Here is the content of activity_main.xml.


<fragmentxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.tutorialspoint7.myapplication.MapsActivity"/>
Here is the content of MapActivity.java.
In the below code we have given sample latitude and longitude details

package com.example.tutorialspoint7.myapplication;

import android.support.v4.app.FragmentActivity;
importandroid.os.Bundle;

importcom.google.android.gms.maps.CameraUpdateFactory;
importcom.google.android.gms.maps.GoogleMap;
importcom.google.android.gms.maps.OnMapReadyCallback;
importcom.google.android.gms.maps.SupportMapFragment;
importcom.google.android.gms.maps.model.LatLng;
Android (operating system)

importcom.google.android.gms.maps.model.MarkerOptions;

publicclassMapsActivityextendsFragmentActivityimplementsOnMapReadyCallback{

privateGoogleMapmMap;

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

/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera.
* In this case, we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device.
* This method will only be triggered once the user has installed
Google Play services and returned to the app.
*/

@Override
publicvoidonMapReady(GoogleMapgoogleMap){
mMap=googleMap;
// Add a marker in Sydney and move the camera
LatLngTutorialsPoint=newLatLng(21,57);
mMap.addMarker(new
MarkerOptions().position(TutorialsPoint).title("Tutorialspoint.com"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(TutorialsPoint));
}
}
Following is the content of AndroidManifest.xml file.
<?xml version="1.0" encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tutorialspoint7.myapplication">

<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->

<uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION"/>
Android (operating system)

<uses-permissionandroid:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permissionandroid:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key
that is used to sign the APK for publishing.
You can define the keys for the debug and
release targets in src/debug/ and src/release/.
-->

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyAXhBdyKxUo_cb-EkSgWJQTdqR0QjLcqes"/>

<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>

You might also like