Public:OpenCellIDCollectService

From OpenCellID wiki
Jump to: navigation, search

OpenCellIDCollectService

This service collects the location of the visible cells and stores the measurements in a local database along with informations about the corresponding networks.

Each time a new cell is detected, or each time your location changes by a significant distance, a new measurement is added to the database. If the measurement is related to a different network, also information about the network is collected and added to the database.

Hence, you can have multiple measurements related to the same cell, because each time your location changes new measurements are added. The more measurements are available, the better a cell's position can be determined by the OpenCellID database.

Using the collect service

1) To use the service, you have first to link the Service library to your project.

2) Next step is to create the service in your app. If you have a single activity (or a main activity), you can do this in the onCreate() method of your activity. If you have a complex app with multiple activities, the best place would be the Application class.

OpenCellIDCollectService collectService = new OpenCellIDCollectService(context);

3) The service works out-of-the-box using some predefined settings. If needed, you can change them (see the Javadoc for a description of all the available settings).

Example: how to change some settings (optional):

collectService.setMinSameCellDistance(20);

4) Now you can start the service. Measurements collection is started, and will continue until you stop the service.

collectService.startService();

Requirements

Your application manifest should hold the following permissions in order to use this service:

 android.permission.WRITE_EXTERNAL_STORAGE <br/>
 android.permission.INTERNET <br/>
 android.permission.ACCESS_FINE_LOCATION<br/>
 android.permission.ACCESS_COARSE_LOCATION <br/>
 android.permission.READ_PHONE_STATE <br/>
 android.permission.WAKE_LOCK </br>
 android.permission.ACCESS_NETWORK_STATE

Also you should put a service tag in your manifest to reference the following Android service:

<service android:name="com.enaikoon.android.service.opencellid.collect.data.CellIDCollectionService" android:process=":collect_service"/>

Service interruptions

Occasionally, Android can interrupt the service when your device is running out of resources.

In such case, the service is restarted automatically by the system when enough resources become again available.

Screen wake options

When the screen goes off, Android stops notifying the services about telephony changes, and the last cell information is retained until the screen goes on again.

Since the service gets information from both GPS and Telephony sources, having outdated telephony information would cause invalid measurements.

For this reason, measurements are collected only when the screen is on (on full power or dimmed).

To cope with this issue, the OpenCellIDCollectService provides the following options:

setWakeScreenOnTimer(boolean flag)

Causes the screen to be turned on (in dimmed state) periodically after a given time since it went to sleep, to allow the system to acquire telephony updates.

This option is off by default. You can turn it on to collect more measurements but this will need some more battery.

setWakeScreenPeriod(long period)

If the option to wake the screen periodically is on, then the screen will be turned on after this given time since it last went to sleep. The default period is ???

Bind this to the speed. If the device is not moving, the screen can stay off. The fastest is moving, the shortest must be the period. 
setWakeScreenTime(long time)

If the option to wake the screen periodically is on, then the wake will last for the configured amount of time. The default time is ???

THIS SECTION HAS TO BE COMPLETED

Storage

For general informations about storage, see the Storage section.

All the measurements are saved in the OCID_measurements database. When a new cell is detected, it is added to the OCID_cells database.