Splunk MINT SDK for Android (Legacy)

Splunk MINT SDK for Android Developer Guide

Acrobat logo Download manual as PDF


Splunk MINT is no longer available for purchase as of January 29, 2021. Customers who have already been paying to ingest and process MINT data in Splunk Enterprise will continue to receive support until December 31, 2021, which is End of Life for all MINT products: App, Web Service (Management Console), SDK and Add-On.
Acrobat logo Download topic as PDF

Add Splunk MINT to your Android project

To add Splunk MINT to your project, you need just one line of code. The method you use to send data to Splunk Enterprise depends on whether you use the MINT Data Collector with an API key, or the HTTP Event Collector with a HEC token and URL. For details, see About Splunk MINT data collection.

  • If you are using the MINT Data Collector, use your API key:
  • Mint.initAndStartSession(this.getApplication(), "YOUR_API_KEY");
    
  • If you are using the HTTP Event Collector, use your HTTP Event Collector token:
  • Mint.initAndStartSessionHEC(this.getApplication(), "HEC_MINT_endpoint_URL", "YOUR_HEC_TOKEN");
    

One line of code―that's it!

The initAndStartSession(application, apiKey) or initAndStartSessionHEC(application, url, token) method installs the Splunk exception handler and the performance monitor, sends all the saved data and performance metrics to Splunk MINT, and starts a new session for your activity. For details about threads, read How MINT initialization works.

A few more details are necessary:

  • Do not use any other SDKs that perform error reporting with MINT. Conflicts might occur when multiple SDKs are active.
  • If you haven't already given your app permission to access the Internet, you need to so that your app can send crash reports and performance metrics to Splunk MINT. Add the following line to your app AndroidManifest.xml file to give permission to access the internet:
  • <uses-permission android:name="android.permission.INTERNET" />
    
  • Most IDEs such as Eclipse and Android Studio automatically handle imports, but if yours does not, add the following line at the top of your Activity class file:
  • import com.splunk.mint.Mint;
    
  • To have a better experience with the Splunk MINT dashboards, use numeric versioning schemes, preferably in MAJOR.MINOR.RELEASE format.

Configuration options

Before you initialize the Splunk MINT SDK for Android, you have several configuration options:

  • Include information about the application environment for your mobile app by using the setApplicationEnvironment(environment) method. Use a custom string or one of the following predefined application environments:
    • appEnvironmentRelease
    • appEnvironmentStaging
    • appEnvironmentUserAcceptanceTesting
    • appEnvironmentTesting
    • appEnvironmentDevelopment

    For example:

    // Example 1
    Mint.setApplicationEnvironment("my custom env");
    
    // Example2:
    Mint.setApplicationEnvironment(Mint.appEnvironmentUserAcceptanceTesting);
    

    You can then use the Environment filter in the MINT App to view data for a specific application environment.

  • Limit the number of lines to log. For details, see Report LogCat output.
  • Disable crash reporting for a specific user, for example to improve memory allocation. For details, see Do not report data.
  • Disable network monitoring. For details, see Disable network monitoring.
  • Hook an OkHTTP interceptor to generate network events. For details, see Generate network events with an OkHTTP Interceptor.

Example code

Use the initAndStartSession(application, apiKey) or initAndStartSessionHEC(application, url, token) method to add the Splunk class to your activity, before calling the setContentView method so that you can catch any errors in your AndroidManifest.xml file:

import com.splunk.mint.Mint;

public MyActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Set the application environment
        Mint.setApplicationEnvironment(Mint.appEnvironmentStaging);

        // TODO: Update with your API key
        Mint.initAndStartSession(this.getApplication(), "YOUR_API_KEY");

        setContentView(R.layout.main);

        // Continue with your code
    }

    ...

How MINT initialization works

When initializing the Splunk MINT SDK for Android, the Mint.initAndStartSession or Mint.initAndStartSessionHEC method blocks the main application thread for a very small amount of time, just milliseconds. Blocking the main thread ensures that if an exception, event, or transaction occurs immediately upon starting the application, the MINT SDK does not lose any data while initializing.

If you don't want to block the main thread, you can manually run the initAndStartSession or initAndStartSessionHEC method on a new thread as follows:

new Thread(new Runnable() {
    @Override
    public void run() { Mint.initAndStartSession(application, apiKey); } }).start();

If you use StrictMode for debugging, your app will crash when initializing the MINT SDK because the detectDiskReads and detectDiskWrites options throw an exception whenever the main thread is blocked. To prevent your app from crashing, either disable StrictMode or run the MINT SDK on a new thread. For example:

If (DEBUG) {
    new Thread(new Runnable() {
    @Override
    public void run() { Mint.initAndStartSession(application, apiKey); } }).start();
} else {
    Mint.initAndStartSession(application, apiKey);
}

Initialize the MINT SDK for Android with Service and BroadcastReceiver components

If Service and/or BroadcastReceiver components are running inside the scope of your activities, initializing the MINT SDK at the start of the first activity as described earlier is sufficient. However, if the Service and/or BroadcastReceiver components are running outside the scope of activities, extend the application and initialize the MINT SDK there as follows:

MyApplication.java

import android.app.Application;
public class MyApplication extends Application
{
    @Override
    public void onCreate()
    {
        super.onCreate();
        Mint.initAndStartSession(this, apikey);
    }
}

Then add the following to your AndroidManifest.xml file:

<application android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:name="my.package.here.MyApplication">
Note  A call to Mint.flush() might be needed to submit events immediately.
Last modified on 28 January, 2019
PREVIOUS
Requirements and installation for Android
  NEXT
Verify the SDK is integrated

This documentation applies to the following versions of Splunk MINT SDK for Android (Legacy): 5.2.x


Was this documentation topic helpful?


You must be logged into splunk.com in order to post comments. Log in now.

Please try to keep this discussion focused on the content covered in this documentation topic. If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk, consider posting a question to Splunkbase Answers.

0 out of 1000 Characters