Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 101

Activity and Multimedia with Databases

INTENT

 An intent is an abstract description of an operation to be performed.


 An Intent is a messaging object you can use to request an action from
another app component via the Android system.
  Intents allow you to interact with components from the same
applications as well as with components contributed by other
applications.
  It is mostly used to start activity, send broadcast receiver,start services
and send message between two activities.

APP
ORIGINATOR
COMPONENT

INTENT ACTION
ANDROID
SYSTEM
USES OF INTENT IN ADNROID

1.Starting an activity:
 An Activity represents a single screen in an app.
 You can start a new instance of an Activity by passing
an Intent to startActivity().
 The Intent describes the activity to start and carries any
necessary data.
 For example, if you are having two activities
namely LoginActivity and MainActivity then, you can start
the MainActivity by clicking the login button present on
the LoginActivity.
 By using the startActivity(), you can start the desired
Activity using the Intents.
2. Starting a Service
 A Service is a component that performs
operations in the background without a user
interface.
 You can start a service to perform a one-time
operation (such as downloading a file) by
passing an Intent to startService().
 The Intent describes the service to start and
carries any necessary data.
3.Delivering a broadcast
 A broadcast is a message that is received by
the application from the system. 
 The system delivers various broadcasts for
system events, such as when the system
boots up or the device starts charging.
 You can deliver a broadcast to other apps by
passing an Intent to sendBroadcast() or 
sendOrderedBroadcast().
Intent Types

 There are two types of intents:

 Explicit intents specify which application will satisfy


the intent, by supplying either the target app's package
name or a fully-qualified component class name. You'll
typically use an explicit intent to start a component in
your own app, because you know the class name of the
activity or service you want to start. For example, you
might start a new activity within your app in response
to a user action, or start a service to download a file in
the background.
 Implicit intents do not name a specific
component, but instead declare a general
action to perform, which allows a component
from another app to handle it. For example, if
you want to show the user a location on a
map, you can use an implicit intent to request
that another capable app show a specified
location on a map.
 Figure 1 shows how an intent is used when starting an activity.
 When the Intent object names a specific activity component explicitly, the
system immediately starts that component.
 When you use an implicit intent, the Android system finds the appropriate
component to start by comparing the contents of the intent to the intent
filters declared in the manifest file of other apps on the device.
 If the intent matches an intent filter, the system starts that component and
delivers it the Intent object.
 If multiple intent filters are compatible, the system displays a dialog so the
user can pick which app to use.
 An intent filter is an expression in an app's manifest file that specifies the
type of intents that the component would like to receive.
 For instance, by declaring an intent filter for an activity, you make it possible
for other apps to directly start your activity with a certain kind of intent.
 Likewise, if you do not declare any intent filters for an activity, then it can be
started only with an explicit intent.


Activity Lifecycle

 Whenever you open an Android application, then you see some UI


over your screen. That screen is called an Activity. It is the basic
component of Android and whenever you are opening an application,
then you are opening some activity.

 For example, when you open your Gmail application, then you see
your emails on your screen. Those emails are present in an Activity. If
you open some particular email, then that email will be opened in
some other Activity.

 An Android activity undergoes through a number of states during its whole


lifecycle, from when it is created until it is destroyed.

 An activity lifecycle shows all the states with transitioning from one
state to the next state
The Activity lifecycle consists of 7
methods:
 onCreate() : It is called when an activity is first created. When
a user opens the app then some Activity is created. You have
to implement this method in every activity because, inside
this method, all the necessary components of your activity
will be initialized. Here the initialization of your application's
UI is done.
 onStart(): This method is called when an activity becomes
visible to the user. When all the initialization is done by
the onCreate() method, then this method is called.
 onResume(): It is called just before the user starts interacting
with the application. Most of the core functionalities of the
app are implemented in this method.
 onPause():  It is called when the activity is paused i.e. it is mostly
called when you press the back or home button of your Android
device. It is an indication that the user is leaving the activity and
starting some other activity.
 onStop(): It is called when the activity is no longer visible to the user.
If you are starting a new activity, or some existing activity is entering
into onResume() state, then the current activity will not be visible to
the user and is stopped.
 onRestart(): It is called when the activity in the stopped state is about
