Cyr*_*lin 13 c# xamarin.android android-toast xamarin.forms android-phone-call
我们的目标是在发生呼号时展示祝酒词.当设备被锁定并发生接收呼叫时,这将不起作用.然后在" 锁定的全屏幕进入呼叫视图" 后面可以看到吐司.
我们尝试了不同的approches,结果相同:
允许:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Run Code Online (Sandbox Code Playgroud)
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();
}
}
Run Code Online (Sandbox Code Playgroud)
我们知道一些可以通过" 锁定的全屏嵌入调用视图"成功显示toast的应用程序,但是它们是用java编写的......它们也没有做任何特殊的事情,然后Toast.MakeText(....).
编辑: => PhoneStateListener在后台生命.从服务开始.
服务如何开始?
Intent serviceStart = new Intent(context, typeof(PhoneCallService));
context.StartService(serviceStart);
Run Code Online (Sandbox Code Playgroud)
如何调用PhoneCallDetector?
var phoneCallDetector = m_scope.Resolve<PhoneCallDetector>();
var tm = (TelephonyManager)GetSystemService(TelephonyService);
tm.Listen(phoneCallDetector, PhoneStateListenerFlags.CallState);
Run Code Online (Sandbox Code Playgroud)
谢谢你帮助我:-)
您需要阅读本文并参考此链接。
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
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
213 次 |
最近记录: |