и для обновления UI я использую broadcastreceiver , но on-out-receive не вызывает:
Код: Выделить всё
//**Service side code:**
void SendProgressUpdate(int progress)
{
try
{
var intent = new Intent("com.foreground.app.PROGRESS_UPDATE");
intent.PutExtra("progress", progress);
AndroidCall.Application.Context.SendBroadcast(intent);
}
catch (Exception ex)
{
throw;
}
}
[BroadcastReceiver(Enabled = true, Exported = false,DirectBootAware = true)]
[IntentFilter(new[] { "com.foreground.app.PROGRESS_UPDATE" })]
public class ProgressBroadcastReceiver : BroadcastReceiver
{
public event Action ProgressUpdated;
public override void OnReceive(Context context, Intent intent)
{
if (intent.Action == "com.foreground.app.PROGRESS_UPDATE")
{
int progress = intent.GetIntExtra("progress", 0);
Log.Debug("ProgressBroadcastReceiver", $"Progress received: {progress}");
ProgressUpdated?.Invoke(progress);
}
}
}
//**UI side code**
void OnProgressUpdated(int progress)
{
System.Diagnostics.Debug.WriteLine($"Progress update received: {progress}");
lblProgress.Text = $"Progress: 000%";
// Update UI on main thread
Device.BeginInvokeOnMainThread(() =>
{
// e.g. update a ProgressBar or Label
lblProgress.Text = $"Progress: {progress}%";
});
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... every-minu