to start again. By doing so, the state of the activity from the time it
was stopped will be restored.
 onDestroy(): It is  called when the activity is totally destroyed i.e.
when you clear the application stack then onDestroy() will be called
and all the states of the activity will be destroyed.
Broadcast Lifecycle
Broadcast intents

 The intents you've seen up to now always resulted in an activity being


launched, either a specific activity from your application or an activity
from a different application that could fulfill the requested action.
 But sometimes an intent doesn't have a specific recipient, and
sometimes you don't want an activity to be launched in response to an
intent.
 For example, when your app receives a system intent indicating that
the network state of a device has changed, you probably don't want to
launch an activity, but you may want to disable some functionality of
your app.
 For this reason there's a third type of intent that can be delivered to any
interested application: the broadcast intent. Although broadcast intents
are defined the same way as implicit intents, each type of intent has
important distinguishing characteristics:
 Broadcast intents are delivered using sendBroadcast() or a related
method, while other types of intents use startActivity() to start
activities. When you broadcast an intent, you never find or start an
activity. Likewise, there's no way for a broadcast receiver to see or
capture intents used with startActivity().
 A broadcast intent is a background operation that the user is not
normally aware of. Starting an activity with an intent, on the other
hand, is a foreground operation that modifies what the user is
currently interacting with.
 There are two types of broadcast intents, those delivered by the
system (system broadcast intents), and those that your app
delivers (custom broadcast intents).
System broadcast intents

 The system delivers a system broadcast intent when a system event


occurs that might interest your app. For example:
 When the device boots, the system sends an 
ACTION_BOOT_COMPLETED system broadcast intent. This intent
contains the constant value "android.intent.action.BOOT_COMPLETED".
 When the device is connected to external power, the system sends 
ACTION_POWER_CONNECTED, which contains the constant
value "android.intent.action.ACTION_POWER_CONNECTED". When the
device is disconnected from external power, the system sends 
ACTION_POWER_DISCONNECTED.
 When the device is low on memory, the system sends 
ACTION_DEVICE_STORAGE_LOW. This intent contains the constant
value "android.intent.action.DEVICE_STORAGE_LOW".
 To receive system broadcast intents, you need to create a 
broadcast receiver.
Custom broadcast intents

 Custom broadcast intents are broadcast intents that your application sends out.
Use a custom broadcast intent when you want your app to take an action
without launching an activity, for example when you want to let other apps know
that data has been downloaded to the device and is available for them to use.

 To create a custom broadcast intent, create a custom intent action. To deliver a


custom broadcast to other apps, pass the intent
to sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().

 For example, the following method creates an intent and broadcasts it to all
interested broadcast receivers:

 public void sendBroadcastIntent() { Intent intent = new Intent();


intent.setAction("com.example.myproject.ACTION_SHOW_TOAST");
sendBroadcast(intent); }
Broadcast receivers

 Broadcast intents aren't targeted at specific recipients. Instead,


interested apps register a component to "listen" for these kind of
intents. This listening component is called a broadcast receiver.
 Use broadcast receivers to respond to messages that are broadcast
from other apps or from the system. To create a broadcast receiver:
 Define a subclass of the BroadcastReceiver class and implement
the onReceive() method.
 Register the broadcast receiver either dynamically in Java, or
statically in your app's manifest file.
 As part of this step, use an intent filter to specify which kinds of
broadcast intents you're interested in receiving.
 These steps are described below.
Define a subclass of BroadcastReceiver

 To create a broadcast receiver, define a subclass


of the BroadcastReceiver class. This subclass is
where intents are delivered (if they match the
intent filters you set when you register the
subclass, which happens in a later step).
 Within your subclass definition:
 Implement the required onReceive() method.
 Include any other logic that your broadcast
receiver needs.
 A broadcast receiver is a dormant component(not active but has a ability to be
active at a later time) of the Android system. Only an Intent (for which it is
registered) can bring it into action. The Broadcast Receiver’s job is to pass a
notification to the user, in case a specific event occurs.
 Using a Broadcast Receiver, applications can register for a particular event. Once
the event occurs, the system will notify all the registered applications.

 For instance, a Broadcast receiver triggers battery Low notification that you see
