Skip to content

Location Based Notifications

The SDK automatically includes the permission for location access in its manifest (necessary for beacon and geofence monitoring).

When targeting API level 23+, you should ask for ACCESS_FINE_LOCATION permission at runtime with our drop-in permission dialog:

// You can choose an arbitrary request code
private val NEAR_PERMISSION_REQUEST: Int = 1000

startActivityForResult(
        NearITUIBindings.getInstance(this@YourActivity)
                .permissionsIntentBuilder()
                .build(),
        NEAR_PERMISSION_REQUEST);

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    if (requestCode == NEAR_PERMISSION_REQUEST) {
        if (resultCode == Activity.RESULT_OK) {
            Toast.makeText(this, "Result OK", Toast.LENGTH_SHORT).show()
            NearItManager.getInstance().startRadar()
        } else Toast.makeText(this, "Result KO", Toast.LENGTH_SHORT).show()
    }
}
// You can choose an arbitrary request code
 private static final int NEAR_PERMISSION_REQUEST = 1000;

 startActivityForResult(
        NearITUIBindings.getInstance(YourActivity.this)
                .permissionsIntentBuilder()
                .build(),
        NEAR_PERMISSION_REQUEST);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == NEAR_PERMISSION_REQUEST) {
        if (resultCode == Activity.RESULT_OK) {
            // start radar
            NearItManager.getInstance().startRadar();
        } else {
            // permissions not fully granted, should not start radar
        }
    }
}

This will produce this behaviour:

NearIT-UI permissions request demo on Android

If you need to customize the permissions request UI/UX, please read this section.

You are now able to test this type of notifications! You should create a recipe in your sandbox environment and see that you will receive a notification. If were already inside the geofence you just created, switch off and on again your location settings.


WARNING: If you experience build or runtime problems with google play services components, make sure to include the right version of any gms dependency in your app. Example:

implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.android.gms:play-services-location:16.0.0'

Conflicting play services version may result in compile-time and run-time errors.