diff --git a/BranchSDK/Platforms/Android/BranchAndroid.cs b/BranchSDK/Platforms/Android/BranchAndroid.cs index 7519972..d823cba 100644 --- a/BranchSDK/Platforms/Android/BranchAndroid.cs +++ b/BranchSDK/Platforms/Android/BranchAndroid.cs @@ -156,50 +156,55 @@ public override void InitSession(IBranchBUOSessionInterface callback) } public void ReInitSession(Intent intent, IBranchSessionInterface callback, Activity activity) - { - if (intent?.Data != null) - { - callbacksList.Clear(); - BranchSessionListener obj = new BranchSessionListener(callback); - callbacksList.Add(obj as Object); - - Console.WriteLine("BRANCHSDK .NET MAUI: ReInitSession Activity: " + activity); - - intent.PutExtra("branch_force_new_session", true); - activity.Intent = intent; - - AndroidNativeBranch.SessionBuilder(activity) - .WithCallback(obj) - .WithData(intent.Data) - .ReInit(); - } - else - { - Console.WriteLine("BRANCHSDK .NET MAUI: ReInitSession: No URL in intent: " + intent); - } - } - - public void ReInitSession(Intent intent, IBranchBUOSessionInterface callback, Activity activity) - { - if (intent?.Data != null) - { - callbacksList.Clear(); - BranchBUOSessionListener obj = new BranchBUOSessionListener(callback); - callbacksList.Add(obj as Object); - - intent.PutExtra("branch_force_new_session", true); - activity.Intent = intent; - - AndroidNativeBranch.SessionBuilder(activity) - .WithCallback(obj) - .WithData(intent.Data) - .ReInit(); - } - else - { - Console.WriteLine("BRANCHSDK .NET MAUI: ReInitSession: No URL in intent: " + intent); - } - } + // public void ReInitSession(Intent intent, IBranchSessionInterface callback, Activity activity) + // { + // if (intent?.Data != null) + // { + // callbacksList.Clear(); + // BranchSessionListener obj = new BranchSessionListener(callback); + // callbacksList.Add(obj as Object); + + // Console.WriteLine("BRANCHSDK .NET MAUI: ReInitSession Activity: " + activity); + + // intent.PutExtra("branch_force_new_session", true); + // activity.Intent = intent; + + // CurrActivity = activity; + + // AndroidNativeBranch.SessionBuilder(activity) + // .WithCallback(obj) + // .WithData(intent.Data) + // .ReInit(); + // } + // else + // { + // Console.WriteLine("BRANCHSDK .NET MAUI: ReInitSession: No URL in intent: " + intent); + // } + // } + + // public void ReInitSession(Intent intent, IBranchBUOSessionInterface callback, Activity activity) + // { + // if (intent?.Data != null) + // { + // callbacksList.Clear(); + // BranchBUOSessionListener obj = new BranchBUOSessionListener(callback); + // callbacksList.Add(obj as Object); + + // intent.PutExtra("branch_force_new_session", true); + // activity.Intent = intent; + + // CurrActivity = activity; + + // AndroidNativeBranch.SessionBuilder(activity) + // .WithCallback(obj) + // .WithData(intent.Data) + // .ReInit(); + // } + // else + // { + // Console.WriteLine("BRANCHSDK .NET MAUI: ReInitSession: No URL in intent: " + intent); + // } + // } public override void NotifyNativeInit() { diff --git a/BranchSDK/Platforms/Android/BranchAndroidLifeCycleHandler.cs b/BranchSDK/Platforms/Android/BranchAndroidLifeCycleHandler.cs index 85ea16d..7557347 100644 --- a/BranchSDK/Platforms/Android/BranchAndroidLifeCycleHandler.cs +++ b/BranchSDK/Platforms/Android/BranchAndroidLifeCycleHandler.cs @@ -30,12 +30,14 @@ public void OnActivityPaused(Activity activity) { } public void OnActivityStarted(Activity activity) { + Console.WriteLine("BranchSDK .NET MAUI: OnActivityStarted: " + activity.LocalClassName); BranchAndroid.getInstance().CurrActivity = activity; - IncreaseActivityCounter (activity); + IncreaseActivityCounter(activity); } public void OnActivityStopped(Activity activity) { + Console.WriteLine("BranchSDK .NET MAUI: OnActivityStopped: " + activity.LocalClassName); DecreaseActivityCounter(); } @@ -43,10 +45,13 @@ private void IncreaseActivityCounter(Activity activity) { if (activeCounter == 0) { - if (callback != null) { - BranchAndroid.getInstance ().InitSession (callback); - } else if (callbackBUO != null) { - BranchAndroid.getInstance ().InitSession (callbackBUO); + if (callback != null) + { + BranchAndroid.getInstance().InitSession(callback); + } + else if (callbackBUO != null) + { + BranchAndroid.getInstance().InitSession(callbackBUO); } } @@ -55,7 +60,8 @@ private void IncreaseActivityCounter(Activity activity) private void DecreaseActivityCounter() { - if (activeCounter > 0) { + if (activeCounter > 0) + { activeCounter--; } } diff --git a/BranchSDK/Platforms/Android/Helpers/BranchSessionListener.cs b/BranchSDK/Platforms/Android/Helpers/BranchSessionListener.cs index ba0870c..cbd8b91 100644 --- a/BranchSDK/Platforms/Android/Helpers/BranchSessionListener.cs +++ b/BranchSDK/Platforms/Android/Helpers/BranchSessionListener.cs @@ -7,26 +7,33 @@ namespace BranchSDK.Droid { - public class BranchSessionListener: Java.Lang.Object, IO.Branch.Referral.AndroidNativeBranch.IBranchReferralInitListener + public class BranchSessionListener : Java.Lang.Object, IO.Branch.Referral.AndroidNativeBranch.IBranchReferralInitListener { private IBranchSessionInterface callback = null; - public BranchSessionListener(IBranchSessionInterface callback) { + public BranchSessionListener(IBranchSessionInterface callback) + { this.callback = callback; } - public void OnInitFinished (JSONObject data, IO.Branch.Referral.BranchError error) { - if (callback == null) { + public void OnInitFinished(JSONObject data, IO.Branch.Referral.BranchError error) + { + Console.WriteLine("BranchSessionListener: OnInitFinished with data: " + data + " error: " + error); + if (callback == null) + { return; } - if (error == null) { + if (error == null) + { - callback.InitSessionComplete (BranchAndroidUtils.ToDictionary(data)); - } else { + callback.InitSessionComplete(BranchAndroidUtils.ToDictionary(data)); + } + else + { - BranchError err = new BranchError (error.Message, error.ErrorCode); - callback.SessionRequestError (err); + BranchError err = new BranchError(error.Message, error.ErrorCode); + callback.SessionRequestError(err); } } } diff --git a/Timber/Platforms/Android/MainActivity.cs b/Timber/Platforms/Android/MainActivity.cs index 18611a0..9e4e73d 100644 --- a/Timber/Platforms/Android/MainActivity.cs +++ b/Timber/Platforms/Android/MainActivity.cs @@ -33,34 +33,30 @@ protected override void OnCreate(Bundle savedInstanceState) base.OnCreate(savedInstanceState); LogMessage("BRANCHSDK .NET MAUI: MainActivity.OnCreate"); BranchAndroid.Init(this, "key_live_nf8w3l1WBpzWdlC00KsLNdmbuEccK6Yr", this); - - } - - protected override void OnStart() - { - base.OnStart(); - LogMessage("BRANCHSDK .NET MAUI: MainActivity.OnStart"); - //BranchAndroid.Init(this, "key_live_nf8w3l1WBpzWdlC00KsLNdmbuEccK6Yr", this); - Branch.GetInstance().NotifyNativeToInit(); - } protected override void OnNewIntent(Intent intent) { - base.OnNewIntent(intent); LogMessage("BRANCHSDK .NET MAUI: MainActivity.OnNewIntent"); - BranchAndroid.getInstance().ReInitSession(intent, this, this); + base.OnNewIntent(intent); + intent.PutExtra("branch_force_new_session", true); + Intent = intent; } public void InitSessionComplete(Dictionary data) { - LogMessage("BRANCHSDK .NET MAUI: InitSessionComplete: "); - foreach (var key in data.Keys) + if (data == null) { - LogMessage(key + " : " + data[key].ToString()); + LogMessage("BRANCHSDK .NET MAUI: InitSessionComplete with data: null"); + } + else + { + var dataString = string.Join(", ", data.Select(kvp => $"{kvp.Key}: {kvp.Value?.ToString() ?? "null"}")); + LogMessage($"BRANCHSDK .NET MAUI: InitSessionComplete with data: {dataString}"); } } + public void SessionRequestError(BranchError error) { LogMessage("BRANCHSDK .NET MAUI: SessionRequestError: "); diff --git a/Timber/Platforms/Android/MainApplication.cs b/Timber/Platforms/Android/MainApplication.cs index ad7bbbf..9ebc84a 100644 --- a/Timber/Platforms/Android/MainApplication.cs +++ b/Timber/Platforms/Android/MainApplication.cs @@ -7,10 +7,10 @@ namespace Timber; [Application] public class MainApplication : MauiApplication { - public MainApplication(IntPtr handle, JniHandleOwnership ownership) - : base(handle, ownership) - { - } + public MainApplication(IntPtr handle, JniHandleOwnership ownership) + : base(handle, ownership) + { + } public override void OnCreate() { diff --git a/Timber/Platforms/Android/Resources/branch.json b/Timber/Platforms/Android/Resources/branch.json deleted file mode 100644 index 850912d..0000000 --- a/Timber/Platforms/Android/Resources/branch.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "deferInitForPluginRuntime": true - } \ No newline at end of file