Show Toast over PhoneScreen in LockState
Asked Answered
S

1

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

Salesclerk answered 9/7, 2018 at 9:36 Comment(4)
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.Cabernet
The App is called "local.ch" (play.google.com/store/apps/…). 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...Salesclerk
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.Collimore
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 ?Salesclerk
B
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

Bibb answered 17/7, 2018 at 12:36 Comment(2)
Thanks for your answer. I want to show a toast, not a notification :(Salesclerk
I found out, my approach is working on Samsung Galaxy S6 with Android 8.0 but it's not working on XIAOMI M1 or Pixel2, strange....Salesclerk

© 2022 - 2024 — McMap. All rights reserved.