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:
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 :-)
You need to read this and also refer this link.
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS = "lock_screen_allow_private_notifications"
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS = "lock_screen_show_notifications"
int ShowAll = Settings.Secure.getInt(getContentResolver(),"lock_screen_allow_private_notifications", -1);
int NotificationEnable = Settings.Secure.getInt(getContentResolver(),"lock_screen_show_notifications", -1);
if(ShowAll > 0 && NotificationEnable > 0){
//post notification
}
Refer this Also Section:-Lock screen notifications
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With