Determining the location on Android
AppMetrica can determine the location of a device. Location accuracy depends on the configuration that the library uses for initialization:
How to enable location determination
Note
Starting with version 5.0.0, the AppMetrica SDK is initialized with locationTracking
disabled by default.
To initialize a library with locationTracking
enabled, pass true
to the withLocationTracking(boolean enabled)
method when creating an extended library configuration:
// Creating an extended library configuration.
AppMetricaConfig config = AppMetricaConfig.newConfigBuilder(API_key)
// Enabling the data sending about the device location.
.withLocationTracking(true)
.build();
// Initializing the AppMetrica SDK.
AppMetrica.activate(getApplicationContext(), config);
To enable locationTracking
after initializing the library, use the AppMetrica.setLocationTracking(boolean enabled)
method:
AppMetrica.setLocationTracking(true);
To determine the location more precisely, add to the AndroidManifest.xml
file one of the following permissions:
- android.permission.ACCESS_COARSE_LOCATION — For approximate determination.
- android.permission.ACCESS_FINE_LOCATION — For accurate determination.
For example:
<manifest>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<application>...</application>
</manifest>
If you didn't find the answer you were looking for, you can use the feedback form to submit your question. Please describe the problem in as much detail as possible. Attach a screenshot if possible.