Adding Discover SDK to your Android Project

Use the Discover Android SDK to instrument your native Android applications for logging and analysis. The Android SDK implementation is simple. It uses standard Android classes and user interface controls to track user interface events.

Before you begin

  • Install Android Studio
  • Use Gradle version 7.2

Adding the SDK to your Project

About this task

When you manually install the Discover SDK, you must add the SDK files to the proper locations in your application.

Procedure

  1. Add the DCXCore.jar and DiscoverMod.jar into the libs folder of your application to make the capture functions available.
  2. Add the files into the build path of the application you want to instrument.
  3. Integrate Discover SDK files into your Android project by copying the following Discover SDK files to the specified folder for your Android project.
    Filename Android Project Loacation
    DiscoverBasicConfig.properties assets folder
    DiscoverAdvancedConfig.json assets folder
    DiscoverLayoutConfig.json assets folder
    DCXCoreBasicConfig.properties assets folder
    DCXCoreAdvancedConfig.json assets folder
    discovermod.jar libs folder
    dcxcore.jar libs folder
  4. Add permissions for Android:
    <uses-permission android:name="android.permission.INTERNET" />
    	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    	<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    	<uses-permission android:name="android.permission.READ_PHONE_STATE" />
  5. Write Singleton class. It should extend Application class, and this class should declared in maniesfest.xml within the Application tag.
    android:name=".MyApplication"
    
    public class MyApplication extends Application {
        @Override
        public void onCreate() {
            super.onCreate();
            new Discover(this);
            Discover.enable();
            Discover.startSession();
            Log.e("sessionID", Discover.getCurrentSessionId());
        }
        @Override
        public void onLowMemory() {
            Discover.onLowMemory();
            super.onLowMemory();
        }
    
        @Override
        public void onTerminate() {
            Discover.disable();
            super.onTerminate();
        }
    }
  6. Update each Activity class and override the dispatchTouchEvent method:
    public boolean dispatchTouchEvent(MotionEvent e) {  
    	Discover.dispatchTouchEvent(this, e);
    	return super.dispatchTouchEvent(e);
     }

Recording an Activity

About this task

In Android, an activity can be considered a page displayed on mobile devices. By default, you should record an activity that is displayed.

Procedure

  1. You can record an activity displayed by placing the following information in the OnCreate method:
    // this will indicate logical page name. 
    Discover.logScreenview(activity, "Name", ScreenviewType.LOAD); 
    // this will get layout of page after it being created. 
    Discover.logScreenLayoutOnCreate(activity, "Name");
    
  2. Post the data from the app to the endpoint by adding the post URL in Assets > DiscoverBasicConfig.properties > PostMessageUrl.
  3. To take screenshot, change the values for params in HCLGlobalScreenSettings dictionary as shown in the following example:
    assets -> DiscoverLayoutConfig:
    "takeScreenShot": true
    
  4. To blur the screenshot, complete the following steps:
    1. Pass the value
    2. Pass the resulting value to the screenShotBlur param in the HCLGlobalScreenSettings of DiscoverLayoutConfig.
    3. Set takeScreenShot value as True.
      This value will be added as the blur value for all the screenshots taken on different screens.
    4. If takeScreenShot value is False in HCLGlobalScreenSettings, no screen shot will be taken in any of the screens.
  5. To take screenshots with different blur values for different screens, complete the following steps:
    1. Set takeScreenShot value as True and pass 0 for screenShotBlur in the HCLGlobalScreenSettings.
    2. Add the following code example in the Activity of the screens where you would want to add the different blur values (the example is passing a vlur value of 5):
      DCFApplicationHelper.sharedInstance().addImageBlurValue(5) method of the SDK
      Discover.takeScreenShot(topScroll, "Personal_onResume", 1, 8);
  6. To take screenshots without blur, pass screenShotBlur value as 0 in HCLGlobalScreenSettings. No code changes are needed in the Activity or screens. This will create screenshots without blur.