13

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 :-)

Cyril Iselin
  • 596
  • 4
  • 20
  • What Java libraries have you seen, if you link a couple I'll be happy to see if theirs anything that can be converted, I tend to convert Java to Xamarin compatible libraries in my spare time etc. – JoeTomks Jul 16 '18 at 12:02
  • The App is called "local.ch" (https://play.google.com/store/apps/details?id=ch.local.android&hl=de). This App make the same (but written in java) -> BackgroundService -> TelephonyService -> Show Toast. The difference is, the toast from this app is over the locked phone screen... – Cyril Iselin Jul 17 '18 at 07:12
  • There are some 'super-secret' permissions that Google give to certain high profile developers that allow things that mere motals can't do (see recent Facebook articles about capturing screenshots without the user knowing). Perhaps this is one of them. If you can't access the lock page using 'normal' methods, perhaps it's because you aren't supposed be able to. – Neil Jul 17 '18 at 10:58
  • Could be, I don't think they have special rights. I want to show additional informations when the phone is ringing (incomming call), is this sooo crazy special ? – Cyril Iselin Jul 17 '18 at 11:47

1 Answers1

2

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

Hitesh Anshani
  • 1,499
  • 9
  • 19