In Android project, in file MainApplication.cs, init Android SDK :
publicoverridevoidOnCreate(){ base.OnCreate();RegisterActivityLifecycleCallbacks(this); // A great place to initialize Xamarin.Insights and Dependency Services!XAPM.Droid.Impl.Initializer.Init();}
Now, you can launch the app and verify that the badge appears.
Connection client
Use the method APMUIServicesUser UserClientConnect() for connect automatically your user to app’s miles.
If no account exist with this informations, the server create automatically this account.
This method needs : « email », « userID » and « optIn »
« email » is the email of user
« userID » is a unique identifier in your database
« optIn » is the RGPD OptIn
If you don’t want pass the email, you can build a encrypted email with the userID, for example : 123456789@appsmiles.f
(123456789 is the userID)
– app’s miles account and client account not connected, so, redirect user to your process login/register account
– app’s miles account not connected and client account connected, so, connect app’s miles account with method userClientConnect
– app’s miles account and client account connected, so, nothing
publicpartialclassMainPage:ContentPage{ //Declare a object of APMOnboardingUtils in your classprivateAPMOnboardingUtils mOnboardingUtils;publicMainPage() {InitializeComponent();APM.RefreshSDK(); mOnboardingUtils =newAPMOnboardingUtils(delegate () {Debug.WriteLine("APMOnboardingUtils.OK"); //Get the event OnboardingButtonOkClickedbool clientAccountConnected =true;if (clientAccountConnected) //TODO: check if account client is connected { //Account client is connectedDictionary<string,object> user =APM.GetUser();if (user !=null&&user["userToken"] !=null&&!user["userToken"].Equals("")) { //Client account connected and app's miles account connectedDebug.WriteLine("Client account connected and app's miles account connected"); }else { //Client account connected --> need to connect app's miles accountDebug.WriteLine("Client account connected --> need to connect app's miles account"); //ApmConnection(); } }else { //TODO show screen login/create account } },delegate () {Debug.WriteLine("APMOnboardingUtils.Later"); },delegate () {Debug.WriteLine("APMOnboardingUtils.Never"); }); //Listen events of onboardingmOnboardingUtils.RegisterNotifications(); }}
Call unregister when the screen is in pause:
//Unlisten events of onboardingmOnboardingUtils.unregister(this);