Upload
majuyasir
View
227
Download
0
Embed Size (px)
Citation preview
3-Day Workshop on AndroidProgramming
Electronic Engineering DepartmentMohammad Ali Jinnah
University(MAJU), Islamabad
Kashif Sardar
Workshop Outline
2
Day 1– Mobile App
development– Android Platform
Architecture– Development
environment setup
– Application execution
– Hello World Application
– User Interface Designing
Day 2– User Interface
Designing Cont…– Activities and
Intents– Permissions– Fragment Classes– Debugging– Accessing Android
Hardware
Day 3– Fragment Classes– Accessing Android
Hardware– Databases and
Content Provider– Map, Geo Coding
and Locations– Deployment– Closing Ceremony
Kashif Sardar
Fragment Classes
3
Tablets have larger displays than phones do
They can support multiple UI panes / user behaviors at the same time
The 1 activity – 1 thing the user can do heuristic may not work for larger
devices
Quote Viewer Application
Application uses two Activities
Ones shows titles of Shakespeare plays & allows user to select one title
The other shows a quote from selected play
This layout is reasonable on a phone But inefficient on a larger device
Kashif Sardar
Fragment Classes
4
Tablets have larger displays than phones do
They can support multiple UI panes / user behaviors at the same time
The 1 activity – 1 thing the user can do heuristic may not work for larger
devices
Quote Viewer Application
Application uses two Activities
Ones shows titles of Shakespeare plays & allows user to select one title
The other shows a quote from selected play
This layout is reasonable on a phone But inefficient on a larger device
Kashif Sardar
Fragment Classes
Represents a behavior / portion of UI within an Activity
Multiple Fragments can be embedded in an Activity to create a multi-pane
UI
A single Fragment can be reused across multiple Activities
Fragments In Action
Kashif Sardar
Accessing Android Hardware-Camera These are the following two ways , in which you can use camera in
your application
1. Using existing android camera application in our application
2. Directly using Camera API provided by android in our application
set of permissions and features in the AndroidManifest.xml
Using existing android camera application in our application
Let See in action and explore the code
Kashif Sardar
Shared Preferences
Small amounts of primitive data
A persistent map Holds key-value pairs of simple data types
Automatically persisted across
application sessions
Often used for long-term storage of customizable application data
Account name
Favorite WiFi networks
User customizations
Kashif Sardar
File
Class represents a file system entity identified by a pathname
Storage areas are classified as internal or external
Internal memory usually used for smaller, application private data sets
External memory usually used for larger, non-private data sets
File API
FileOutputStream
openFileOutput(String name, intmode)
Open private file for writing. Creates the file if it doesn't
already exist
FileInputStream
openFileInput(String name)
Open private file for reading
Kashif Sardar
SQLite Databases
Android provides structured data persistence through a combination
of SQLite databases and Co
Using SQLite you can create fully encapsulated relational databases for
your applications. Use them to store and manage complex, structured
application data.
Android databases are stored in the
/data/data/<package_name>/databases folder on your device (or
emulator).
Kashif Sardar
SQLite Databases Cont..
SQLiteis a well-regarded relational database management system
(RDBMS). It is:
Open-source
Standards-compliant
Lightweight
Single-tier
It has been implemented as a compact C library that’s included as part
of the Android software stack
Why This?
Kashif Sardar
Content Providers Represents a repository of structured data
Encapsulates data sets
Enforces data access permissions
Content Providers provide an interface for publishing and consuming
data, based around a simple URI addressing model using the
content://schema.
They enable you to decouple your application layers from the
underlying data layers, making your applications data-source agnostic
by abstracting the underlying data source.
Intended for inter-application data sharing
Kashif Sardar
Content Providers Format content://authority/path/id
content – scheme indicating data that is managed by a content
provider
authority – id for the content provider
path – 0 or more segments indicating the type of data to be accessed
id – a specific record being requested
Example:
ContactsContract.Contacts.CONTENT_URI=“content://com.android.contacts/contacts/”
Kashif Sardar
Content Providers Examples Browser – bookmarks, history
Call log- telephone usage
Contacts – contact data
Media – media database
UserDictionary– database for predictive spelling
Many more
Kashif Sardar
Maps, Geo-coding, and Location-Based Services
“Location-based services” is an umbrella term that describes the
different technologies you can use to find a device’s current location.
Mobile applications can benefit from being location-aware
Allow applications to determine & manipulate location
Find stores near the user’s current location
Direct a user from a current to a particular store
Define a geofence
Initiate action when user enters or
exits the geofence
Kashif Sardar
Maps, Geo-coding, and Location-Based Services
Location
Represents a position on the Earth A Location instance consists of:
Latitude, longitude, timestamp and,
optionally, accuracy, altitude, speed,
and bearing
Location Providers
Represents a location data source
Actual data may come from
GPS satellites
Cell phone towers or WiFiaccess points
Kashif Sardar
Maps, Geo-coding, and Location-Based Services
Location Manager
Determine the last known user location
Register for location updates
Register to receive Intents when the device nears or moves away
from a given geographic area
Location Listeners
Defines callback methods that are
called when Location or LocationProvider status changes
Kashif Sardar
Signing and publishing applications (deployment)
Android package files (.APK).
During development, your applications will be signed using a debug
key that is automatically generated by the ADT tools.
The JDK includes the Keytooland Jarsignercommand-line tools
necessary to create a new keystore/signing certificate, and to sign your
APK, respectively.
Alternatively, you can use the Export Android Application wizard
Kashif Sardar
Signing Applications Using the Export Android Application Wizard
To launch the wizard, open the Package Explorer and select File then
Export,
Kashif Sardar
Signing Applications Using the Export Android Application Wizard
Open the Android folder, select Export Android Application, and then
click Next.
Kashif Sardar
Signing Applications Using the Export Android Application Wizard
The Keystore selection screen provides the option either to use an
existing keystore file, or to generate a new file.
Kashif Sardar
Signing Applications Using the Export Android Application Wizard
The next step is to generate a new private key which will be used to sign the application
package. Once the information has been entered, click on the Next button to proceed
with the package creation.
Kashif Sardar
Signing Applications Using the Export Android Application Wizard
Final step Press Finish
Kashif Sardar
Signing Applications Using the Export Android Application Wizard
When you Press Finish following output will shown on console window
Now go to the location which you select for your key see what happen two files are
created
Kashif Sardar