Region

Package: com.salesforce.marketingcloud.pushmodels

Module: Push Models Module v1.0.2

SDK: Salesforce Marketing Cloud Unified SDK 11.0.0

Overview 

Region is a data class representing a geographic or beacon region in the Salesforce Marketing Cloud SDK. It provides functionality for managing both geofence regions and proximity beacon regions.

Declaration 

1data class Region : Parcelable, Comparable<Region>

Inheritance 

  • Implements Parcelable - Enables Android inter-component communication
  • Implements Comparable<Region> - Allows sorting and comparison operations

Constructor 

As a data class, Region has a primary constructor with the following parameters:

1Region(
2    center: LatLon,
3    description: String?,
4    id: String,
5    major: Int,
6    messages: List<Message>,
7    minor: Int,
8    name: String?,
9    proximityUuid: String?,
10    radius: Int,
11    regionType: Int
12)

Properties 

All properties are annotated with @JvmField for direct field access from Java:

PropertyTypeDescription
centerLatLonThe geographic center coordinates of the region
descriptionString?Optional textual description of the region
idStringUnique identifier for the region
majorIntMajor value (typically used for beacon regions)
messagesList<Message>Collection of messages associated with this region
minorIntMinor value (typically used for beacon regions)
nameString?Optional display name for the region
proximityUuidString?Optional UUID for proximity beacons
radiusIntThe radius of the region (in meters for geofences)
regionTypeIntNumeric type identifier for the region (see Companion constants)

Methods 

toJson 

1fun toJson(): JSONObject

Converts the Region object to its JSON representation.

Returns: JSONObject containing the region data

Companion Object 

The Region.Companion object provides constants and factory methods for working with Region instances.

Constants 

REGION_TYPE_FENCE 

1const val REGION_TYPE_FENCE: Int = 1

Constant representing a fence-type region (geofence).

REGION_TYPE_PROXIMITY 

1const val REGION_TYPE_PROXIMITY: Int = 3

Constant representing a proximity-type region (beacon).

Factory Methods 

fromJson 

1@JvmStatic
2fun fromJson(jsonObject: JSONObject?): Region?

Creates a Region object from a JSONObject.

Parameters:

  • jsonObject - A nullable JSONObject containing region data

Returns: A nullable Region instance, or null if creation fails

Annotations: @JvmStatic - Makes this function accessible as a static method from Java

Usage Example 

1// Creating a geofence region
2val geofenceRegion = Region(
3    center = LatLon(latitude = 37.7749, longitude = -122.4194),
4    description = "San Francisco Office",
5    id = "sf-office-001",
6    major = 0,
7    messages = emptyList(),
8    minor = 0,
9    name = "SF Office",
10    proximityUuid = null,
11    radius = 100,
12    regionType = Region.REGION_TYPE_FENCE
13)
14
15// Creating a beacon region
16val beaconRegion = Region(
17    center = LatLon(latitude = 37.7749, longitude = -122.4194),
18    description = "Store Entrance Beacon",
19    id = "beacon-001",
20    major = 1,
21    messages = emptyList(),
22    minor = 2,
23    name = "Entrance",
24    proximityUuid = "12345678-1234-1234-1234-123456789012",
25    radius = 0,
26    regionType = Region.REGION_TYPE_PROXIMITY
27)
28
29// Converting to JSON
30val jsonObject = geofenceRegion.toJson()
31
32// Creating from JSON
33val region = Region.fromJson(jsonObject)

Related Classes 

  • LatLon - Represents geographic coordinates (latitude/longitude)
  • Message - Represents messages associated with a region