簡體   English   中英

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

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

我想在收到短信時顯示通知...但是無法執行,因為我無法更改為靜態“ StartService(intente);” 我應該更改我的代碼嗎?

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
        }
    }
}

嘗試一下:

context.StartService(intente);

這是供參考的討論

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM