1

How to get current location in android?

  • i. Use either GPS location provider or Network location provider to fetch the current location of a phone, in terms of latitude and longitude.
  • ii. Use LocationManager class, and LocationListener class to fetch locations. Use requestLocationUpdates to register locationlistener with locationmanager object.
  • iii. When ever location gets changed, location manager will automatically call onLocationChanged() method of locationlistner.
  • iv. Use ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION permissions in the manifest file.
  • i
  • i&ii
  • i,ii,&iii
  • i,ii,iii,&iv
2

How to create a sensormanager object to access and view list of sensors available in the phone?

  • Sensor s = new Sensor();
  • SensorManager s = new SensorManager(this);
  • SensorManager s = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
  • Sensor s = (Sensor) getSystemService(Context.SENSOR_SERVICE);

Answer: C SensorManager s = (SensorManager) getSystemService(Context.SENSOR_SERVICE); Description:

3

What does below sensor code do?

  • sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
  • List ls = sm.getSensorList(Sensor.TYPE_ALL);
  • It is creating sensor manager object, and fetching all sensors available in phone of all sensor types.
  • It is creating sensor manager object, and fetching all sensors available in phone of accelerometer type.
  • It is creating sensor manager object, and fetching all sensors types supported by android.
  • all of the above are true.

Answer: A It is creating sensor manager object, and fetching all sensors available in phone of all sensor types.
Description:

4

How to fetch x,y,z co-ordinate values of accelerometer sensor in below function.

  • Note: assume that, this is the function of Sensoreventlistener.
  • Note: assume that, this is registered to listen accelerometer sensor
  • public void onSensorChanged(SensorEvent event) {
    }
  • call event.x, event.y, event.z to get the values.
  • event[0] - contains x value, event[1] - contains y value, event[2] - contains z value.
  • event.values[0] - contains x value, event.values[1] - contains y value, event.values[2] - contains z value.
  • none of the above.

Answer: C event.values[0] - contains x value, event.values[1] - contains y value, event.values[2] - contains z value.
Description: Accelerometer sensor will sens the acceleration force on all 3 axes (x,y,z) and send that even to onSensorChanged().
SensorEvent object is a data structure which will contain all the information about incoming sensor event.. event.values[0] - contains x value, event.values[1] - contains y value, event.values[2] - contains z value.

5

Which sensor is used to find gravitational force on each axes (x,y, &z).

  • GyroScope
  • Accelerometer
  • Proximity sensor
  • we can use any of the above 3 options for this requirement.

Answer: A Accelerometer
Description: Accelerometer is used to find the gravitational force on all 3-axes.

6

What is the sensor to use to find how much near is an object to your phone?

  • GyroScope
  • Accelerometer
  • Proximity sensor
  • Magnetometer

Answer: C Proximity sensor
Description: Proximity sensor is used to find the the distance of an object from the phone.

7

Which of the below is a Motion sensor?

  • GyroScope
  • Humidity sensor
  • Proximity sensor
  • Magnetometer

Answer: A GyroScope
Description: GyroScope is used to find the motion of phone on each axis.

8

Which of the below is a Positional sensors?

  • i. Magnetometer
  • ii. Proxmity sensor
  • iii. Accelerometer
  • iv. Gyroscop sensor
  • i
  • i & ii
  • i, ii, & iii
  • i & iv

Answer: B i & ii
Description: Magnetometer & proximity sensors belong to positional sensor type.

9

What will happen if a sensor is not unregistered, after using it for some time?

  • Android will automatically switch off that sensor and stops it.
  • Nothing will happen, but that sensor will keep running in background. With this no side-effect occurs.
  • that sensor will keep running in the background, and consumes lot of battery power un-necessarily.
  • Program will crash.

Answer: C that sensor will keep running in the background, and consumes lot of battery power un-necessarily.
Description: If we forget to un-register a sensor after registering, then that sensor will keep running in the background, and consumes lot of battery power un-necessarily.

10

How to get phone location? which is better network provider or GPS provider?

  • You can use satellite to fetch your locations.
  • You can either use your cell tower information or WiFi information to know your phone location.
  • using option 1 is faster and more accurate than second option. it also takes less battery power.
  • using option 2 is faster than option1, but how ever it will not give you exact location compared to option 1. takes less battery power.

Answer: D using option 2 is faster than option1, but how ever it will not give you exact location compared to option 1. takes less battery power.
Description: To find location of your phone there are two ways. 1.using network provider info, which makes use of nearest cell tower information or WiFi information to find location. how ever it is not so accurate but gives you nearest location details. it is faster and take less batter power. 2. GPS provider, which makes use of satellites to fetch information of your phone. it is very accurate most of the times and gives exact location details. how ever it is slow and may take more batter power. both will not cost you any thing.