on your mobile screen.
 Other instances caused by a Broadcast Receiver are new friend notifications,
new friend feeds, new message etc. on your Facebook app.
 In fact, you see broadcast receivers at work all the time. Notifications
like incoming messages, WiFi Activated/Deactivated message etc. are all real-
time announcements of what is happening in the Android system and the
applications.
Content provider

 The Android framework uses a concept called content providers to


enable applications to share and use data across the platform.
 A content provider is an owner of particular content, it provides
well defined APIs to read, insert, update and delete that data.
 The content provider can internally use any place to store its data
like a local file, local database or some remote service.
 A content provider component supplies data from one application
to others on request.
 Such requests are handled by the methods of the ContentResolver
class.
 A content provider can use different ways to store its data and the
data can be stored in a database, in files, or even over a network.
 Content Providers support the four basic
operations, normally called CRUD-operations.
  CRUD is the acronym
for create, read, update and delete.
 With content providers those objects simply
represent data as most often a record of a
database — but they could also be a photo on
your SD-card or a video on the web.
Content URIs

 To query a content provider, you specify the


query string in the form of a URI which has
following format

 <prefix>://<authority>/<data_type>/<id>
Create Content Provider

 This involves number of simple steps to create your own content provider.
 First of all you need to create a Content Provider class that extends
the ContentProviderbaseclass.
 Second, you need to define your content provider URI address which will
be used to access the content.
 Next you will need to create your own database to keep the content.
Usually, Android uses SQLite database and framework needs to
override onCreate() method which will use SQLite Open Helper method to
create or open the provider's database.
 When your application is launched, the onCreate() handler of each of its
Content Providers is called on the main application thread.
 Next you will have to implement Content Provider queries to perform
different database specific operations.
 Finally register your Content Provider in your activity file using <provider>
tag.
Methods of content provider
 onCreate() This method is called when the provider is
started.
 query() This method receives a request from a client. The
result is returned as a Cursor object.
 insert()This method inserts a new record into the content
provider.
 delete() This method deletes an existing record from the
content provider.
 update() This method updates an existing record from the
content provider.
 getType() This method returns the MIME type of the data at
the given URI.
Fragments

 Android Fragment is the part of activity, it is also known as sub-activity.

 There can be more than one fragment in an activity.

 Fragments represent multiple screen inside one activity.

 Android fragment lifecycle is affected by activity lifecycle because


fragments are included in activity.

 Each fragment has its own life cycle methods that is affected by activity
life cycle because fragments are embedded in activity.

 The FragmentManager class is responsible to make interaction between


fragment objects.
 A fragment has its own layout and its own behaviour with
its own life cycle callbacks.
 You can add or remove fragments in an activity while the
activity is running.
 You can combine multiple fragments in a single activity to
build a multi-pane UI.
 A fragment can be used in multiple activities.
 Fragment life cycle is closely related to the life cycle of its
host activity which means when the activity is paused, all
the fragments available in the activity will also be stopped.
 A fragment can implement a behaviour that has no user
interface component.
 Fragments were added to the Android API in Honeycomb
version of Android which API version 11.
Following is a typical example of how two UI modules defined by fragments can be combined
into one activity for a tablet design, but separated for a handset design.

The application can embed two fragments in Activity A, when running on a tablet-sized
device. However, on a handset-sized screen, there's not enough room for both fragments,
so Activity A includes only the fragment for the list of articles, and when the user selects an
article, it starts Activity B, which includes the second fragment to read the article.
Fragment Life Cycle

 Android fragments have their own life cycle very similar to an android
activity. This section briefs different stages of its life cycle.
How to use Fragments

 First of all decide how many fragments you want to use in an


activity. For example let's we want to use two fragments to
handle landscape and portrait modes of the device.
 Next based on number of fragments, create classes which will
extend the Fragment class. The Fragment class has above
mentioned callback functions. You can override any of the
functions based on your requirements.
 Corresponding to each fragment, you will need to create
layout files in XML file. These files will have layout for the
defined fragments.
 Finally modify activity file to define the actual logic of
replacing fragments based on your requirement.
Types of Fragments

 Basically fragments are divided as three stages as


shown below.
 Single frame fragments − Single frame fragments
