Oracle Android Integration

Bluedot Point SDK can be added as an AAR (recommended) or JAR file to your project.  Follow the links  below for SDK integration  steps:

The development tool or IDE (Integrated Development Environment) for the project is recommended to be Android Studio which can be downloaded from here.

Responsys & Bluedot SDK Integration

Add the following repositories and dependencies to your application’s build.gradle file:

dependencies {
  implementation fileTree(dir: 'libs', include: ['PushIOManager.aar']) // Responsys PushIOManager
  implementation 'com.github.Bluedot-Innovation:PointSDK-Android:1.13.2' //Bluedot Point SDK
  implementation 'com.google.firebase:firebase-core:16.0.8'
  implementation 'com.google.firebase:firebase-messaging:17.6.0'
  ...
}

apply plugin: 'com.google.gms.google-services'

 

The following code example demonstrates registering your app with Responsys SDK & also listen to Blue Dot Point SDK’s ServiceStatusListener & ApplicationNotificationListener:


Starting the Bluedot SDK

The ServiceManager is the entry-point for an app to start using the Bluedot Point SDK. The app must get an instance of the ServiceManager class and invoke sendAuthenticationRequest method by providing the  API key in order to authenticate and start the Bluedot engine. The  API Key can be retrieved from the Bluedot Point Access account. It is important to pass a reference to ServiceStatusListener so the app can receive Service status callbacks from the SDK.

Initializing the Bluedot SDK and requesting for Location permission from the user and setting a foreground notification.

public class MainApplication extends Application implements ServiceStatusListener, ApplicationNotificationListener { 
   ServiceManager mServiceManager; 
   private String apiKey = ""; //API key for the App
 
   // set this to true if you want to start the SDK with service sticky and auto-start mode on boot complete. 
   // Please refer to Bluedot Developer documentation for further information. 
   boolean restartMode = true; 
   @Override public void onCreate() { 
       ...
       //Registering App with Responsys SDK 
       PushIOManager.getInstance(getApplicationContext()).registerApp(); 
       //Set this you need In App Push feature from Responsys 
       PushIOManager.getInstance(this).setInAppFetchEnabled(true); 
       // Initialize Bluedot point sdk 
       initPointSDK(); 
   }

   public void initPointSDK() { 
       int checkPermissionCoarse = ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION); 
       int checkPermissionFine = ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION); 
       if(checkPermissionCoarse == PackageManager.PERMISSION_GRANTED && checkPermissionFine == PackageManager.PERMISSION_GRANTED) { 
             mServiceManager = ServiceManager.getInstance(this); 
             if(!mServiceManager.isBlueDotPointServiceRunning()) { 
                 // Setting Notification for foreground service, required for Android Oreo and above. 
                 // Setting targetAllAPIs to TRUE will display foreground notification for Android versions lower than Oreo 
                 mServiceManager.setForegroundServiceNotification(createNotification(), false); 
                 mServiceManager.sendAuthenticationRequest(apiKey, this, restartMode); 
             } 
       } else { 
            requestPermissions(); 
       } 
   } 

   private void requestPermissions() { 
       Intent intent = new Intent(getApplicationContext(), RequestPermissionActivity.class); 
       intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); 
   }
}

RequestingPermissionActivity for asking for location permissions from the user required for Bluedot SDK functioning:


public class RequestPermissionActivity extends AppCompatActivity {
    final int PERMISSION_REQUEST_CODE = 1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Request permission required for location
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_REQUEST_CODE);
    }
    @Override 
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 
        super.onRequestPermissionsResult(requestCode, permissions, grantResults); 
        switch (requestCode) { 
            case PERMISSION_REQUEST_CODE: 
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 
                ((MainApplication)getApplication()).initPointSDK(); 
            } else { 
                //Permissions denied 
            } 
            break; 
        } 
        finish(); 
    } 
}

Foreground Notification to be displayed on Android Oreo and above for better performance.

