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 16 Next »

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 17 API Level Test Device

Step 2 - Adding Dependencies

2.1  Please add code block to app/build.gradle (Module: app) 

dependencies {
		implementation 'com.euromsg:euromsg:$euromessage_version'
	}

apply plugin: 'com.huawei.agconnect'
apply plugin: 'com.google.gms.google-services'
Euromessage Version

 

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/'}
    }
}

Don’t forget to click sync.

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

 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() {

        FirebaseInstanceId.getInstance().getInstanceId()
                .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
                    @Override
                    public void onComplete(@NonNull Task<InstanceIdResult> task) {

                        if (!task.isSuccessful()) {
                            return;
                        }

                        String token = task.getResult().getToken();
                        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 = 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();
        }

    }
}	       


Adım 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.

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

Extra parameter in payload sent for user-token matching will take parameters in this way;

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

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

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    if (intent.getExtras() != null) {
        Message message = (Message) intent.getExtras().getSerializable("message");
        handlePush(message, intent);
    }
}

    @Override
    protected void onResume() {
        super.onResume();

        if (getIntent().getExtras() != null && EuroMobileManager.getInstance().getNotification(getIntent()) != null) {
            EuroMobileManager.getInstance().reportRead(getIntent().getExtras());
        }
    }
    
private void handlePush(Message message, Intent intent) {
    EuroMobileManager.getInstance().reportRead(intent.getExtras());
    EuroMobileManager.getInstance().removeIntentExtra(intent);
    // Navigate the corresponding page here by using message
}

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