are using for hand hold devices like mobiles, here
we can show only one fragment as a view.
 List fragments − fragments having special list view
is called as list fragment
 Fragments transaction − Using with fragment
transaction. we can move one fragment to
another fragment
Services

 Android service is a component that runs in the


background in order to perform long-running
operations without interacting with the user and it
works even if the application is destroyed.
  Another application component can start a service
and it continues to run in the background even if
you switch to another application.
 A service can essentially take two states −
Features of services
 Android services interface interprets real world actions,
like swiping, tapping, pinching, and reverse pinching to
work on the objects appearing on the mobile screen with
the help of virtual keyboard
 Android services allow immediate hepatic feedback to
the user
 Internal hardware application have been build to adjust
and manipulate the screen according the need of the
user.
 For example , while watching a video or playing game
you can enable the rotate screen feature, i.e. on the
landscape mode
Android Platform Service

 The Androidplatform provides and runs


predefined system services

 Every Android application can use them,


given the right permission

 Theseservices can be accessed by


getSystemServices() method
Defining new service

 Following steps are implement new service


1. Declare the service in the manifest file
2. Create implementation code,
a. Started service
b. IntentService
c. Bound Services
Android Service-LifeCycle

 A service has life cycle call-back methods that


you can implement to monitor changes in the
service's state and you can perform work at the
appropriate stage.
 The following diagram on the left shows the life
cycle when the service is created with
startService()
 and the diagram on the right shows the life cycle
when the service is created with bindService()
 To create an service, you create a Java class
that extends the Service base class or one of
its existing subclasses.
 The Service base class defines various
callback methods and the most important are
given below. 
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.
 The name of a permission that an entity must have in
order to launch the service or bind to it.
 If a caller of startService(), bindService(), or stopService
(), has not been granted this permission, the method will
not work and the Intent object will not be delivered to the
service.
 If this attribute is not set, the permission set by the 
<application> element's permission attribute applies to
the service.
 If neither attribute is set, the service is not protected by
a permission.
Android System - Architecture
Linux kernel

 At the bottom of the layers is Linux –


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

 On top of Linux kernel there is a set of


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

 This category encompasses those Java-based libraries that are


specific to Android development.
 Examples of libraries in this category include the application
framework libraries in addition to those that facilitate user interface
building, graphics drawing and database access.
 A summary of some key core Android libraries available to the
Android developer is as follows −
 android.app − Provides access to the application model and is the
cornerstone of all Android applications.

 android.content − Facilitates content access, publishing and


messaging between applications and application components.

 android.database − Used to access data published by content


providers and includes SQLite database management classes.
 android.opengl − A Java interface to the OpenGL ES 3D graphics
rendering API.

 android.os − Provides applications with access to standard operating


system services including messages, system services and inter-process
communication.

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

 android.view − The fundamental building blocks of application user


interfaces.

 android.widget − A rich collection of pre-built user interface components


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

 android.webkit − A set of classes intended to allow web-browsing


capabilities to be built into applications.
Architecture

 Media applications interact with the Android


native multimedia framework according to
the following architecture.
1.Application Framework:
At the application framework level is application code that utilizes 
android.media APIs(Application Programming Interface) to interact with
the multimedia hardware.
2.Binder IPC
The Binder IPC proxies facilitate communication over process boundaries.
They are located in the frameworks/av/media/libmedia directory and
begin with the letter "I".
3.Native Multimedia Framework
At the native level, Android provides a multimedia framework that utilizes
the Stagefright engine for audio and video recording and playback.
Stagefright comes with a default list of supported software codecs and
you can implement your own hardware codec by using the OpenMax
integration layer standard
4.OpenMAX Integration Layer (IL)
The OpenMAX IL provides a standardized way for
Stagefright to recognize and use custom hardware-
based multimedia codecs called components.
You must provide an OpenMAX plugin in the form of
a shared library named  libstagefrighthw.so. This
plugin links Stagefright with your custom codec
components, which must be implemented
according to the OpenMAX IL component standard.
Play Audio and Video

 The Android multimedia framework includes


support for playing variety of common media
types, so that you can easily integrate audio,
video and images into your applications.
Play Audio

 The following classes are used to play sound


