Our goal is to show a toast when an incomming call happens. This won't work when the device is locked and an incomming call occures. Then the toast is visible behind the "locked fullscreen incomming call view".
We tried different approches with like the same result:
- PhoneCallListener / BroadCastReciver
- Instead of a toast, use a new Intent with some Flags (ShowOnLockScreen etc.)
Permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Setup for PhoneCallListener:
public class PhoneCallDetector : PhoneStateListener
{
public override void OnCallStateChanged(CallState state, string incomingNumber)
{
ShowToast(incomingNumber);
base.OnCallStateChanged(state, incomingNumber);
}
private void ShowToast(string phonenumber)
{
Toast toast = Toast.MakeText(Application.Context, phonenumber, ToastLength.Long);
toast.SetGravity(GravityFlags.Center, 0, 0);
toast.Show();
}
}
We know some apps which can display toasts successfully over the "locked fullscreen incomming call view", but they written in java... They also don't do anything special then Toast.MakeText(....).
Edit: => The PhoneStateListener lifes in the background. Started from a service.
How the service get started?
Intent serviceStart = new Intent(context, typeof(PhoneCallService));
context.StartService(serviceStart);
How the PhoneCallDetector is invoked?
var phoneCallDetector = m_scope.Resolve<PhoneCallDetector>();
var tm = (TelephonyManager)GetSystemService(TelephonyService);
tm.Listen(phoneCallDetector, PhoneStateListenerFlags.CallState);
Thanks for helping me :-)