Initializing the SDK
It is recommended to call init() method in Application class. Please, do not forget to define the Application class in AndroidManifest.xml file with android:name attribute under <application tag.
init() method has 4 mandatory parameters. You can initialize the SDK as shown below:
Kotlin
RelatedDigital.init( context = context, organizationId = "organization ID value", profileId = "profile ID value", dataSource = "data source value" )
Java
RelatedDigital.init( context, "organization ID value", "profile ID value", "data source value" );
You can reach this information on RMC panel.
Enabling the modules that will be used
RelatedDigital SDK consists of 3 different modules:
Push Notification Module
In-App Notification Module
Geofencing Module
It is required to enable the modules that are going to be used as shown below:
Kullanmak istediğiniz modülleri aşağıdaki gibi etkinleştirmeniz gerekmektedir.
It is recommended to enable the modules in Application class. You can find an example Application class that initializes the SDK and enables the all modules below.
AndroidManifest.xml
<application android:name=".MainApplication"
Kotlin
class MainApplication : Application() { override fun onCreate() { super.onCreate() // Init the SDK RelatedDigital.init( context = context, organizationId = "organizationIdValue", profileId = "profileIdValue", dataSource = "dataSourceValue") // Enable In-App Notification Module RelatedDigital.setIsInAppNotificationEnabled( context = context, isInAppNotificationEnabled = true ) // Enable Push Notification Module if(GoogleUtils.checkPlayService(this)) { getFirebaseToken() } else { getHuaweiToken() } // Enable Geofencing Module RelatedDigital.setIsGeofenceEnabled( context = context, isGeofenceEnabled = true ) } private fun getFirebaseToken(){ FirebaseMessaging.getInstance().token .addOnCompleteListener(OnCompleteListener { task -> if (!task.isSuccessful) { Log.e("Firebase Token : ", "Getting the token failed!!!") return@OnCompleteListener } val token = task.result // Enable Push Notification Module RelatedDigital.setIsPushNotificationEnabled( context = context, isPushNotificationEnabled = true, googleAppAlias = "googleAppAliasValue", huaweiAppAlias = "huaweiAppAliasValue", token = token ) }) } private fun getHuaweiToken() { object : Thread() { override fun run() { try { val appId = AGConnectOptionsBuilder().build(applicationContext) .getString("client/app_id") val token = HmsInstanceId.getInstance(applicationContext).getToken(appId, "HCM") if (TextUtils.isEmpty(token) || token == null) { Log.e("Huawei Token : ", "Empty token!!!") return } Log.i("Huawei Token", "" + token) // Enable Push Notification Module RelatedDigital.setIsPushNotificationEnabled( context = context, isPushNotificationEnabled = true, googleAppAlias = "googleAppAliasValue", huaweiAppAlias = "huaweiAppAliasValue", token = token ) } catch (e: ApiException) { Log.e("Huawei Token", "Getting the token failed! $e") } } }.start() } }
Java
public class MainApplication extends Application { @Override public void onCreate() { super.onCreate(); // Init the SDK RelatedDigital.init( context, "organizationIdValue", "profileIdValue", "dataSourceValue"); // Enable In-App Notification Module RelatedDigital.setIsInAppNotificationEnabled( context, true ); // Enable Push Notification Module if(GoogleUtils.checkPlayService(this)) { getFirebaseToken(); } else { getHuaweiToken(); } // Enable Geofencing Module RelatedDigital.setIsGeofenceEnabled( context, true ); } private void getFirebaseToken(){ FirebaseMessaging.getInstance().token .addOnCompleteListener(new OnCompleteListener<String>() { @Override public void onComplete(@NonNull Task<String> task) { if (!task.isSuccessful()) { Log.e("Firebase Token : ", "Getting the token failed!!!"); return; } String token = task.getResult(); // Enable Push Notification Module RelatedDigital.setIsPushNotificationEnabled( context, true, "googleAppAliasValue", "huaweiAppAliasValue", token ); } }); } private void getHuaweiToken() { new Thread() { @Override public void run() { try { String appId = AGConnectServicesConfig.fromContext(getApplicationContext()).getString("client/app_id"); final String token = HmsInstanceId.getInstance(getApplicationContext()).getToken(appId, "HCM"); // Enable Push Notification Module RelatedDigital.setIsPushNotificationEnabled( context, true, "googleAppAliasValue", "huaweiAppAliasValue", token); } catch (ApiException e) { Log.e("Huawei Token", "Getting the token failed! " + e); } } }.start(); } }