Xamarin Android initialization for Mapp Cloud

  1. Create a new Xamarin Android application in Visual Studio/Xamarin Studio

  2. Add.dll into your project: open the Solution Explorer →  right-click on the References → Choose Add Reference-> Click on Browse option  (on the bottom right angle) →  browse the binding file (.dll), and click OK

  3. Add Google Play Service into your project: right-click on Packages → Add Google Play Service → select  InstanceIDMessagingIdentityLocation and click Add Packages

  4. Mapp Android library requires the following dependencies (those dependencies can be downloaded using NuGet): 

    1. Google.Gson

    2. Xamarin.Android.Glide 

    3. Xamarin.Google.Dagger

    4. Xamarin.AndroidX.Media

  5. Add the Google Service Json file

    1. Copy google-services.json to the project folder

    2. Add google-services.json to the app project

    3. Right-click google-services.json

    4. Set the Build Action to GoogleServicesJson 

       

  6. The project must be on AndroidX and use Dex Compiler D8

  7. Create a class that extends Application. At the beginning of class import binding application:  

    using Appoxee; using Android.Gms.Common; using Appoxee.Push;


    And add the following code snippet: 

    [Service] [IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })] [Application] public class MappApp : Application { const string TAG = "MyFirebaseIIDService"; public MappApp(IntPtr handle, JniHandleOwnership ownerShip) : base(handle, ownerShip) { } public override void OnCreate() { base.OnCreate(); AppoxeeOptions opt = new AppoxeeOptions(); opt.SdkKey = "SDK_KEY"; opt.GoogleProjectId = "GOOGLE_PROJECT_ID"; opt.CepURL = "CEP_URL"; opt.AppID = "APP_ID"; opt.TenantID = "TENANT_ID"; opt.NotificationMode = NotificationModes.BackgroundAndForeground; opt.Server = AppoxeeOptions.ServerForUsing.Test; Appoxee.EngageApoxee.Engage(this, opt); // } public bool IsPlayServicesAvailable() { int resultCode = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.Success) { if (GoogleApiAvailability.Instance.IsUserResolvableError(resultCode)) Android.Util.Log.Debug(TAG, GoogleApiAvailability.Instance.GetErrorString(resultCode)); else { Android.Util.Log.Debug(TAG, "This device is not supported"); //Finish(); } return false; } else { Android.Util.Log.Debug(TAG, "Google Play Services is available."); return true; } } }


    NotificationMode is an enum and you can choose one of three options:

    • BACKGROUND_ONLY - notification will show only when an app is closed or in idle mode.

    • BACKGROUND_AND_FOREGROUND - notification will show every time when a push notification comes.

    • SILENT_ONLY - notification never shows on the device.

    If you don't choose one of these options, by default is BACKGROUND_ONLY.  

    AppoxeeOptions.The server is an enum and you can choose one of four options:

    • L3

    • EMC

    • CROC

    • TEST

    An account manager will provide you info which one you should use in your application (L3, EMC or CROC). If you don't choose one of these options, by default is a TEST. 
    Our developers use TEST for development purposes and you shouldn't use this one.

  8. In AndroidManifest.xml mandatory add internet permission:

    <uses-permission android:name="android.permission.INTERNET" />


    Within application tag you must add a receiver for push notification:

     

  9. Add a callback when Engage finished all initialization, the callback will be called when Engaged is up and ready, or if server hand-shaking is failed.