13

我们的目标是在来电发生时表示祝酒。当设备被锁定并且有来电时,这将不起作用。然后在“锁定的全屏来电视图”后面可以看到吐司。

我们尝试了不同的方法,结果相同:

  • PhoneCallListener / BroadCastReciver
  • 使用带有一些标志(ShowOnLockScreen 等)的新 Intent 而不是敬酒

允许:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

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();
    }
}

我们知道一些应用程序可以在“锁定的全屏来电视图”上成功显示 toast ,但它们是用 java 编写的......它们也没有做任何特别的事情,然后是 Toast.MakeText(....)。

编辑: =>PhoneStateListener 生活在后台。从服务开始。

服务如何启动?

Intent serviceStart = new Intent(context, typeof(PhoneCallService));
context.StartService(serviceStart);

如何调用 PhoneCallDetector?

 var phoneCallDetector = m_scope.Resolve<PhoneCallDetector>();
 var tm = (TelephonyManager)GetSystemService(TelephonyService);
 tm.Listen(phoneCallDetector, PhoneStateListenerFlags.CallState);

谢谢你帮助我:-)

4

1 回答 1

2

您需要阅读此内容并参考此链接。

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
}

另请参阅此部分:-锁定屏幕通知

于 2018-07-17T12:36:53.103 回答