Table of Contents | ||||
---|---|---|---|---|
|
SDK'nın init edilmesi
Info |
---|
init() metodunun Application sınıfının içerisinde çağırılması önerilir. Application sınıfını AndroidManifest.xml dosyasında <application tag ı içerisinde android:name ile tanımlamayı unutmayınız. |
init metodu 4 zorunlu parametre almaktadır. SDK yı aşağıdaki gibi init edebilirsiniz.
Kotlin
Code Block |
---|
RelatedDigital.init(
context = context,
organizationId = "buraya organization id nizi yazınız",
profileId = "buraya profile id nizi yazınız",
dataSource = "buraya datasource değerini yazınız"
) |
Java
Code Block |
---|
RelatedDigital.init(
context,
"buraya organization id nizi yazınız",
"buraya profile id nizi yazınız",
"buraya datasource değerini yazınız"
); |
Bu bilgilere RMC paneli üzerinden ulaşabilirsiniz.
...
Kullanılacak Modüllerin Aktifleştirilmesi
RelatedDigital SDK 3 ayrı modülden oluşmaktadır :
Push Notification Modülü
In-App Notification Modülü
Geofence Modülü
Kullanmak istediğiniz modülleri aşağıdaki gibi etkinleştirmeniz gerekmektedir.
Info |
---|
Modüllerin etkinleştirilmesi işleminin Application sınıfı içerisinde yapılması önerilir. Aşağıda SDK yı init eden ve tüm modülleri etkinleştiren örnek bir Application sınıfı bulunmaktadır |
AndroidManifest.xml
Code Block |
---|
<application
android:name=".MainApplication"
|
Kotlin
Code Block |
---|
class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
// RelatedDigital SDK nın init edilmesi
RelatedDigital.init(
context = context,
organizationId = "organizationIdDeğeri",
profileId = "profileIdDeğeri",
dataSource = "dataSourceDeğeri")
// In-App Notification Modülünün etkinleştirilmesi
RelatedDigital.setIsInAppNotificationEnabled(
context = context,
isInAppNotificationEnabled = true
)
// Push Notification Modülünün Etkinleştirilmesi
if(GoogleUtils.checkPlayService(this)) {
getFirebaseToken()
} else {
getHuaweiToken()
}
// Geofence Modülünün Etkinleştirilmesi
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
// Push Notification Modülünün Etkinleştirilmesi
RelatedDigital.setIsPushNotificationEnabled(
context = context,
isPushNotificationEnabled = true,
googleAppAlias = "googleAppAliasDeğeri",
huaweiAppAlias = "huaweiAppAliasDeğeri",
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)
// Push Notification Modülünün Etkinleştirilmesi
RelatedDigital.setIsPushNotificationEnabled(
context = context,
isPushNotificationEnabled = true,
googleAppAlias = "googleAppAliasDeğeri",
huaweiAppAlias = "huaweiAppAliasDeğeri",
token = token
)
} catch (e: ApiException) {
Log.e("Huawei Token", "Getting the token failed! $e")
}
}
}.start()
}
} |
Java
Code Block |
---|
public class MainApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// RelatedDigital SDK nın init edilmesi
RelatedDigital.init(
context,
"organizationIdDeğeri",
"profileIdDeğeri",
"dataSourceDeğeri");
// In-App Notification Modülünün etkinleştirilmesi
RelatedDigital.setIsInAppNotificationEnabled(
context,
true
);
// Push Notification Modülünün Etkinleştirilmesi
if(GoogleUtils.checkPlayService(this)) {
getFirebaseToken();
} else {
getHuaweiToken();
}
// Geofence Modülünün Etkinleştirilmesi
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();
//Push Notification Modülünün Etkinleştirilmesi
RelatedDigital.setIsPushNotificationEnabled(
context,
true,
"googleAppAliasDeğeri",
"huaweiAppAliasDeğeri",
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");
// Push Notification Modülünün Etkinleştirilmesi
RelatedDigital.setIsPushNotificationEnabled(
context,
true,
"googleAppAliasDeğeri",
"huaweiAppAliasDeğeri",
token);
} catch (ApiException e) {
Log.e("Huawei Token", "Getting the token failed! " + e);
}
}
}.start();
}
} |