and video in the Android framework:
 MediaPlayer
This class is the primary API for playing sound
and video.
 AudioManager
This class manages audio sources and audio output
on a device.
Manifest declarations

 Before starting development on your application using MediaPlayer,


make sure your manifest has the appropriate declarations to allow use of
related features.
 Internet Permission - If you are using MediaPlayer to stream network-
based content, your application must request network access.<uses-
permission android:name="android.permission.INTERNET" />

 Wake Lock Permission - If your player application needs to keep the


screen from dimming or the processor from sleeping, or uses the 
MediaPlayer.setScreenOnWhilePlaying() or MediaPlayer.setWakeMode()
 methods, you must request this permission.<uses-permission
android:name="android.permission.WAKE_LOCK" />
Basic MediaPlayer tasks

 Load a media file for playback. This is done with the


methods setDataSource(), prepare(), and prepareAsync
().
 Start playback / Play audio. This is handled by start().
 Pause playback (once playback has started). This is
handled by pause().
 Stop playback and reset the MediaPlayer, so that you
can load another media file into it. This is handled by 
reset().
 Find the length of a song (in ms). This is handled by 
getDuration().
 Find what part of the song is playing. This is handled by 
getCurrentPosition().
 Jump to a specific time position (in ms) in the song and
play from there. This is handled by seekTo(position).
 Check to see if audio is being played back right now. This is
handled by isPlaying().
 Find out when a song is done playing. This is handled by
attaching a MediaPlayer.OnCompletionListener. Your code
will get an onCompletion() callback from the listener.
 Deallocate resources used by the player. This is handled by 
release(), which releases all the resources attached to the
player. After being released the player is no longer usable.
Text To Speech

 Android allows you convert your text into voice.


 Not only you can convert it but it also allows you to speak text in variety of
different languages.
  TTS is a simple but powerful feature.
 It can also be effectively used in mobile APPs dedicated to visually impaired
people or in educational app for kids or can be used in pronunciation learning
app, etc.
 These are some of the ways you can use TTS.
 Using TextToSpeech enhances interaction between the user and the mobile
application.
Sensors

 Most Android-powered devices have built-in


sensors that measure motion, orientation,
and various environmental conditions.
 These sensors are capable of providing raw
data with high precision and accuracy, and
are useful if you want to monitor three-
dimensional device movement or positioning,
or you want to monitor changes in the
ambient environment near a device.
The Android platform supports three broad
categories of sensors:

 Motion sensors:-
These sensors measure acceleration forces and rotational
forces along three axes. This category includes accelerometers,
gravity sensors, gyroscopes, and rotational vector sensors.
 Environmental sensors:-
These sensors measure various environmental parameters,
such as medium air temperature and pressure, illumination,
and humidity. This category includes barometers, photometers,
and thermometers.
 Position sensors:-
These sensors measure the physical position of a device. This
category includes orientation sensors and magnetometers.
Sensor Framework

 You can access these sensors and acquire raw sensor data by using the Android sensor framework.
 The sensor framework is part of the android.hardware package and includes the following classes and
interfaces:

 SensorManagerYou can use this class to create an instance of the sensor service. This class provides
various methods for accessing and listing sensors, registering and unregistering sensor event
listeners, and acquiring orientation information. This class also provides several sensor constants that
are used to report sensor accuracy, set data acquisition rates, and calibrate sensors.

 SensorYou can use this class to create an instance of a specific sensor. This class provides various
methods that let you determine a sensor's capabilities.

 SensorEventThe system uses this class to create a sensor event object, which provides information
about a sensor event. A sensor event object includes the following information: the raw sensor data,
the type of sensor that generated the event, the accuracy of the data, and the timestamp for the
event.

 SensorEventListenerYou can use this interface to create two callback methods that receive
notifications (sensor events) when sensor values change or when sensor accuracy changes.
AsyncTask

 Android AsyncTask is an abstract class provided by Android


which gives us the liberty to perform heavy tasks in the
background and keep the UI thread light thus making the
application more responsive.
 Android application runs on a single thread when launched.
 Due to this single thread model tasks that take longer time to
fetch the response can make the application non-responsive.
 To avoid this we use android AsyncTask to perform the heavy