private Notification createNotification() {
     String channelId;
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
           channelId = "Bluedot" + getString(R.string.app_name);
           String channelName = "Bluedot Service" + getString(R.string.app_name);
           NotificationChannel notificationChannel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
           notificationChannel.enableLights(false);
           notificationChannel.setLightColor(Color.RED);
           notificationChannel.enableVibration(false);

           NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
           notificationManager.createNotificationChannel(notificationChannel);
           Notification.Builder notification = new Notification.Builder(getApplicationContext(), channelId)
                                              .setContentTitle(getString(R.string.foreground_notification_title))
                                              .setContentText(getString(R.string.foreground_notification_text))
                                              .setStyle(new Notification.BigTextStyle().bigText(getString(R.string.foreground_notification_text)))
                                              .setOngoing(true)
                                              .setCategory(Notification.CATEGORY_SERVICE)
                                              .setSmallIcon(R.mipmap.ic_launcher);
         return notification.build();
     } else {
         NotificationCompat.Builder notification = new NotificationCompat.Builder(getApplicationContext())
                                                  .setContentTitle(getString(R.string.foreground_notification_title))
                                                  .setContentText(getString(R.string.foreground_notification_text))
                                                  .setStyle(new NotificationCompat.BigTextStyle().bigText(getString(R.string.foreground_notification_text)))
                                                  .setOngoing(true)
                                                  .setCategory(Notification.CATEGORY_SERVICE)
                                                  .setPriority(PRIORITY_MAX)
                                                  .setSmallIcon(R.mipmap.ic_launcher);
        return notification.build();
     }
 }

Callbacks
The following mandatory callbacks of the ServiceStatusListener interface must be implemented. 

User should registerUserID on PushIOManager with any customer user-specific ID, by default we are using Bluedot Point SDK InstallRef (It is a unique identifier assigned to a device during installation) in onBlueDotPointServiceStartedSuccess() callback.

@Override public void onBlueDotPointServiceStartedSuccess() { 
   //This is called when BluedotPointService started successfully 
   //Start listening for Check-in/Check-out events from Bluedot SDK 
   mServiceManager.subscribeForApplicationNotification(this); 
   //Register with Installref/or any other ID with Responsys SDk once Bluedot Service is started successfully 
   PushIOManager.getInstance(getApplicationContext()).registerUserId(mServiceManager.getInstallRef()); 
} 

@Override public void onBlueDotPointServiceStop() { 
   //This is called when BluedotPointService has been stopped 
   mServiceManager.unsubscribeForApplicationNotification(this); 
}

@Override public void onBlueDotPointServiceError(BDError bdError) { 
   //If any Error occurs in BluedotPointService,it can be checked here. 
} 

@Override public void onRuleUpdate(List<ZoneInfo> list) { 
   //Receives Zone Information from PointAccess (Optional) 
}

The ApplicationNotificationListener provides the following callbacks to inform when a Zone Check-in / Check-out event occurs.

Inside the callbacks ZoneInfo and FenceInfo details are populated in PIOGeoRegion and corresponding PushIOManager onGeoRegionEntered() / onGeoRegionExited() are called.

/** * This callback happens when user is checked into any fence under that Zone */ 
@Override 
public void onCheckIntoFence(final FenceInfo fenceInfo, ZoneInfo zoneInfo, LocationInfo location, Map<String, String> customData, boolean isCheckOut) { 
    //Building GeoRegion with Fence details 
    PIOGeoRegion geoRegion= new PIOGeoRegion(); 
    geoRegion.setGeofenceId(fenceInfo.getId()); 
    geoRegion.setGeofenceName(fenceInfo.getName()); 
    geoRegion.setZoneId(zoneInfo.getZoneId()); 
    geoRegion.setZoneName(zoneInfo.getZoneName()); 
    geoRegion.setSource("Bluedot SDK"); 
   
    //Reporting Checkin to Responsys 
    PushIOManager.getInstance(getApplicationContext()).onGeoRegionEntered (geoRegion, new PIORegionCompletionListener() { 
       @Override 
       public void onRegionReported(String s, PIORegionEventType pioRegionEventType, PIORegionException e) { 
             Log.i(TAG,"onGeoRegionEntered pioRegionEventType"+pioRegionEventType); 
       } 
    }); 
} 

