简体   繁体   English

Xamarin.Andriod:如何接收消息和显示通知

[英]Xamarin.Andriod: How to Receive message and show Notification

I would like to show a notification when Received SMS... but can't do it because I can't change to static 'StartService(intente);' 我想在收到短信时显示通知...但是无法执行,因为我无法更改为静态“ StartService(intente);” what should I change in my code? 我应该更改我的代码吗?

public override void OnReceive(Context context, Intent intent)
{
    if (intent.HasExtra("pdus"))
    {
        var smsArray = (Java.Lang.Object[])intent.Extras.Get("pdus");
        string address = "";
        string message = "";
        foreach (var item in smsArray)
        {
            var sms = SmsMessage.CreateFromPdu((byte[])item);
            _message = sms.MessageBody;
            _sender = sms.OriginatingAddress;
        }
        if (_sender.Contains(txtCarNumber.Text.Substring(1, 10)))
        {
            MsgReceived(_message, context);
            SwitchClass.StopProgress();
            // For Show on Notification
            var intente = new Intent(context, typeof(NotificationsCommand));
            intente.PutExtra("Command", "TurnOff");
            StartService(intente); //=> here compiler say should be Static
                                   // End
        }
    }
}

Have a try with : 尝试一下:

context.StartService(intente);

Here is a discussion for reference. 这是供参考的讨论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Xamarin.Andriod:如何从收件箱中删除或标记为已读邮件(对话) - Xamarin.Andriod: How to Delete or mark as read message(conversation) From Inbox 如果在后台Android Xamarin中,获取通知消息以在前台显示我的应用程序 - Getting a notification message to show my app in foreground if in background Android Xamarin 如何在通知区域中显示带有图标的消息 - How to show a message with icon in the notification area 如何在应用程序WPF关机时显示通知消息 - How to show Notification Message on Shutdown of Application WPF 如何在我的 xamarin andriod 中将 TextView.Text 保存为文本文件 - How to save the TextView.Text as text file in my xamarin andriod 如何发送和接收通知 - How to send and receive notification 如何将标签更改为布局,与在Xamarin Forms上显示通知相同? - How to change label to layout as same as show Notification on Xamarin Forms? 当我的 Xamarin Android 应用程序停止时,如何接收推送通知? - How can I receive a Push Notification when my Xamarin Android app is stopped? Xamarin Forms 消息中心没有收到消息 - Xamarin Forms MessagingCenter does not receive message 如何在 Winform 中显示某种通知(toast 消息)? - How to show kind of notification (toast message) within Winform?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM