Countly Documentation

Countly Resources

Here you'll find comprehensive guides to help you start working with Countly as quickly as possible.

Android SDK FAQ

How to add Countly Android SDK sources to my project?

Since all our SDKs are open-sourced, you need to checkout code from GitHub:

git clone https://github.com/Countly/countly-sdk-android.git

SDK is located in two folders: sdk & sdk-messaging. If you need GCM support, you'll need to add sources from both folders; if you don't need it - just from sdk.

Next open sdk/src/main/java and copy ly & org folders to your project.

Then check that your AndroidManifest.xml has all permissions and services defined in sdk/src/main/AndroidManifest.xml, then in case you use OpenUDID, don't forget to add corresponding service (see in the beginning of this document).

In case you need GCM support, copy sources from sdk-messaging/src/main/java and copy contents of sdk-messaging/src/main/AndroidManifest.xml to your AndroidManifest.xml as well.

How can I make sure that requests to Countly are sent correctly?

Enable logging using Countly.sharedInstance().setLoggingEnabled(true)

How can I provide exact geolocation of user? (Enterprise version only)

Countly.sharedInstance().setLocation(double latitude, double longitude)

Note that this geolocation information is used to send push notifications to users in a specific location.

How can I use Google Play Install referrer?

To improve install attribution precision, you can use Countly Built in Referrer Receiver to catch Google Play Install Referrer data by simply putting this code into your Android manifest application tag.

<receiver android:name="ly.count.android.sdk.ReferrerReceiver" android:exported="true">
    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
    </intent-filter>
</receiver>

How can I enable pinning of public key of SSL certificate for extra security?

Public key pinning is a technique which improves communication security by eliminating threat of man-in-the-middle attack (MiM) in SSL connection. When you supply a list of acceptable SSL certificates to Countly SDK with either Countly.enablePublicKeyPinning(), or Countly.enableCertificatePinning(), it will ensure that connection is made with public key of one of those certificates or those specific certificates respectively. Using whole certificate pinning is somewhat safer, but using public key pinning is preferred since certificates can be rotated and do expire while public keys don't.

Here is an example for Countly try server. You should change the bottom line to read the exact server name or IP if you use a server different than that.

Countly.enablePublicKeyPinning(Arrays.asList(
        "MIIFKTCCBBGgAwIBAgIHKwiwzoMTGzANBgkqhkiG9w0BAQsFADCBtDELMAkGA1UE" +
        "BhMCVVMxEDAOBgNVBAgTB0FyaXpvbmExEzARBgNVBAcTClNjb3R0c2RhbGUxGjAY" +
        "BgNVBAoTEUdvRGFkZHkuY29tLCBJbmMuMS0wKwYDVQQLEyRodHRwOi8vY2VydHMu" +
        "Z29kYWRkeS5jb20vcmVwb3NpdG9yeS8xMzAxBgNVBAMTKkdvIERhZGR5IFNlY3Vy" +
        "ZSBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkgLSBHMjAeFw0xNDExMDgyMjEzMDFaFw0x" +
        "NTExMDgyMDMyNDdaMDwxITAfBgNVBAsTGERvbWFpbiBDb250cm9sIFZhbGlkYXRl" +
        "ZDEXMBUGA1UEAxMOY2xvdWQuY291bnQubHkwggEiMA0GCSqGSIb3DQEBAQUAA4IB" +
        "DwAwggEKAoIBAQDJeeEOvEFjIQIG1HIOdFIq+dLQ6aKB5cX5S5se9OeimU4CZKBV" +
        "IPM9w5a7GXC9N1vLijp5Mg/mHXnxOOqd8bauiZmgfqn5AblYuAfVmI8JXx2UUMVS" +
        "OdE4otNwlyYk6EGeqkKpuH82fBepQbAA8+K9MIlIOA4ALMkO7Eq+2/0/zLIFTlXz" +
        "I+LcKyx6mRSC45wjW0VxZHfPLf7wqyrSnTC2ihuBVJCvT8b0dJoeDDP+pebiLbMK" +
        "I0qi99WZovISI8LLn4BADbH4KpeKFC0b9dBIPBwIVVb+x6OXwmpAnOyeq5sNyFxv" +
        "OJr/LYDRqYZiIztSjuDqG++G0nZqv1rKnQP/AgMBAAGjggG1MIIBsTAMBgNVHRMB" +
        "Af8EAjAAMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAOBgNVHQ8BAf8E" +
        "BAMCBaAwNgYDVR0fBC8wLTAroCmgJ4YlaHR0cDovL2NybC5nb2RhZGR5LmNvbS9n" +
        "ZGlnMnMxLTg3LmNybDBTBgNVHSAETDBKMEgGC2CGSAGG/W0BBxcBMDkwNwYIKwYB" +
        "BQUHAgEWK2h0dHA6Ly9jZXJ0aWZpY2F0ZXMuZ29kYWRkeS5jb20vcmVwb3NpdG9y" +
        "eS8wdgYIKwYBBQUHAQEEajBoMCQGCCsGAQUFBzABhhhodHRwOi8vb2NzcC5nb2Rh" +
        "ZGR5LmNvbS8wQAYIKwYBBQUHMAKGNGh0dHA6Ly9jZXJ0aWZpY2F0ZXMuZ29kYWRk" +
        "eS5jb20vcmVwb3NpdG9yeS9nZGlnMi5jcnQwHwYDVR0jBBgwFoAUQMK9J47MNIMw" +
        "ojPX+2yz8LQsgM4wLQYDVR0RBCYwJIIOY2xvdWQuY291bnQubHmCEnd3dy5jbG91" +
        "ZC5jb3VudC5seTAdBgNVHQ4EFgQU2HaVyBs6bqNJxxBSu3gI6rhpX38wDQYJKoZI" +
        "hvcNAQELBQADggEBAI+uKV661xgfAk3YhHhsQ7zUKeWQEa0TUrMjSSh8uuVhmGpH" +
        "vport3DJdc4/PWQ7iZCXAd7pKz7Mb/IDhtL++lmU/vaInthaTtpt2M22gxqbBgvO" +
        "1hnq4gcwohh6ahJaYNcZYgO5raagcRkEh2c21WdHrybAgFGTj6ToQXcJDOtTi8tw" +
        "w0tmcpbhx2HT72xCdwxwE07KulxdIn4Ei3BWvrMot68y5DaOxUrP8vfBkGbxAVG/" +
        "BPiFRsN/m6SQWlaswztVH5MSPE8Ea2uDSp2OrZx8pO6zsXI2eUoLkvjAygPkk3k6" +
        "GDHzA8+cd8HuXuZ6dTAswYWvyKdSwlyz1qWti18="))
    .init(this, "https://try.count.ly", "c4608d0a021b1cef0f8cb031f51200e9cbe48dd4")

To easily get current certificate from your server you can use this snippet (replace try.count.ly with your server name):

 openssl s_client -connect try.count.ly:443 -showcerts

Is it possible to use Android SDK with another crash SDK?

It should be fine to use Countly together with another crash SDK. If you would like to track caught exception, you would just pass them to both SDK's. When catching uncaught exceptions with both, there are some uncertainties. Although in Android there can be only one uncaught exception handler, you can save the previous handler and when receiving a uncaught exception, pass it also to the saved one. We can't be certain how other SDK's are implemented or if the OS would give enough time to propagate the exception through all handlers. Therefore if you want to use Countly another crash SDK, we advise to initialize Countly as the last one.

How can I tell which Countly Android SDK version I am using?

The Countly class has a public static string called COUNTLY_SDK_VERSION_STRING that contains the current SDK version. You can access it by calling Countly.COUNTLY_SDK_VERSION_STRING. It would return something similar to "17.05".

I get HTTP 400 from when I submit event data

If you are using a Android SDK version before 16.12.3 then you could encounter this problem by providing the server URL in the wrong format. In the earlier versions the init function would expect to receive the server url in the format "http://server.com", and the format "http://server.com/" would throw an error with the text "HTTP error response code was 400 from submitting event data".

To fix this problem, just remove the trailing "/".

What metrics data is collected by Countly Android SDK?

Countly Android SDK collects following metrics by default:

  • Device Model
  • Screen Resolution
  • Screen Density
  • OS Name
  • OS Version
  • App Version
  • Locale Identifier
  • Carrier
  • App package name

Android SDK FAQ


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.