tasks in background on a dedicated thread and passing the
results back to the UI thread.
 Hence use of AsyncTask in android application keeps the UI
thread responsive at all times.
The basic methods used in an android
AsyncTask class are defined below :
 doInBackground() : This method contains the code which needs to be
executed in background. In this method we can send results multiple
times to the UI thread by publishProgress() method. To notify that the
background processing has been completed we just need to use the
return statements
 onPreExecute() : This method contains the code which is executed
before the background processing starts
 onPostExecute() : This method is called after doInBackground method
completes processing. Result from doInBackground is passed to this
method
 onProgressUpdate() : This method receives progress updates from
doInBackground method, which is published via publishProgress
method, and this method can use this progress update to update the UI
thread
The three generic types used in an android AsyncTask
class are given below :

 Params : The type of the parameters sent to


the task upon execution
 Progress : The type of the progress units
published during the background
computation
 Result : The type of the result of the
background computation
Audio Capture

 The Android multimedia framework includes


support for capturing and encoding a variety
of common audio formats, so that you can
easily integrate audio into your applications.
You can record audio using the 
MediaRecorder APIs if supported by the
device hardware.
Performing Audio Capture

Audio capture from the device is a bit more complicated than audio and
video playback, but still fairly simple:

1. Create a new instance of android.media.MediaRecorder.


2. Set the audio source using MediaRecorder.setAudioSource(). You will
probably want to use MediaRecorder.AudioSource.MIC.
3. Set output file format using MediaRecorder.setOutputFormat().
4. Set output file name using MediaRecorder.setOutputFile().
5. Set the audio encoder using MediaRecorder.setAudioEncoder().
6. Call MediaRecorder.prepare() on the MediaRecorder instance.
7. To start audio capture, call MediaRecorder.start().
8. To stop audio capture, call MediaRecorder.stop().
9. When you are done with the MediaRecorder instance, call 
MediaRecorder.release() on it. Calling MediaRecorder.release() is always
recommended to free the resource immediately.
Camera

 There are two ways to integrate the camera


module
1. Using In-built camera App:
2. Writing Custom Camera App
Basic for Camera

 The Android framework supports capturing


images and video through
the android.hardware.camera2 API or
camera Intent.
 Here are the relevant classes:
 android.hardware.camera2:
This package is the primary API for controlling device cameras. It can
be used to take pictures or videos when you are building a camera
application.
 Camera:
This class is the older deprecated API for controlling device cameras.
 SurfaceView:
This class is used to present a live camera preview to the user.
 MediaRecorder
This class is used to record video from the camera.
 Intent
An intent action type of MediaStore.ACTION_IMAGE_CAPTURE
 or MediaStore.ACTION_VIDEO_CAPTURE can be used to capture images or
videos without directly using the Camera object.
Manifest declarations

 Before starting development on your application


with the Camera API, you should make sure your
manifest has the appropriate declarations to
allow use of camera hardware and other related
features.
1.Camera Permission -
Your application must request permission to use
a device camera.
<uses-permission
android:name="android.permission.CAMERA" />
2.Camera Features - Your application must also declare use of camera
features, for example:<uses-feature
android:name="android.hardware.camera" />

 Adding camera features to your manifest causes Google Play to


prevent your application from being installed to devices that do not
include a camera or do not support the camera features you specify..
 If your application can use a camera or camera feature for proper
operation, but does not require it, you should specify this in the
manifest by including the android:required attribute, and setting it
to false:
 <uses-feature android:name="android.hardware.camera"
android:required="false" />
3.Storage Permission - If your application saves images or
videos to the device's external storage (SD Card), you
must also specify this in the manifest.<uses-permission
android:name="android.permission.WRITE_EXTERNAL_
STORAGE" />

4.Audio Recording Permission - For recording audio with


video capture, your application must request the audio
capture permission.<uses-permission
android:name="android.permission.RECORD_AUDIO" />
5.Location Permission - If your application tags
images with GPS location information, you must
request
the ACCESS_FINE_LOCATION permission. Note
that, if your app targets Android 5.0 (API level 21)
or higher, you also need to declare that your app
uses the device's GPS:
 <uses-permission