11

How to get the phone's location when battery is draining out? which feature is preferable to use to fetch my current location?

  • Use Network Provider and disable WiFi.
  • Use network provider and enable WiFi.
  • Use GPS provider and fetch from satellites.
  • either use network provider with WiFi disabled or use lastKnownLocation.

Answer: D either use network provider with WiFi disabled or use lastKnownLocation.
Description: If battery is draining out, then we should not use too much of battery power. Using GPS or WiFi will take lot of battery power. so either use network provider with cell tower or use GPS and get last known location.

12

How to find whether GPS is disabled in the phone?

  • if it is disabled onProviderDisabled() will be called with provider name.
  • if it is disabled onStatusChanged() will be called with provider name.
  • either one of the option1 or 2 will happen.
  • There is no way to find it out.

Answer: A if it is disabled onProviderDisabled() will be called with provider name.
Description: if GPS is disabled then onProviderDisabled() function of LocationListener class will be called with provider name.

13

I am travelling through a forest, and GPS satellite is not reachable, once I exit from forest to the area where satellite signal is available, then I want to perform some operation. how should I write this logic?

  • Once satellite is available, onProviderEnabled() will be called. write your logic in that function.
  • onStatusChanged() with status AVAILABLE will be called, write your code there based on this status.
  • onStatusChanged() with status TEMPORARILY_UNAVAILABLE will be called, write your code there based on this status.
  • Once satellite is available, your phone's signal strength will increase. use system properties to check when your signal will increase at that time execute that logic.

Answer: B onStatusChanged() with status AVAILABLE will be called, write your code there based on this status.
Description: onStatusChanged() with status AVAILABLE will be called, write your code there based on this status.

14

What are the permissions required to access phone's location using NETWORK_PROVIDER?

  • ACCESS_FINELOCATION
  • ACCESS_COARSE_LOCATION
  • both option 1 & 2.
  • we don't need to take any permission.

Answer: C both option 1 & 2.
Description: NETWORK_PROVIDER will fetch locations either by using WiFi point or cell tower information. for cell tower we have to use COARSE_LOCATION permission and for WiFi we have to use FINELOCATION permission.

15

In which library GeoCoder class is located?

  • android.location
  • android.hardware
  • com.google.android.maps
  • none of the above.

Answer: A android.location
Description: GeoCoding is part of location's package. It is not related with Maps library.

16

When there is no network signal and satellite signal, How to fetch my phone last location where signal was available?

  • Now it is impossible to find out location
  • Still you can send SMS to find your last location
  • String locationProvider = LocationManager.NETWORK_PROVIDER;
    Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);
  • Use option3 or use this..String locationProvider = LocationManager.GPS_PROVIDER
    Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);

Answer: D Use option3 or use this..String locationProvider = LocationManager.GPS_PROVIDER
Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);
Description: String locationProvider = LocationManager.NETWORK_PROVIDER;
// Or use LocationManager.GPS_PROVIDER

Location lastKnownLocation = locationManager.getLastKnownLocation(locationProvider);
This should give your last known location. Use GPS_PROVIDER for better results.

17

What are the permissions required to obtain phone locations?

  • android.permission.ACCESS_FINE_LOCATION
  • android.permission.ACCESS_COARSE_LOCATION
  • Only option 1 is sufficient
  • You can uese eihter option 1 or 2 or both if required

Answer: D You can uese eihter option 1 or 2 or both if required
Description: android.permission.ACCESS_FINE_LOCATION - use this if you are using GPS features in your programming. else android.permission.ACCESS_COARSE_LOCATION - use this if you are fetching locations based on career network or by using WiFi.

18

What is the package of Sensor framework class.

  • android.kernel
  • android.hardware
  • android.sensor
  • android.framework.sensor

Answer: C android.hardware
Description:

19

How to get current phone location, with out using GPS, internet, WiFi, and cell tower.
If there is no cell tower signal, no WiFi access point, and no satellite signal; then is there any way to fetch my phone location?

  • There is no other way.
  • We can send an SMS to some one to get our location.
  • Use lastKnownLocatoin from location manager using some provider.
  • fetch locations using GPS.

Answer: C Use lastKnownLocatoin from location manager using some provider.
Description: Even if there are no cell tower signal, no WiFi access point, and no satellite signal, still we can find last known location using any of the above two providers. use lastKnownLocation() using locationmanager object. Note : if GPS was turned off recently, then you can get the last known location from gps, which gives more relevant location.