Skip to content

Instantly share code, notes, and snippets.

@tugcearar
Created September 10, 2020 15:01
Show Gist options
  • Save tugcearar/25e83e7db4ea099d73d00d1c89aab3d9 to your computer and use it in GitHub Desktop.
Save tugcearar/25e83e7db4ea099d73d00d1c89aab3d9 to your computer and use it in GitHub Desktop.
[BroadcastReceiver(Enabled = true)]
[IntentFilter(new[] { "com.huawei.hms.geofence.ACTION_PROCESS_ACTIVITY" })]
class GeofenceBroadcastReceiver : BroadcastReceiver
{
public static readonly string ActionGeofence = "com.huawei.hms.geofence.ACTION_PROCESS_ACTIVITY";
public override void OnReceive(Context context, Intent intent)
{
if (intent != null)
{
var action = intent.Action;
if (action == ActionGeofence)
{
GeofenceData geofenceData = GeofenceData.GetDataFromIntent(intent);
if (geofenceData != null)
{
Toast.MakeText(context, "Geofence triggered: " + geofenceData.ConvertingLocation.Latitude +"\n" + geofenceData.ConvertingLocation.Longitude + "\n" + geofenceData.Conversion.ToConversionName(), ToastLength.Long).Show();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment