Search…
3. Configuration
To initialize the Sentiance SDK, you first need to prepare a configuration object of type SdkConfig that includes your Sentiance appID and secret key. Head over to the apps section of your developer account to grab these.
Depending on your app's configuration and OS version, the SDK may need to start a foreground service every now and again. You must therefore pass a notification that can be used by the service. In the next section, you'll find a handy notification creation method.
Please read our notification management section to learn how to build user friendly notifications.
Create an SdkConig object as follow:
1
SdkConfig config = new SdkConfig.Builder(APP_ID, SECRET, notification)
2
.setMetaUserLinker(userLinker)
3
.build();
Copied!
In the above example, we hard-code the the appID and secret key for testing purposes. However, this is not secure and can lead to leaked credentials. In your own app, load these credentials from a secure source such a remote server, and store them securely on the device.
The SdkConfig accepts a userLinker which is responsible for handling user linking. The linker is invoked by the SDK when creating a Sentiance user (during the first initialization) to give you a chance to link your app's user to the Sentiance user. If linking succeeds, this linker does not get invoked during subsequent SDK intializations, unless the SDK gets reset.
1
MetaUserLinker userLinker = new MetaUserLinker() {
2
@Override
3
public boolean link(String installId) {
4
// Supply the 'installId' to your server, which should then initiate
5
// a user linking request with the Sentiance backend.
6
7
return requestLinking(installId); // return true if user linking succeeds
8
}
9
};
Copied!
The above implementation expects synchronous execution. Alternatively, you can use MetaUserLinkerAsync which is the async variant of the linker. You then notify the SDK about the linking result by calling onSuccess() or onFailure().
You can learn more about user linking here. To see what other SDK configuration options are available, see SdkConfig.Builder.
Copy link