我们的目标是在来电发生时表示祝酒。当设备被锁定并且有来电时,这将不起作用。然后在“锁定的全屏来电视图”后面可以看到吐司。
我们尝试了不同的方法,结果相同:
- 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);
谢谢你帮助我:-)