0
我需要生成一個通知時,應用程序在後臺,但我不知道如何開始廣播接收器如何在Xamarin中使用C#中的BroadcastReceiver?
我需要生成一個通知時,應用程序在後臺,但我不知道如何開始廣播接收器如何在Xamarin中使用C#中的BroadcastReceiver?
有兩種方式:
1. LocalBroadcastManager
將發送消息只有您的應用程序
Intent message = new Intent("com.xamarin.example.TEST");
// If desired, pass some values to the broadcast receiver.
intent.PutExtra("key", "value");
Android.Support.V4.Content.LocalBroadcastManager.GetInstance(this).SendBroadcast(message);
2. Context.SendBroadcast
方法將消息發送到整個系統
Intent message = new Intent("com.xamarin.example.TEST");
// If desired, pass some values to the broadcast receiver.
intent.PutExtra("key", "value");
context.SendBroadcast(intent);
from Xamarin guide
非常感謝!它幫助了很多。 –
Xamarin有關於此主題的完整指南:https://developer.xamarin.com/guides/android/application_fundamentals/broadcast-receivers/ – SushiHangover