コード例 #1
0
ファイル: MainActivity.cs プロジェクト: bassels777/GeoFencing
        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)
            {
            }
        }
コード例 #2
0
 public static async Task <Statuses> RemoveGeofencesAsync(this IGeofencingApi api, GoogleApiClient client, IList <string> geofenceRequestIds)
 {
     return((await api.RemoveGeofences(client, geofenceRequestIds)).JavaCast <Statuses> ());
 }
コード例 #3
0
 public static async Task <Statuses> RemoveGeofencesAsync(this IGeofencingApi api, GoogleApiClient client, Android.App.PendingIntent pendingIntent)
 {
     return((await api.RemoveGeofences(client, pendingIntent)).JavaCast <Statuses> ());
 }
コード例 #4
0
 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> ());
 }