/** * This callback happens when the user is checked out from a fence under that Zone */ 
@Override 
public void onCheckedOutFromFence(final FenceInfo fenceInfo, ZoneInfo zoneInfo, final int dwellTime, Map<String, String> customData) { 
    //Building GeoRegion with Fence details 
    PIOGeoRegion geoRegion= new PIOGeoRegion(); 
    geoRegion.setGeofenceId(fenceInfo.getId()); 
    geoRegion.setGeofenceName(fenceInfo.getName()); 
    geoRegion.setDwellTime(dwellTime); 
    geoRegion.setZoneId(zoneInfo.getZoneId()); 
    geoRegion.setZoneName(zoneInfo.getZoneName()); 
    geoRegion.setSource("Bluedot SDK");
    //Reporting Checkout to Responsys 
    PushIOManager.getInstance(getApplicationContext()).onGeoRegionExited (geoRegion, new PIORegionCompletionListener() { 
         @Override 
         public void onRegionReported(String s, PIORegionEventType pioRegionEventType, PIORegionException e) { 
              Log.i(TAG,"onGeoRegionExited "+s); 
         } 
    }); 
}

Similarly for Beacon enabled Zones inside the callbacks ZoneInfo  and BeaconInfo details are populated in PIOBeaconRegion and corresponding PushIOManager onBeaconRegionEntered() / onBeaconRegionExited() are called.

/** * This callback happens when the user is checked into any beacon under that Zone */ 
@Override public void onCheckIntoBeacon(final BeaconInfo beaconInfo, ZoneInfo zoneInfo, LocationInfo location, Proximity proximity, Map<String, String> customData, boolean isCheckOut) { 
    //Building BeaconRegion with Beacon & Zone details 
    PIOBeaconRegion beaconRegion = new PIOBeaconRegion(); 
    beaconRegion.setBeaconId(beaconInfo.getId()); 
    beaconRegion.setBeaconName(beaconInfo.getName()); 
    beaconRegion.setZoneId(zoneInfo.getZoneId()); 
    beaconRegion.setZoneName(zoneInfo.getZoneName()); 
    beaconRegion.setSource("Bluedot SDK"); 

    //Reporting Beacon Checkin to Responsys 
    PushIOManager.getInstance(getApplicationContext()).onBeaconRegionEntered (beaconRegion, new PIORegionCompletionListener() { 
       @Override 
       public void onRegionReported(String s, PIORegionEventType pioRegionEventType, PIORegionException e) { 
            Log.i(TAG,"onBeaconRegionEntered "+s); 
       } 
    }); 
} 

/** * This callback happens when the user is checked out from a beacon under that Zone */ 
@Override 
public void onCheckedOutFromBeacon(final BeaconInfo beaconInfo, ZoneInfo zoneInfo, final int dwellTime, Map<String, String> customData) { 
     //Building BeaconRegion with Beacon & Zone details 
     PIOBeaconRegion beaconRegion = new PIOBeaconRegion(); 
     beaconRegion.setBeaconId(beaconInfo.getId()); 
     beaconRegion.setBeaconName(beaconInfo.getName()); 
     beaconRegion.setZoneId(zoneInfo.getZoneId()); 
     beaconRegion.setZoneName(zoneInfo.getZoneName()); 
     beaconRegion.setSource("Bluedot SDK"); 

     //Reporting Beacon Checkout to Responsys 
     PushIOManager.getInstance(getApplicationContext()).onBeaconRegionExited (beaconRegion, new PIORegionCompletionListener() { 
          @Override 
          public void onRegionReported(String s, PIORegionEventType pioRegionEventType, PIORegionException e) { 
                 Log.i(TAG,"onBeaconRegionExited "+s); 
          } 
     }); 
}

For further information on the classes and methods discussed within this documentation, please refer to the Android SDK documentation.

GitHub Sample Project

A sample project which demonstrates the integration of the Responsys SDK and Bluedot Point SDK is available on GitHub.

 

Created by Neha Ishwar on May 2, 2019