Initializing the SDK
Step 5: Invoke SDK from the App
5.1 SDK Initialization from the Application Class
The SDK should be initialized from the onCreate()
method of the Application class in your app.
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// ...
// Choose one of the examples below:
// Example 1
IUApp.init(getApplicationContext(), null);
// OR
// Example 2
IUApp.init(getApplicationContext(), YourMainActivity.class);
}
}
- When
null
is passed as an argument, the SDK will handle the Google compliant activity with a blank screen as the background of in-app messages. - You can pass
MainActivity.class
as an argument to use it as the background of in-app messages. - Contact your account manager for further details.
Note: If you plan to conditionally start or stop the SDK, you can use the
init
orstopSDKService
methods conditionally as shown below:
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// ...
if (sdkActive == true) {
// Choose one of the examples below:
// Example 1
IUApp.init(getApplication(), null);
// OR
// Example 2
IUApp.init(getApplication(), YourMainActivity.class);
} else {
IUApp.stopSDKService(context);
}
}
}
- If there is a change in the SDK state from inactive to active, it will be reflected on the next application launch. However, a change from active to inactive will not be reflected until the application is restarted.
- Restart the application after changing the SDK state during testing.
If your app doesn't have an Application class, please refer to the link.
5.2 SDK Launch from Activity Class
To invoke the SDK, use the following code in a point where the user always interacts, such as the app's launch (Splash Screen).
IUApp.launch(activityContext);
- Ensure that
IUApp.launch()
is passed anactivityContext
.
5.3 Custom Organization Selection
If the client wishes to have the same app available for different organizations, use the following API from the DR SDK:
// Pass the countryCode configured on DigitalReef server.
IUApp.createOrganisationFromCountryCode(getApplicationContext(), countryCode);
- The
createOrganisationFromCountryCode
method internally configures the SDK. - Example usage:
IUApp.createOrganisationFromCountryCode(getApplicationContext(), "BR");
IUApp.createOrganisationFromCountryCode(getApplicationContext(), "CHL");
IUApp.createOrganisationFromCountryCode(getApplicationContext(), "Peru");
- Ensure that the country code mappings are created in the Digital Reef servers before going live.
Note: The
IUApp.changeOrganization
method is deprecated and will be removed in an upcoming version. Use the above method instead. Contact your DigitalReef contact for more details about this feature. Currently available only for native Android apps.
5.4 Enable/Disable Sensitive Data Collection
If the HostApp wants to control the data being collected, they can do so by setting or resetting the flag using the following method:
IUApp.setSensitiveDataSwitch(context, booleanValue);
- When
booleanValue
istrue
, the SDK will collect the restricted data. Whenfalse
, the data collection will be skipped. - View the list of sensitive data: Sensitive Data List.
Updated almost 2 years ago