Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 26 Current »

In this page:


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  Add Euromessage to the dependencies in app/build.gradle.

dependencies {
		implementation 'com.github.relateddigital:euromessage-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

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

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<service
            android:name="euromsg.com.euromobileandroid.service.EuroFirebaseMessagingService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

        <service
            android:name="euromsg.com.euromobileandroid.service.EuroHuaweiMessagingService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.huawei.push.action.MESSAGING_EVENT" />
            </intent-filter>
        </service>


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

<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

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.

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());
    }
}


4.1 Getting Token from Firebase Messaging Services

EuroFirebaseMessagingService takes and subscribes token for an application opened for the first time in the onNewToken () method.

To set the tokens you already have, you need to add the following codes

 private void setExistingFirebaseTokenToEuroMessage() {

        FirebaseMessaging.getInstance().getToken()
        .addOnCompleteListener(new OnCompleteListener<String>() {
            @Override
            public void onComplete(@NonNull Task<String> task) {
                if (!task.isSuccessful()) {
                    return;
                }
                String token = task.getResult();
                euroMobileManager.subscribe(token, getApplicationContext());
            }
        });
    }


4.2 Getting Token Huawei Messaging Service

In Huawei, the method of generating tokens are different according to the EMUI version.

EMUI less than 10, subscribe tokens on onNewToken () in EuroHuaweiMessagingService,

On EMUI 10, phones generate tokens as follows. You have to subscribe this generated token to euroMobileManager.

private void setHuaweiTokenToEuromessage() {
    new Thread() {
        @Override
        public void run() {
            try {
                String appId = new AGConnectOptionsBuilder().build(getApplicationContext()).getString("client/app_id");
                final String token = HmsInstanceId.getInstance(getApplicationContext()).getToken(appId, "HCM");

                if(TextUtils.isEmpty(token) || token == null) {
                    Log.e("Huawei Token : ", "Empty token!!!");
                    return;
                }

                euroMobileManager.subscribe(token, getApplicationContext());

                Log.i("Huawei Token", "" + token);

            } catch (ApiException e) {
                Log.e("Huawei Token", "Getting the token failed! " + e);
            }
        }
    }.start();
}

OR

 private void setHuaweiTokenToEuromessage() {

        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");

                    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

if (!EuroMobileManager.checkPlayService(getApplicationContext())) {
            setHuaweiTokenToEuromessage();
        }

Final code:

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.

android {
    compileSdkVersion "33"

    defaultConfig {
        targetSdkVersion "33"
    }
}

Use the below Euromessage method to trigger the native prompt to request push notification permission.

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.

--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;

"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.

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.

@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();
                    }
                }
            }
        }
    }
}
  • 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+.)

@Override
protected void onNewIntent(Intent intent) {
  super.onNewIntent(intent);
  if (intent.getExtras() != null) {
    Message message = (Message) intent.getExtras().getSerializable("message");
    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.

@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.
    }
}

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.

You can add the following codes to proguard-rules.pro;

-keep class com.visilabs.**{*;} #Visilabs
-keep class euromsg.com.**{*;} #Euromessage


Sample Apps :

Euromessage Demo

Shopping Demo- VL&EM

  • No labels