...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
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.github.euromsgrelateddigital:euromsgeuromessage-android:$euromessage_version' } apply plugin: 'com.huawei.agconnect' apply plugin: 'com.google.gms.google-services' |
...
Click to know the latest version: Euromessage Android GitHub
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
Code Block | ||
---|---|---|
| ||
<application android:name=".MainApplication" android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > |
...
If you are using WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions in your application, you need to add the following line to your AndroidManifest.xml file in the <application tag
Code Block | ||
---|---|---|
| ||
android:requestLegacyExternalStorage="true" |
...
Step 4 - Add other codes
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; } } String token = task.getResult(); String token = task.getResult().getToken(); 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 Thread() { @Override public void run() { try { String appId = AGConnectServicesConfig.fromContextnew AGConnectOptionsBuilder().build(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); } } catch }.start(); (ApiException e) { } |
...
Code Block | ||
---|---|---|
| ||
if (!EuroMobileManager.checkPlayService(getApplicationContext())) { Log.e("Huawei Token", "Getting the setHuaweiTokenToEuromessage(); token failed! " + e); } } |
Final code:
Code Block | ||
---|---|---|
| ||
public class MainApplication extends Application } }.start(); } |
OR
Code Block |
---|
private void setHuaweiTokenToEuromessage() { private final String FIREBASE_APP_ALIAS = "euromessage-android"; new Thread() { private final String HUAWEI_APP_ALIAS = "euromsg-huawei"; @Override 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") {; final String token setHuaweiTokenToEuromessage(= HmsInstanceId.getInstance(getApplicationContext()).getToken(appId, "HCM"); } } } |
...
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.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.
Extra parameter in payload sent for user-token matching will take parameters in this way;
Code Block | ||
---|---|---|
| ||
"extra" : {"email" : "melike.yildirim@euromsg.com",euroMobileManager.subscribe(token, getApplicationContext()); 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();
}
}
} |
4.4 Getting Push Notification Permission(Android 13 or higher)
Validate your SDK versions. Compile and target SDK version should be at least 33.
Code Block | ||
---|---|---|
| ||
android {
compileSdkVersion "33"
defaultConfig {
targetSdkVersion "33"
}
} |
Use the below Euromessage method to trigger the native prompt to request push notification permission.
Code Block | ||
---|---|---|
| ||
EuroMobileManager.getInstance().requestNotificationPermission(activity); |
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 + 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 did not use the setPushIntent() method, the onNewIntent() method must be added to the launcher activity.
About read reports:
If you are using SDK version 5.1.3 or higher, you have to send the read report yourself. It cannot be shipped by the SDK due to restrictions with Android 12.
Code Block | ||
---|---|---|
| ||
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if(intent != null) { Bundle bundle = intent.getExtras(); if (bundle != null) { Message message = (Message) intent.getExtras().getSerializable("message"); if(message != null) { // Send open report if(EuroMobileManager.getInstance() == null) { EuroMobileManager.init(googleAppAlias, huaweiAppAlias, getApplicationContext()).sendOpenRequest(message); } else { EuroMobileManager.getInstance().sendOpenRequest(message); } } else { // Carousel push notification : an item was clicked String itemClickedUrl = bundle.getString("CarouselItemClickedUrl"); if(itemClickedUrl != null && !itemClickedUrl.equals("")) { try { Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(itemClickedUrl)); viewIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(viewIntent); } catch (Exception e) { e.printStackTrace(); } } } } "keyID" :} "123456"} |
...
If you are using SDK version 5.0 - 5.1.2, SDK will automatically send read reports. That's why you shouldn't call the reportRead() method. (This method is not already available in SDK versions 5.0+.)
Code Block | ||
---|---|---|
| ||
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if super.onNewIntent(intent); (intent.getExtras() != null) { Message message if= (Message) intent.getExtras().getSerializable("message") != null) { EuroMobileManager.getInstance().reportRead(intent.getExtras()); } } @Override protected void onResume() { super.onResume(); if (getIntent().getExtras() != null &&; String url = message.getUrl(); // Navigate to the corresponding page by using url above. } } |
If you are using an SDK version below 5.0, you should call the reportRead() method as below for the read reports to be reflected on the panel.
Code Block |
---|
@Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); if (intent.getExtras() != null) { Message message = (Message) intent.getExtras().getSerializable("message"); EuroMobileManager.getInstance().getNotificationreportRead(getIntentintent.getExtras()) != null) {; String url = message.getUrl(); EuroMobileManager.getInstance().reportRead(getIntent().getExtras()); } // Navigate to the corresponding page by using url above. } } |
Proposal :
If the push notification reaches your device in debug mode when sending campaigns from RMC, but not in release mode, take a look at your problems with pro-guard in your application.
...