示例#1
0
        private void OnConnected()
        {
            if (ContextCompat.CheckSelfPermission(ApplicationContext,
                                                  Manifest.Permission.AccessFineLocation)
                != Permission.Granted)
            {
                ActivityCompat.RequestPermissions(this,
                                                  new[] { Manifest.Permission.AccessFineLocation }, 5);

                // MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION is an
                // app-defined int constant. The callback method gets the
                // result of the request.
            }

            if (ContextCompat.CheckSelfPermission(ApplicationContext,
                                                  Manifest.Permission.AccessMockLocation)
                != Permission.Granted)
            {
                ActivityCompat.RequestPermissions(this,
                                                  new[] { Manifest.Permission.AccessMockLocation }, 6);

                // MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION is an
                // app-defined int constant. The callback method gets the
                // result of the request.
            }

            var requestId = "rid";

            m_geofencingClient = LocationServices.GeofencingApi;
            var geoFence = new GeofenceBuilder()
                           .SetRequestId(requestId)
                           .SetTransitionTypes(Geofence.GeofenceTransitionEnter | Geofence.GeofenceTransitionExit | Geofence.GeofenceTransitionDwell)
                           .SetLoiteringDelay(1000)
                           .SetCircularRegion(37.621313, -122.378955, 1000)
                           .SetExpirationDuration(Geofence.NeverExpire)
                           .SetNotificationResponsiveness(1000)
                           .Build();
            Intent        intent        = new Intent(ApplicationContext, typeof(GeoIntentService));
            PendingIntent pendingIntent = PendingIntent.GetService(ApplicationContext, 0, intent, PendingIntentFlags.UpdateCurrent);

            try
            {
                m_geofencingClient.AddGeofences(m_googleApiClient, GetAddGeofencingRequest(geoFence), pendingIntent);
            }
            catch (IllegalStateException exception)
            {
                Log.Error("tag", exception.ToString());
            }
            catch (Exception exception)
            {
            }
        }
 public static async Task <Statuses> AddGeofencesAsync(this IGeofencingApi api, GoogleApiClient client, IList <IGeofence> geofences, Android.App.PendingIntent pendingIntent)
 {
     return((await api.AddGeofences(client, geofences, pendingIntent)).JavaCast <Statuses> ());
 }