In In this page:
Table of Contents |
---|
...
Step 1 - Requirements
Android mobile app & Android Studio |
Firebase Cloud Messaging ve Huawei Push Kit - google_services.json & agconnect_services.json |
RMC Account - AppAlias |
Minimum |
21 API Level Test Device |
Step 2 - Adding Dependencies
2.1 Please add code block to Add Euromessage to the dependencies
in app/build.gradle (Module: app) .
Code Block | ||
---|---|---|
| ||
dependencies { implementation 'com.euromsg:euromsg:$euromessage_version' github.relateddigital:euromessage-android:4.6.1' } apply plugin: 'com.huawei.agconnect' apply plugin: 'com.google.gms.google-services' |
...
2.2 Please add code block to project / build.gradle'
Code Block | ||
---|---|---|
| ||
buildscript { repositories { google() jcenter() maven {url 'http://developer.huawei.com/repo/'} } dependencies { classpath "com.android.tools.build:gradle:$gradle_version" classpath 'com.google.gms:google-services:$google_version' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.huawei.agconnect:agcp:$huawei_version' } } allprojects { repositories { google() jcenter() maven {url 'http://developer.huawei.com/repo/'} maven { url 'https://jitpack.io' } } } |
...
...
Step 3 - Adding codes to Android Manifest
Code Block |
---|
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> |
|
Push notifications are from FCM and HMS will be covered by Euromessage. You may need to define your application's Application Class - if it does not exist. All you have to do here is create a new class, extend it from Application Class and define it in the AndroidManifest file
...
You will see example implementation below. For this you need to define FIREBASE_APP_ALIAS and HUAWEI_APP_ALIAS through the RMC panel.
Code Block | ||
---|---|---|
| ||
public class MainApplication extends Application { private final String FIREBASE_APP_ALIAS = "euromessage-android"; private final String HUAWEI_APP_ALIAS = "euromsg-huawei"; private static EuroMobileManager euroMobileManager; @Override public void onCreate() { super.onCreate(); euroMobileManager = EuroMobileManager.init(FIREBASE_APP_ALIAS, HUAWEI_APP_ALIAS, this); euroMobileManager.registerToFCM(getBaseContext()); } } |
...
Code Block | ||
---|---|---|
| ||
private void setExistingFirebaseTokenToEuroMessage() { FirebaseInstanceIdFirebaseMessaging.getInstance().getInstanceIdgetToken() .addOnCompleteListener(new OnCompleteListener<String>() { .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() { @Override public void onComplete(@NonNull Task<InstanceIdResult>Task<String> task) { if (!task.isSuccessful()) { return; return; } } String token = task.getResult(); String token = task.getResult().getToken(); euroMobileManager.euroMobileManager.subscribe(token, getApplicationContext()); } }); } |
4.2 Getting Token Huawei Messaging Service
...
On EMUI 10, phones generate tokens as follows. You have to subscribe this generated token to euroMobileManager.
Code Block | ||
---|---|---|
| ||
private void setHuaweiTokenToEuromessage() { new new Thread() { @Override public void run() { try { String appId = new AGConnectServicesConfigAGConnectOptionsBuilder().fromContextbuild(getApplicationContext()).getString("client/app_id"); final String token = HmsInstanceId.getInstance(getApplicationContext()).getToken(appId, "HCM"); if(TextUtils.isEmpty(token) || token euroMobileManager.subscribe(token, getApplicationContext()); == null) { Log.ie("Huawei Token : ", "" +Empty token!!!"); } catch (ApiException e)return; { } Log.e("Huawei Token", "get token failed, " + e); euroMobileManager.subscribe(token, getApplicationContext()); } Log.i("Huawei Token", "" + }token); }.start(); } |
...
Code Block | ||
---|---|---|
| ||
if (!EuroMobileManager.checkPlayService(getApplicationContext()) catch (ApiException e) { setHuaweiTokenToEuromessage(); Log.e("Huawei Token", "Getting the token failed! " }+ e); |
Final code:
Code Block | ||
---|---|---|
| ||
public class MainApplication extends Application {} private final String FIREBASE_APP_ALIAS} = "euromessage-android"; }.start(); } |
OR
Code Block |
---|
private final String HUAWEI_APP_ALIAS = "euromsg-huawei"; void setHuaweiTokenToEuromessage() { new Thread() { private static EuroMobileManager euroMobileManager; @Override public void onCreaterun() { super.onCreate(); try { euroMobileManager = EuroMobileManager.init(FIREBASE_APP_ALIAS, HUAWEI_APP_ALIAS, this); euroMobileManager.registerToFCM(getBaseContext()); String appId setExistingFirebaseTokenToEuroMessage(); if (!EuroMobileManager.checkPlayService= AGConnectServicesConfig.fromContext(getApplicationContext()).getString("client/app_id"); { setHuaweiTokenToEuromessage(); final String token = HmsInstanceId.getInstance(getApplicationContext()).getToken(appId, "HCM"); } } } euroMobileManager.subscribe(token, getApplicationContext()); |
...
If various parameters belonging to the user are known, they can be added in the activity as below or during the registration phase. Thanks to the code block below, if the user with the same information is available in the Euromessage RMC panel, the received token will be matched to the user.
With this method, values are added to the extra parameter in the json object sent to the server for subscribe operation and it is specified with which token the user will match. The sync () method should be called after the mandatory parameters and optional parameters are sent.
Code Block | ||
---|---|---|
| ||
--compulsory parameters--
euroMobileManager.setEmail("melike.yildirim@euromsg.com", this);
euroMobileManager.setEuroUserId("123455", this);
--optional parameters--
euroMobileManager.setAppVersion("1.1");
euroMobileManager.setFacebook("euroFB", this);
euroMobileManager.setTwitterId("euroTW", this);
euroMobileManager.setPhoneNumber("05320000000", this);
euroMobileManager.setLocation(41.12,29.11);
euroMobileManager.setNotificationTransparentSmallIcon(android.R.drawable.your_drawable, getApplicationContext());
euroMobileManager.setNotificationColor("#d1dbbd");
euroMobileManager.setChannelName("Demo", getApplicationContext());
euroMobileManager.setPushIntent("com.relateddigital.euromessage.MainActivity", getApplicationContext());
euroMobileManager.sync(this);
|
As soon as an application is installed on the mobile device, the token information of this device is written to the RMC database with the push subscription service. A token; “anonymous”, that is, it is recorded without being paired with any user until the user logs in to the application. In order for this token to be paired with a user, it must be logged in the device and an information identifying the owner of this token (KEY_ID or EMAIL) must be sent to the RMC. This information is located in the "extra": {} block in the push message payload.
In order for your data from the mobile channel to be uploaded to RMC, please pay attention that whatever reference value you have used in your active RMC account (KEY_ID * or E-Mail) comes from the mobile channel with this reference.
*KEY_ID: These are the id values used by the application owner to deduplicate the customer. These can be expressed with different names such as CRMid, userid, customerid, accountid.
Extra parameter in payload sent for user-token matching will take parameters in this way;
Code Block | ||
---|---|---|
| ||
"extra" : {"email" : "melike.yildirim@euromsg.com",
"keyID" : "123456"} |
Step 6 - IYS Email Register
If your user is a corporate account, you must send it as a TACIR. To do this, change the value from false to true in registerEmail method.
Code Block | ||
---|---|---|
| ||
EuromessageCallback callback = new EuromessageCallback() {
@Override
public void success() {
Toast.makeText(getApplicationContext(), "REGISTER EMAIL SUCCESS", Toast.LENGTH_LONG).show();
}
@Override
public void fail(String errorMessage) {
String message = "REGISTER EMAIL ERROR ";
if(errorMessage != null) {
message = message + errorMessage;
}
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}
};
EuroMobileManager.getInstance().registerEmail("test@euromsg.com", EmailPermit.ACTIVE, false, getApplicationContext(), callback); |
Step 7 - Read Report & Navigating
To capture the content of the incoming push notification, you should use the onNewIntent() method as follows.
If you have previously entered a class through the EuroMobileManager.setPushIntent() method, the onNewIntent() method must be added to that class. If you did not use the setPushIntent() method, the onNewIntent() method must be added to the launcher activity.
If you are using SDK version 4.5.2 and above, read report will be sent from SDK automatically. You just need to navigate.
Code Block |
---|
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if (intent.getExtras() != null) { Log.i("Huawei Token", "" + token); } catch (ApiException e) { Log.e("Huawei Token", "get token failed, " + e); } } }.start(); } |
4.3 In devices where two services are active, to avoid sending the token twice
Code Block | ||
---|---|---|
| ||
if (!EuroMobileManager.checkPlayService(getApplicationContext())) {
setHuaweiTokenToEuromessage();
}
|
Final code:
Code Block | ||
---|---|---|
| ||
public class MainApplication extends Application {
private final String FIREBASE_APP_ALIAS = "euromessage-android";
private final String HUAWEI_APP_ALIAS = "euromsg-huawei";
private static EuroMobileManager euroMobileManager;
@Override
public void onCreate() {
super.onCreate();
euroMobileManager = EuroMobileManager.init(FIREBASE_APP_ALIAS, HUAWEI_APP_ALIAS, this);
euroMobileManager.registerToFCM(getBaseContext());
setExistingFirebaseTokenToEuroMessage();
if (!EuroMobileManager.checkPlayService(getApplicationContext())) {
setHuaweiTokenToEuromessage();
}
}
} |
Step 5 - Token User Member Match
If various parameters belonging to the user are known, they can be added in the activity as below or during the registration phase. Thanks to the code block below, if the user with the same information is available in the Euromessage RMC panel, the received token will be matched to the user.
With this method, values are added to the extra parameter in the json object sent to the server for subscribe operation and it is specified with which token the user will match. The sync () method should be called after the mandatory parameters and optional parameters are sent.
Code Block | ||
---|---|---|
| ||
--Mandatory Parameters--
euroMobileManager.setEmail("euromsg@euromsg.com", this);
euroMobileManager.setEuroUserId("123456", this);
--Optional Parameters--
euroMobileManager.setAppVersion("1.1");
euroMobileManager.setFacebook("euroFB", this);
euroMobileManager.setTwitterId("euroTW", this);
euroMobileManager.setPhoneNumber("05320000000", this);
euroMobileManager.setLocation(41.12,29.11);
euroMobileManager.setNotificationTransparentSmallIcon(android.R.drawable.your_drawable, getApplicationContext());
euroMobileManager.setNotificationLargeIcon(R.drawable.your_drawable, getApplicationContext());
euroMobileManager.setNotificationColor("#d1dbbd");
euroMobileManager.setChannelName("Android", getApplicationContext());
euroMobileManager.setPushIntent("com.relateddigital.euromessage.MainActivity", getApplicationContext());
euroMobileManager.sync(this);
|
As soon as an application is installed on the mobile device, the token information of this device is written to the RMC database with the push subscription service. A token; “anonymous”, that is, it is recorded without being paired with any user until the user logs in to the application. In order for this token to be paired with a user, it must be logged in the device and an information identifying the owner of this token (KEY_ID or EMAIL) must be sent to the RMC. This information is located in the "extra": {} block in the push message payload.
In order for your data from the mobile channel to be uploaded to RMC, please pay attention that whatever reference value you have used in your active RMC account (KEY_ID * or E-Mail) comes from the mobile channel with this reference.
*KEY_ID: These are the id values used by the application owner to deduplicate the customer. These can be expressed with different names such as CRMid, userid, customerid, accountid.
Extra parameter in payload sent for user-token matching will take parameters in this way;
Code Block | ||
---|---|---|
| ||
"extra" : {"email" : "umutcan.alparslan@euromsg.com",
"keyID" : "123456"} |
Step 6 - IYS Email Register
If your user is a corporate account, you must send it as a TACIR. To do this, change the value from false to true in registerEmail method.
Code Block | ||
---|---|---|
| ||
EuromessageCallback callback = new EuromessageCallback() { @Override public void success() { Toast.makeText(getApplicationContext(), "REGISTER EMAIL SUCCESS", Toast.LENGTH_LONG).show(); } @Override public void fail(String errorMessage) { String message = "REGISTER EMAIL ERROR "; if(errorMessage != null) { Message message = (Message) intent.getExtras().getSerializable("message"); + errorMessage; String url = message.getUrl();} // Navigate to the corresponding page by using url above. } } |
...
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
}
};
EuroMobileManager.getInstance().registerEmail("test@euromsg.com", EmailPermit.ACTIVE, false, getApplicationContext(), callback); |
Step 7 - Read Report & Navigating
To capture the content of the incoming push notification, you should use the onNewIntent() method as follows. If you have previously entered a class through the EuroMobileManager.setPushIntent() method, the onNewIntent() method must be added to that class. If you did not use the setPushIntent() method, the onNewIntent() method must be added to the launcher activity.
Code Block |
---|
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if (intent.getExtras() != null) { Message message = (Message) intent.getExtras().getSerializable("message"); EuroMobileManager.getInstance().reportRead(intent.getExtras()); String url = message.getUrl(); // Navigate to the corresponding page by using url above. } } |
...