Start GroundSage Subscription and Location Update with Android

For receiving the GroundSage crowd density data from the system, you will need to call addGroundSageListener for registering the GroundSage data subscription, and then call startSubcription to start the GroundSage data update and the location update. The application will only receive regular updates of the GroundSage data when the location update indicates that the user is within the vicinity of the venue. When the user enters the vicinity of the venue, onEnterDensityRegion will get called and the application will receive GroundSage data regularly via onUpdateDensity. When the user leaves the vicinity of the venue, onExitDensityRegion will get called and the application won't receive further GroundSage data via onUpdateDensity.

As startSubscription will also initiate location update, typically you will need to call registerLocationListener for handling the callback of location update. Please refer to the example code for registering callbacks and starting subscription.


Kotlin
class MainActivity : AppCompatActivity(), IAGSManagerListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        subscriptionVenueDensityExample()
    }
    
    fun subscriptionVenueDensityExample() {
        val sdk = IAGSManager.getInstance(this)
        // set your api key and api secret.
        sdk.setApiKey(
            "SET YOUR API KEY HERE",
            "YOUR SECRET KEY HERE"
        )
        sdk.addGroundSageListener(this)
        sdk.registerLocationListener(this)
        // start subscription to request venue density
        sdk.startSubscription()
    } 

    override fun onUpdateDensity(venueDensity: IAGSVenueDensity?) {
        println(String.format("update density = %s", venueDensity))
    }

    override fun onEnterDensityRegion(region: IARegion) {
        println(String.format("Enter region = %s", region))
    }

    override fun onExitDensityRegion(region: IARegion) {
        println(String.format("Exit region = %s", region))
    }
}


Java

public class MainActivity extends AppCompatActivity implements IAGSManagerListener {
    private final String TAG = MainActivity.class.getSimpleName();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        subscriptionVenueDensityExample();
    }

    void subscriptionVenueDensityExample() {
        IAGSManager sdk = IAGSManager.Companion.getInstance(this);
        // set your api key and api secret.
        sdk.setApiKey(
            "SET YOUR API KEY HERE",
            "YOUR SECRET KEY HERE"
        );
        sdk.addGroundSageListener(this);
        sdk.registerLocationListener(this);
        // start subscription to request venue density
        sdk.startSubscription();
    }

    @Override
    public void onUpdateDensity(@Nullable IAGSVenueDensity venueDensity) {
        Log.d(TAG, String.format("Update density = %s", venueDensity));
    }

    @Override
    public void onEnterDensityRegion(@NotNull IARegion region) {
        Log.d(TAG, String.format("Enter region = %s", region));
    }

    @Override
    public void onExitDensityRegion(@NotNull IARegion region) {
        Log.d(TAG, String.format("Exit region = %s", region));
    }
}