MAD Assignment Answers
MAD Assignment Answers
Answer:
Persistent Data:
Persistent data is one which reside on nonvolatile storage like SD card, internal memory etc.
Persistent data remains preserved irrespective of execution state of application.
Files stored on externally mounted storage device like sd card and which is not part
of application specific directory is called external storage file.
Before using external storage through programming api’s application need
“android.permission.WRITE_EXTERNAL_STORAGE” permission.
Before using external storage, its availability can be verified using
“getExternalStorageState()” method, if storage is available method
returns MEDIA_MOUNTED constant.
There are two alternative to create external storage directory
o In public folder :
Q 5.2 What is shared preference ? explain in detail all methods in shared preference.
Explain scenario when shared preference is useful.(10 Marks)
Anwer:
SharedPreference:
It is an xml file which can store semistructured data in the form of key and value pairs.
Share preferences files are used when data managed by application is small in volume and
no complicated operations are needed to be performed on data.
For many application these files are useful to save configuration information about use
preferences of application setting like background of app, theme, font specifications
etc.
Any application component can read or update the shared preference file.
Sqlite
it is client side ,open source light weight dbms application designed for portable
low configuration handheld devices.
Sqlite Features:
Sqlite Api:
Sqlite
it is client side ,open source light weight dbms application designed for portable
low configuration handheld devices.
Sqlite Features:
Provides almost all features of basic relational DBMS software like transaction support,
query engine.
It needs around 250k memory. By virtue of its low memory requirement, it is used in wide range
of handheld devices.
It supports data types like integer,real ,text, NULL, blob etc.
It support weakly types data storage mechanism.
In android devices , it is available as an integrated application
It doesn’t provide server side administration, foreign key constraint and complex join operation.
All tables created by sqlite api are stored at location “data/data/APP_NAME/databases/” directory
Sqlite Api’s:
1.SqliteOpenHelper:
onUpgrade()
o method defines postoperative action when database version is changed.
o Normally database table should be migrated from old version to new version format,
if not possible tables should be deleted and recreated.
getWritable():
o returns writable instance of SqliteDatabase class.
o This instance can be used to perform insert,update,delete operations on database tables.
getReadable():
o returns readable instance of SqliteDatabase object,it can be used to perform
select operation on database tables.
2. SqliteDatabase:
1. ContentValue:
ContentValue instance is an object which stores values in the form of key and value pair
This object represent entire row /part of row that has to be inserted/updated in
database tables.
Key for database program is name of column and value is column value
Eg. If student is table with 3 columns , rollnumber , name and marks content value can
be created and inserted as
(5M) Drawable:
any graphical file which can be represented in android via Bitmap drawable class.
Drawable can be image or shape located in res/drawable folder.
Based upon image resolution, it can be located in ldpi, hdpi, mdpi or xhdpi folder.
Canvas:-Refer anubhav pradhan book
Animation:
Entire animation process is expressed in separate xml file which defines drawable
resources to be moved, duration for which each resource should be visible.
Steps to Create Drawable Animation
2. create xml file drawableanim.xml in drawable folder with animation-list as root element
<animation-list>
<item location,interval>
</animation-list>
method ad=iv.getBackground();
object ad.start()
//step 4
iv=(ImageView) findViewById(R.id.imageView1);
//step 5
iv.setImageDrawable(null);
//step 6:set background prop of iv to anim file
iv.setBackgroundResource(R.drawable.drawableanim)
;
(5M) Animation:
View Animation:
step 1: create anim folder ,inside create xml file describing properties to be changed for view animation
Animation animation=AnimatioinUtils.loadAnimation(xmlfilename);
step 3:on image view call startAnimation method and pass Animation object as
parameter iv.startAnimation(animation);
//res/anim/scalinganim.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:fromXScale="1.0"
android:toXScale="2.0"
android:fromYScale="1.0"
android:toYScale="2.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000"/>
</set>
}
public void startAnim(View v) throws InterruptedException
{
Animation scaling=AnimationUtils.loadAnimation(this, R.anim.scalinganim);
iv.startAnimation(scaling);
}
Answer:
Media player class can be used to control audio /video files and streams.
Playback of audio/video files/streams is managed by state machine which indicates state
of media player device in different life cycle phases.
1. Idle : state retained when media player instance is just created.in this state it is not associated
with any media source.calling any method related to media source in this state results in
exception.
2. Initialized : media player instance variables are initialized to default values.
3. Prepare: associate media file/stream with media player. Stream /file can be residing in
resource folder, sd card or on web server. phase is analogous to loading dvd in dvd player.
Path of media must be provided to setDataSource() method which is implicitly called in this
state.media contents are decoded in this phase.
4. Start: in this state ,device starts reading codecs from media file, and music is played.
5. Pause : it suspend the media player . in this method state of playing actions is not maintained
by mediaplayer instance. Programmer can record current track using getCurrentPosition()
method and resume its playing action with seekTo(position) when media is restarted.
6. Stop: in this state , media player release data source and no same media can be played in current
life cycle by media player instance
7. Release : in this phase, media player instance is destroyed, it releases all the resources held
by instance eg. references to device files, stream/file connections etc.
Program to illustrate different states through method invocation:
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_music_a b_div);
mp=MediaPlayer.create(getApplicationContext(),
R.raw.janumerijaa);
mp.start();
Toast.makeText(getApplicationContext(), "music
started", Toast.LENGTH_SHORT).show();
arg)
mp.stop();
mp.release();
Cell tower transmit radio signal at regular interval to the devices available in hexagonal cell
area surrounding tower.
Devices communicates continuously with tower once in 0.1second. So in simplest
scenario location of cell indicates location of device.
Since cell covers large span of circular area, it will be difficult to determine location of
device within circumference of the cell.
The advantage of network-based techniques, from a service provider's point of view, is that
they can be implemented non-intrusively without affecting handsets.
Network-based techniques were developed many years prior to the widespread availability of
GPS on handsets.
Accuracy with cell identification as the least accurate and triangulation as moderately accurate
Triangulation is the process of determining the location of a point by forming triangles to it
from known points.
it is the way of location device location using signal strength of nearest three towers.
Answer:
Geocodes are standard mechanism to represent any location on the earth in terms of
latitude and longitude.
Latitude and longitude are imaginary vertical and circular lines plotted around earth axis.
Physical location of object can be represented by the pair of intersecting lattitutde
and longitude at the location of object
Location={latitude,longitude}
Since geocordinates cannot be understood by ordinary peoples who are aware physical location
identity consisting of city,pincode, lane etc.
Mapping of geocoordinate physical location name is maintained in google map server and is
accessible through programming api’s .
Translation of physical location to geocoordinate is called forward geocoding , and
translating geocoordinates to physical location is called reverse geocoding.
Eg. {lat:12.77,long:14.155}-tale hipparaga,solapur ….reverse geocoding
{tale hipparaga,solapur}{lat:12.77,long:14.155} ….forward geocoding
In android Geocoder class is provided to perform forward and reverse geocoding mechanisms.
Answer:
LocationBased Services:
These are the services enables programmer/user to locate location of device in geographical
area in space, time dimensions.
3 mechanism exist which act as location provider mechanisms for device users
o Cell based identification:
Mobile device continuously receive signal from nearest tower.
but single tower can cover long span circular are for signal transmission, so
within circumference again to identify exact position, weak signal from next
two towers are used.
Intersection area covered between three towers is returned as an approximate
device location in this mechanism.
These approach provides lowest accuracy ,lowest battery consumption and
involve low cost as signal transmission to and from GSM tower is continuos
action in device
o Using Wifi :
If wifi is enabled on device and device captures wifi signal, then location of
wifi network will be the same location of device.
Involve low accuracy, high battery consumtion and low cost
o GPS based location identification:
In this approach in built gps hardware is provided in device, which continuously
communicate its position to gps satellites.
GPS satellite are dedicated satellite to operate on locating all gps enabled
devices.
Mechanism provides highest accuracy of location, require extra power for
internal gps device and incur cost for internet connection.
Classes:
1. LocationManager:
a. Used to retrieve location list of different location provider available on device
<String>(getProviders())
b. Used to test whether specific provider for location identification is available or
not (isProviderEnabled(LocationManager.GPS_PROVIDER)) : function returns true
if device has gps and it is turned on
c. Returns best provider, matching constraints in Criteria object
(getBestProvider(Criteria obc,Boolean flag)
d. Returns last known location of device (getLastKnownLocation(provider)
e. Can set device to retriever regular location updates based on time interval and
distance changed from current location.
(requestLocationUpdate(provider,timeinms,distanceimmeter,location_listener)
2. Location:
Object returned as a result of getLastKnownLocation or as an argument to
locationchange activity.
a. getLatitude() : returns latitude of device as a double value
b. getLongitude(): returns longitude of device
3. Criteria:
a. Is an object used to specify the choice of location provider based upon
balanced combination of specific criteria values.
b. Those factors are
i. Accuracy:- ACCURACY_COARSE,ACCURACY_FINE
ii. Power requirement:-POWER_LOW, POWER_HIGH
iii. costAllowed:- true, false
4. Geocoder:returns different location parameters like city, area description,pincode
etc a. getMaxAddressLineIndex(): -returns max number of lines in address
b. getAddressLine(index):-returns address line with specified index
c. getFromLocation(lat,long,maxloc):-return Address object,consisting of fields
locality,city ,pincode etc.
LocationListener:
create activity implementing LocationListerner interface. Listener provide several methods that
will be invoked on location update or during provider status change(eg. onLocationChanged(),
onProviderEnabled(), onProviderDisabled())
create instance of LocationManager using getSystemServices(GPS_PROVIDER)
implements onLocationChanged(Location) method.
Sensor:
Answer:
Android provides api’s are provided to recognize sensors and operates on sensors data.
Framework provides several classes and interfaces to determine list of available sensors in
device, to activate specific sensor, to read data from sensors whenever it find changes in certain
parameters, to determine power requirement of sensor and to deactivate sensor.
Two classes exist in android which provide all those functionalities
1. SensorManager:
It can be instantiated by the context
method
getSystemServices(Context.SensorService
)
Can provide list of available sensors ((List)getSensorList(TYPE_ALL))
Can generate programming handle to specific sensor as
Sensor accelerometer=sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
Code to retrieve list of sensors
final SensorManager
sm=(SensorManager)getSystemService(Context.SENSOR_SERVICE);
List<Sensor> slist=sm.getSensorList(Sensor.TYPE_ALL);
tv.setText(List.toString());
2. SensorEventListener Interface:
This interface provides two abstract methods
onSensorChanged() : invoked when sensor find change in data values
it was retrieving for specific parameter. Eg. for Accelerometer ,when
acceleration changes in any direction this method is called
onAccuracyChanged() :
o invoked when accuracy of sensor reaches below
predefined threshold value.
3. Sensor:
Used to refer specific sensor and to operate on it to fetch data .
Act as programming handle to sensor to be operated.
Register sensor for listening events on it and once processing is over , unregister
it sm.registerListener(this, s, SensorManager.SENSOR_DELAY_FASTEST);
sm.unregisterListener(this);
Define onSensorChanged() and onAccuracyChanged()
methods. public void onSensorChanged(SensorEvent arg0) {
// TODO Auto-generated method stub
Sensor s=arg0.sensor;
if(s.getType()==Sensor.TYPE_ACCELEROMETER)
{
Toast.makeText(getApplicationContext(), "mobile is in
motion", Toast.LENGTH_SHORT).show();
float x=arg0.values[0];
float =arg0.values[1];
float=arg0.values[2];
}
}
8.1 Explain in details steps to upload app on android play store OR Explain versioning ,signing
,packaging mechanism in detail. (10
M) Answer:
To upload app on api store, user need to create playstore account with completion of
registration process at 25$ onetime cost.
Uploading app involves following steps
1. Versioning
2. Signing app
3. Packaging
Versioning:
Versioning information is provided in manifest file and include version code and version name.
o Version Code :
o versionName —
A string used as the version number shown to users. This setting can be specified
as a raw string or as a reference to a string resource.
The value is a string so that you can describe the app version as a
<major>.<minor>.<point> string, or as any other type of absolute or relative version
identifier. The versionName has no purpose other than to be displayed to users
Signing App:
Android requires that all APKs be digitally signed with a certificate before they can be installed.
signing tools like jarsigner attaches the public-key certificate to the APK
A keystore is a binary file that contains one or more private keys.
We can sign app from the command line using standard tools from the Android SDK
and the JDK. To sign an app in release mode from the command line −
Dx tools(Dalvik executable tools ): It going to convert .class file to .dex file. it has useful for
memory optimization and reduce the boot-up speed time
AAPT(Android assistance packaging tool):it has useful to convert .Dex file to.Apk
APK(Android packaging kit): The final stage of deployment process is called as .apk.