Skip to content

fix: android PhoneCallManager #19638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
using Android.Runtime;
using Android.Telephony;

namespace Windows.ApplicationModel.Calls
{
internal class CallCallback : TelephonyCallback, TelephonyCallback.ICallStateListener
{
public void OnCallStateChanged(int state)
{
PhoneCallManager.RaiseCallStateChanged();
}
}
}
24 changes: 23 additions & 1 deletion src/Uno.UWP/ApplicationModel/Calls/PhoneCallManager.Android.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Android.Content;
using Android.OS;
using Android.Telephony;
Expand All @@ -20,11 +21,32 @@
"PhoneCallManager was used too early in the application lifetime. " +
"Android app context needs to be available.");
}

_telephonyManager = (TelephonyManager)ContextHelper.Current
.GetSystemService(Context.TelephonyService);

#pragma warning disable CS0618 // TelephonyManager is obsolete in API 31
#pragma warning disable CA1422 // Validate platform compatibility
if (Build.VERSION.SdkInt < BuildVersionCodes.S)
{
_telephonyManager.Listen(new CallStateListener(), PhoneStateListenerFlags.CallState);
}
else
{
RegisterTelephonyCallbackAsync();
}
#pragma warning restore CA1422 // Validate platform compatibility
#pragma warning restore CS0618 // TelephonyManager is obsolete in API 31
}

private static async void RegisterTelephonyCallbackAsync()

Check warning on line 42 in src/Uno.UWP/ApplicationModel/Calls/PhoneCallManager.Android.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Uno.UWP/ApplicationModel/Calls/PhoneCallManager.Android.cs#L42

Return 'Task' instead.
{
#pragma warning disable CS0618 // TelephonyManager is obsolete in API 31
#pragma warning disable CA1422 // Validate platform compatibility
_telephonyManager.Listen(new CallStateListener(), PhoneStateListenerFlags.CallState);
if (await Extensions.PermissionsHelper.TryGetPermission(CancellationToken.None, Android.Manifest.Permission.ReadPhoneState))
{
_telephonyManager.RegisterTelephonyCallback(ContextHelper.Current.MainExecutor, new CallCallback());
}
#pragma warning restore CA1422 // Validate platform compatibility
#pragma warning restore CS0618 // TelephonyManager is obsolete in API 31
}
Expand Down
Loading