내가 자 마린 양식에서 방송 메시지 수신을 구현하기 위해 노력하고 있지만, 모든 메시지를 수신 할 수 있어요 양식, 다음 내 주요 활동 코드방송 수신기가 내가 잘못 무슨 일이 일어나고 있는지 확실하지 않다,
[Activity(Label = "HeloApp.Android", Theme = "@style/MyTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
Connector.Instance.Initialize(this, "151265380086941117", "E862D6D7D70ED2C3729CB24BC3AB40753A52EAB0");
MeasurementReceiver heartRateRec = new MeasurementReceiver();
RegisterReceiver(heartRateRec, new IntentFilter("com.worldgn.connector.HR_MEASUREMENT"));
}
}
[BroadcastReceiver(Enabled = true)]
[IntentFilter(new[] { "com.worldgn.connector.HR_MEASUREMENT" })]
public class MeasurementReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
if (intent.Action.Equals("com.worldgn.connector.HR_MEASUREMENT"))
{
var heartRate = intent.GetStringExtra("HR_MEASUREMENT");
}
}
}
입니다
그리고 아래는 제가 xamarin 폼 측면에서 브로드 캐스트 리시버를 시작하는 방법입니다. 나는 브로드 캐스트 리시버가 주어진 시나리오에서 어떻게 작동 할 것인지는 잘 모르겠다. 왜냐하면 나는 처음으로 그것을하고 있기 때문이다.
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class BLEDevices : ContentPage
{
public BLEDevices()
{
InitializeComponent();
}
private void SearchBLE_Clicked(object sender, EventArgs e)
{
Connector.Instance.Scan(new DeviceScanCallBack());
}
private void Disconnect_Clicked(object sender, EventArgs e)
{
Connector.Instance.UnbindDevice();
}
}
public class DeviceScanCallBack : Java.Lang.Object, IScanCallBack
{
public void OnLedeviceFound(DeviceItem p0)
{
Connector.Instance.Connect(p0);
App.Current.MainPage.DisplayAlert("Information", "Device connected successfully.", "Cancel");
//Here i am trying to initiate the broadcast receiver
Connector.Instance.MeasureHR();
}
public void OnPairedDeviceNotFound()
{
App.Current.MainPage.DisplayAlert("Warning", "Please disconnect the device first.", "OK");
}
public void OnScanFinished()
{
}
public void OnScanStarted()
{
}
}
내가 얻으려고하는 것은 디버그 모드에서 OnReceive 메서드를 누르면 모든 문제가 해결됩니다.
도움을 주시면 감사하겠습니다. 감사합니다
나는 당신이 여기 제안하지만 여전히 뭔가가 누락으로 인터페이스를 구현했습니다. – user6352350
'Init (this, bundle)'위에'RegisterReceiver'를 붙이면 어떨까요? –