Upgrading from 2.X

The 3.X SDK is the next generation Pulse SDK that builds upon over 3 years of user feedback and production experience gained with the 2.X. Some of the more notable changes that have gone in:

  • Simplified integration workflow
  • Improved background operations on Android 8 and above
  • Revamp of the deep linking functionality for ease of use
  • Further improvements regarding battery efficiency
  • Reduced codebase size and slimed down feature set

Breaking API changes


As this is a major release, we've introduced breaking API changes, which we will discuss in greater detail bellow.

Initializing the SDK

The initialization process has been simplified and a PulseSdkConfig builder class has been introduced to help with it.

Find the following code in your Application class:

@Override
public void onCreate() {
  super.onCreate();
  mApplicationContext = instance;
  mPulseSDK = new PulseSDK(mApplicationContext);
  String mPackageName = "com.pulse.demo";
  boolean available = mPulseSDK.isAvailable(mApplicationContext,mPackageName);
  if(available) {
    initPulseSDK(mPackageName);
  }
}

public static void initPulseSDK(String mPackageName) {
  mPulseSDK.setPackageName(mPackageName);
  mPulseSDK.setConfig("key","APP-KEY");
  mPulseSDK.setConfig("url","APP-URL");
  mPulseSDK.startService(true, true, true);
  PulseDeepLinkReceiver mPulseDeepLinkReceiver = new PulseDeepLinkReceiver(mApplicationContext);
}

Replace it all with this:

private static final String APP_KEY = "YOUR_APP_KEY"; // TODO: Replace with your own!
private static final String APP_URL = "YOUR_APP_URL"; // TODO: Replace with your own!

private static PulseSdkApplication application;
private PulseSdk pulseSdk;

@Override
public void onCreate() {
    super.onCreate();

    application = this;

    PulseSdkConfig config = new PulseSdkConfig(APP_KEY, APP_URL);
    pulseSdk = new PulseSdk(this, config);
}

Starting the SDK

The starting of the SDK has been simplified with the introduction of the ActivityCompat helpers for checking/requesting user runtime permissions and an overall lighter SDK API.

Find the following code in your main activity:

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  if (Build.VERSION.SDK_INT >= 23) {
    PulsePermissions mPulsePermissions = new PulsePermissions(this.getApplicationContext());
    requestLocationPermission(mPulsePermissions.getPemissionStatusLocation());
  }else {
    if(true != PulseSDK.getSDKInitialised()) {
      pulseSDKInit();
    }
  }

  if(PulseSDK.getSDKInitialised()==true) {
    sdkStatus = true;
  }
}

private void requestLocationPermission(int mLocation) {
  if (Build.VERSION.SDK_INT >= 23) {
    if ((mLocation != PackageManager.PERMISSION_GRANTED)) {
      boolean bLocation = ActivityCompat.shouldShowRequestPermissionRationale(this,Manifest.permission.ACCESS_FINE_LOCATION);
      if (bLocation) {
        Toast.makeText(this, "User diabled Location Permission... Wait until user changes Permissions", Toast.LENGTH_LONG).show();

      } else {
        ActivityCompat.requestPermissions((Activity) this,
            new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
            REQUEST_PERMISSION_LOCATION);
      }
    } else {
      if ((mLocation != PackageManager.PERMISSION_GRANTED)) {
        boolean bLocation = ActivityCompat.shouldShowRequestPermissionRationale(this,Manifest.permission.ACCESS_FINE_LOCATION);
        if (bLocation) {
          Toast.makeText(this, "User diabled Location Permissions... Wait until user changes Permissions", Toast.LENGTH_LONG).show();
        }

      }else {
        Toast.makeText(DemoActivity.this, "Location Permission (already) Granted!", Toast.LENGTH_SHORT).show();
      }
    }
  } else {
    Toast.makeText(DemoActivity.this, "targetSdkVersion < 23"+Build.VERSION.SDK_INT, Toast.LENGTH_SHORT).show();
  }
}

Replace it with:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    pulseSdk = PulseSdkApplication.getInstance().getPulseSdk();

    if (ActivityCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        //Step #1: Request user permissions
        requestPermissions();
    }
}

private void requestPermissions() {
    ActivityCompat.requestPermissions(MainActivity.this,
            new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
            REQUEST_PERMISSIONS_REQUEST_CODE);
}


@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                       @NonNull int[] grantResults) {
    if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE) {
        if (grantResults.length <= 0) {
            Log.i(TAG, "User interaction was cancelled.");
        } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            Log.i(TAG, "Permission granted.");
            //Step #2: Start the SDK
            pulseSdk.start();
        } else {
            Log.i(TAG, "Permission denied");
        }
    }
}

Segments

In order to handle segments easier we've moved on to use a Map which is a data type that better represents the segment functionality key/value nature.

Find the following code in your main activity:

ArrayList<String> segmentList = new ArrayList<String>();
segmentList.add(0, "gender=female");
segmentList.add(1, "age=35");
segmentList.add(2, "job=engineer");
mPulseSDK.setSegments(segmentList);

Replace it with:

Map<String, String> segmentMap = new HashMap<>();
segmentMap.put("gender", "male");
segmentMap.put("age", "18");
segmentMap.put("job", "engineer");
pulseSdk.addSegments(segmentMap);

Deep linking

You no longer need to handle the following deep link types:

  • Email
  • Phone
  • URL

As for the custom deep links the integration has been simplified. Please follow the guide here to adjust your implementation.

Deprecated Features


The following features will no longer be supported:

  • Google DFP
  • Precise and last known location and location updates

Please contact us at support@pulseid.com regarding help with migrating off of these features.