我们的目标是在打来电话时举杯敬酒。 当设备锁定且有来电时这将不起作用。然后,在锁定的全屏来电视图中后会看到吐司>。
我们尝试了不同的审批方式,结果相同:
权限:
<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();
}
}
我们知道有些应用程序可以在“ 锁定的全屏来电视图”上成功显示烤面包,但是它们是用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);
感谢您的帮助:-)
答案 0 :(得分: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
}