android:name="android.permission.ACCESS_FIN
E_LOCATION" />
Bluetooth

 Bluetooth is a way to send or receive data between two different devices.


 Android platform includes support for the Bluetooth framework that allows a
device to wirelessly exchange data with other Bluetooth devices.
 The application framework provides access to the Bluetooth functionality
through the Android Bluetooth APIs. These APIs let applications wirelessly
connect to other Bluetooth devices, enabling point-to-point and multipoint
wireless features.
 Using the Bluetooth APIs, an Android application can perform the following:
 Scan for other Bluetooth devices
 Query the local Bluetooth adapter for paired Bluetooth devices
 Establish RFCOMM channels
 Connect to other devices through service discovery
 Transfer data to and from other devices
 Manage multiple connections
The basics

 In order for Bluetooth-enabled devices to transmit data between each other,


they must first form a channel of communication using a pairing process.
 One device, a discoverable device, makes itself available for incoming
connection requests.
 Another device finds the discoverable device using a service discovery process.
 After the discoverable device accepts the pairing request, the two devices
complete a bonding process where they exchange security keys. The devices
cache these keys for later use.
 After the pairing and bonding processes are complete, the two devices
exchange information.
 When the session is complete, the device that initiated the pairing request
releases the channel that had linked it to the discoverable device.
 The two devices remain bonded, however, so they can reconnect
automatically during a future session as long as they're in range of each other
and neither device has removed the bond.
Bluetooth permissions

 In order to use Bluetooth features in your application, you


must declare two permissions. The first of these is 
BLUETOOTH. You need this permission to perform any
Bluetooth communication, such as requesting a connection,
accepting a connection, and transferring data.
 The other permission that you must declare is 
ACCESS_FINE_LOCATION. Your app needs this permission
because a Bluetooth scan can be used to gather information
about the location of the user. This information may come
from the user's own devices, as well as Bluetooth beacons in
use at locations such as shops and transit facilities.
Animations

 Animation is the process of creating motion


and shape change.
 Animations notify users about what’s going
on in your app and improve the mental model
of your app’s interface.
 Animation in android is possible from many
ways.
 Android Defines Three Types Of Animations:
1. View Animation:
 This is the simplest animation used in Android.
 It define the properties of our Views that should be animated using a
technique called Tween Animation.
 It take the following parameters i.e. size, time duration , rotation angle,
start value , end value, and perform the required animation on that object.
 You can  execute the animation by specifying transformations on your
View.
 This can be done in XML resource files or programmatically.
 Android View animation can make animation on any View objects, such as
ImageView, TextView or Button objects.
 View animation can only animate simple properties like position, size,
rotation, and the alpha property that allows you animate the transparency
of a View.
 The drawback of this mechanism is that it can only be applied to Views.
Property Animation:
 This animation was introduced in Android 3.0 (API level 11).
 It allows the user to animate anything.
 Property animations are highly customizable, you can specify the duration, the
number of repeats, the type of interpolation, and the frame rate of the animation.
 The Property Animation system is always preferred for more complex animations.
 Property animations allow us to animate any property of any object from one value to
another over a specified duration.
 Let us take an example, imagine you wanted to animate the 3d rotation using the
rotationX or rotationY properties that were introduced in API 11.
 Or maybe you want to animate a color change or animate the change of a drawable.
 This is not possible by using View Animations.
 For this purpose Property Animation is used .
 You are not limited by predefined animation types or by the type of object that you
want to animate.
 At first the usage of the Property Animation System might seem a little complicated.
 However, in most cases you can use the very versatile ObjectAnimator that uses
reflection.
 The ObjectAnimator makes creating Property Animations almost as easy as creating
View Animations.
 Common properties commonly animated on
views include:
Drawable Animation:
 This animation allows the user to load drawable resources and
display them one frame after another.
 This method of animation is useful when user wants to animate
things that are easier to represent with Drawable resources.
 To use Animations in Android , Android has provided us a class
called Animation.
 The Animation class has many methods given below:
 1.start(): This method will start the animation.
 2.setDuration(long duration): This method sets the duration of an
animation.
 3.getDuration(): This method gets the duration.
 4.end(): This method ends the animation.
 5.cancel(): This method cancels the animation.
