Skip to content

Add example of how to integrate clevertap-geofence-sdk #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CTExample/Assets/Plugins/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<!-- Permissions for Geofence -->
<!--
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
-->

<uses-feature android:glEsVersion="0x00020000" />

<uses-feature
Expand All @@ -37,6 +44,7 @@
android:label="@string/app_name"
android:theme="@style/UnityThemeSelector">

<!-- For Geofence example use anroid:name="com.clevertap.unity.example.GeofenceExampleActivity" -->
<activity
android:name="com.clevertap.unity.CleverTapOverrideActivity"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale"
Expand Down
6 changes: 6 additions & 0 deletions CTExample/Assets/Plugins/Android/mainTemplate.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ dependencies {
// Optional CleverTap push templates
implementation 'com.clevertap.android:push-templates:1.2.4'

// Optional CleverTap Geofence libraries
// implementation 'com.clevertap.android:clevertap-geofence-sdk:1.3.0'
// implementation 'com.google.android.gms:play-services-location:21.0.0'
// implementation 'androidx.work:work-runtime:2.7.1' // required for FETCH_LAST_LOCATION_PERIODIC
// implementation 'androidx.concurrent:concurrent-futures:1.1.0' // required for FETCH_LAST_LOCATION_PERIODIC

// Optional AndroidX Media3 Libraries for CleverTap Audio/Video Inbox Messages.
// Audio/Video messages will be dropped without these dependencies
// implementation "androidx.media3:media3-exoplayer:1.1.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.clevertap.unity.example;

import static com.clevertap.android.geofence.Logger.DEBUG;

import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.clevertap.android.geofence.CTGeofenceAPI;
import com.clevertap.android.geofence.CTGeofenceSettings;
import com.clevertap.android.geofence.interfaces.CTGeofenceEventsListener;
import com.clevertap.android.geofence.interfaces.CTLocationUpdatesListener;
import com.clevertap.android.sdk.CleverTapAPI;
import com.clevertap.unity.CleverTapOverrideActivity;

import org.json.JSONObject;

public class GeofenceExampleActivity extends CleverTapOverrideActivity implements CTGeofenceAPI.OnGeofenceApiInitializedListener, CTGeofenceEventsListener, CTLocationUpdatesListener {

private CTGeofenceAPI geofenceAPI;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
geofenceAPI = CTGeofenceAPI.getInstance(getApplicationContext());
geofenceAPI.setOnGeofenceApiInitializedListener(this);
geofenceAPI.setCtGeofenceEventsListener(this);
geofenceAPI.setCtLocationUpdatesListener(this);
}

@Override
protected void onResume() {
super.onResume();
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION
) == PackageManager.PERMISSION_GRANTED) {
initGeofenceApi();
} else {
ActivityCompat.requestPermissions(
this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
1
);
}
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
initGeofenceApi();
}
}

private void initGeofenceApi() {
CleverTapAPI cleverTapAPI = CleverTapAPI.getDefaultInstance(this);
CTGeofenceSettings ctGeofenceSettings = new CTGeofenceSettings.Builder()
.setLogLevel(DEBUG)
.build();
geofenceAPI.init(ctGeofenceSettings, cleverTapAPI);
}

@Override
public void OnGeofenceApiInitialized() {
Toast.makeText(this, "Geofence Api Initialized", Toast.LENGTH_SHORT).show();
}

@Override
public void onGeofenceEnteredEvent(JSONObject geofenceEnteredEventProperties) {
Toast.makeText(this, "Geofence Entered", Toast.LENGTH_SHORT).show();
}

@Override
public void onGeofenceExitedEvent(JSONObject geofenceExitedEventProperties) {
Toast.makeText(this, "Geofence Exited", Toast.LENGTH_SHORT).show();
}

@Override
public void onLocationUpdates(Location location) {
Toast.makeText(this, "Location update " + location, Toast.LENGTH_SHORT).show();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.