public override void OnCreate() { var options = AirshipConfigOptions.LoadDefaultOptions(this); // Optionally, customize your config options.InProduction = false; options.DevelopmentAppKey = ""; options.DevelopmentAppSecret = ""; UAirship.TakeOff(this, options); //use CustomPushNotificationBuilder to specify a custom layout CustomPushNotificationBuilder nb = new CustomPushNotificationBuilder(); nb.StatusBarIconDrawableId = Resource.Id.icon; //custom status bar icon nb.Layout = Resource.Layout.notification; nb.LayoutIconDrawableId = Resource.Id.icon; //custom layout icon nb.LayoutIconId = Resource.Id.icon; nb.LayoutSubjectId = Resource.Id.subject; nb.LayoutMessageId = Resource.Id.message; PushManager.Shared().NotificationBuilder = nb; PushManager.Shared().IntentReceiver = Class.FromType(typeof(IntentReceiver)); UALocationManager.Shared().IntentReceiver = Class.FromType(typeof(IntentReceiver)); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.location); networkUpdateButton = (Button)FindViewById(Resource.Id.network_update_button); gpsUpdateButton = (Button)FindViewById(Resource.Id.gps_update_button); locationFilter = new IntentFilter(); locationFilter.AddAction(UALocationManager.ActionLocationUpdate); newCriteria = new Criteria(); newCriteria.Accuracy = Accuracy.Fine; networkUpdateButton.Click += delegate { try { UALocationManager.Shared().RecordCurrentLocation(); } catch (ServiceNotBoundException e) { Logger.Debug(e.Message); } catch (RemoteException e) { Logger.Debug(e.Message); } }; gpsUpdateButton.Click += delegate { try { UALocationManager.Shared().RecordCurrentLocation(newCriteria); } catch (ServiceNotBoundException e) { Logger.Debug(e.Message); } catch (RemoteException e) { Logger.Debug(e.Message); } }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.main); locationButton = (Button)FindViewById(Resource.Id.location_button); locationButton.Click += delegate { StartActivity(new Intent(BaseContext, typeof(LocationActivity))); }; // Set up custom preference screen style button Button customPreferencesButton = (Button)FindViewById(Resource.Id.push_custom_preferences_button); customPreferencesButton.Click += delegate { StartActivity(new Intent(BaseContext, typeof(CustomPreferencesActivity))); }; // Set up android built-in preference screen style button Button preferencesButton = (Button)FindViewById(Resource.Id.push_preferences_button); preferencesButton.Click += delegate { StartActivity(new Intent(BaseContext, typeof(PreferencesActivity))); }; boundServiceFilter = new IntentFilter(); boundServiceFilter.AddAction(UALocationManager.GetLocationIntentAction(UALocationManager.ActionSuffixLocationServiceBound)); boundServiceFilter.AddAction(UALocationManager.GetLocationIntentAction(UALocationManager.ActionSuffixLocationServiceUnbound)); apidUpdateFilter = new IntentFilter(); apidUpdateFilter.AddAction(UAirship.PackageName + IntentReceiver.APID_UPDATED_ACTION_SUFFIX); }
void BoundServiceReceiver_OnReceive(Context context, Intent intent) { if (UALocationManager.GetLocationIntentAction(UALocationManager.ActionSuffixLocationServiceBound).Equals(intent.Action)) { locationButton.Enabled = true; } else { locationButton.Enabled = false; } }
private void HandleForegroundLocationPreference(bool foregroundLocationEnabled) { if (foregroundLocationEnabled) { UALocationManager.EnableForegroundLocation(); } else { UALocationManager.DisableForegroundLocation(); } }
private void HandleBackgroundLocationPreference(bool backgroundLocationEnabled) { if (backgroundLocationEnabled) { UALocationManager.EnableBackgroundLocation(); } else { UALocationManager.DisableBackgroundLocation(); } }
void LocationUpdateReceiver_OnReceive(Context context, Intent intent) { if (UALocationManager.GetLocationIntentAction(UALocationManager.ActionSuffixLocationUpdate) == intent.Action) { Location newLocation = (Location)intent.Extras.Get(UALocationManager.LocationKey); String text = string.Format("lat: {0}, lon: {1}", newLocation.Latitude, newLocation.Longitude); Toast.MakeText(UAirship.Shared().ApplicationContext, text, ToastLength.Long).Show(); } }
private void HandleLocation() { if (!UAirship.Shared().AirshipConfigOptions.LocationOptions.LocationServiceEnabled) { return; } bool isLocationEnabledInActivity = locationEnabled.Checked; bool isBackgroundLocationEnabledInActivity = backgroundLocationEnabled.Checked; bool isForegroundLocationEnabledInActivity = foregroundLocationEnabled.Checked; // Set the location enable preference first because it will be used // in the logic to enable/disable background and foreground locations. if (isLocationEnabledInActivity) { UALocationManager.EnableLocation(); } else { UALocationManager.DisableLocation(); } HandleBackgroundLocationPreference(isBackgroundLocationEnabledInActivity); HandleForegroundLocationPreference(isForegroundLocationEnabledInActivity); }