SQLiteDatabase

 Android SQLite is a very lightweight database which


comes with Android OS.
 Android SQLite combines a clean SQL interface
with a very small memory footprint and decent
speed.
 For Android, SQLite is “baked into” the Android
runtime, so every Android application can create its
own SQLite databases.
 QLite is a typical relational database, containing
tables (which consists of rows and columns), indexes
etc.
 The Android SQLite Database requires very little memory (around 250kb), which is
available on all android devices.
 Every device has an inbuilt support for SQLite database, which is automatically
managed on android right from its creation, execution to querying up process.
 SQLite is an open source database, available on every android database.
 It supports standard relations database features, like SQL syntax, transactions & SQL
statements. 
 SQLite is considerably, the lighter version of SQL database, where most of the SQL
commands don’t run on SQLite database. Once SQLite is in place, it is important to
ensure that a feature or command is available in SQLite; only then can it be executed.

 The Basic Advantages of SQLite:

 It’s a light weight database


 Requires very little memory
 An Automatically managed database
 SQLite supports the following data types:
 TEXT(similar to String in Java)
 INTEGER(similar to long in Java)
 REAL (similar to double in Java)
Creating And Updating Database In Android

 For creating, updating and other operations you need to create


a subclass or SQLiteOpenHelper class.
 SQLiteOpenHelper is a helper class to manage database
creation and version management.
 It provides two methods onCreate(SQLiteDatabase db),
onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion).
 The SQLiteOpenHelper is responsible for opening database if
exist, creating database if it does not exists and upgrading if
required.
 The SQLiteOpenHelper only require the DATABASE_NAME to
create database.
 After extending SQLiteOpenHelper you will need to implement
its methods onCreate, onUpgrade and constructor.
 onCreate(SQLiteDatabase sqLiteDatabase) method is called
only once throughout the application lifecycle. It will be called
whenever there is a first call to getReadableDatabase() or
getWritableDatabase() function available in super
SQLiteOpenHelper class. So SQLiteOpenHelper class call the
onCreate() method after creating database and instantiate
SQLiteDatabase object. Database name is passed in constructor
call.

 onUpgrade(SQLiteDatabase db,int oldVersion, int


newVersion) is only called whenever there is a updation in existing
version. So to update a version we have to increment the value of
version variable passed in the superclass constructor
 In onUpgrade method we can write queries to perform
whatever action is required. In most example you will see
that existing table(s) are being dropped and again
onCreate() method is being called to create tables again.
But it’s not mandatory to do so and it all depends upon
your requirements.
 We have to change database version if we have added a
new row in the database table. If we have requirement that
we don’t want to lose existing data in the table then we can
write alter table query in the onUpgrade(SQLiteDatabase
db,int oldVersion, int newVersion) method.
Transactions

 A transaction is a unit of work that is performed against a


database.
 Transactions are units or sequences of work accomplished in a
logical order, whether in a manual fashion by a user or
automatically by some sort of a database program.
 A transaction is the propagation of one or more changes to the
database.
 For example, if you are creating, updating, or deleting a record
from the table, then you are performing transaction on the
table.
 It is important to control transactions to ensure data integrity
and to handle database errors.
 Practically, you will club many SQLite queries into a group and
you will execute all of them together as part of a transaction.
Properties of Transactions

 Transactions have the following four standard properties,


usually referred to by the acronym ACID.
 Atomicity − Ensures that all operations within the work unit
are completed successfully; otherwise, the transaction is
aborted at the point of failure and previous operations are
rolled back to their former state.
 Consistency − Ensures that the database properly changes
states upon a successfully committed transaction.
 Isolation − Enables transactions to operate independently of
and transparent to each other.
 Durability − Ensures that the result or effect of a committed
transaction persists in case of a system failure.
Transaction Control

 Following are the following commands used to control


transactions:
 BEGIN TRANSACTION − To start a transaction.
 COMMIT − To save the changes, alternatively you can
use END TRANSACTION command.
 ROLLBACK − To rollback the changes.

 Transactional control commands are only used with DML


commands INSERT, UPDATE, and DELETE.
 They cannot be used while creating tables or dropping them
because these operations are automatically committed in
the database.

You might also like