Survey notifications

These are optional implementations for Sense360 SDK survey notifications.

Notifying click-data

If your application displays Sense360 surveys in its interface (instead of using the SDK survey notification), it must notify the click data to Sense360 using this code snippet:

NotificationClickData clickData = new NotificationClickData("[notificationId]");
  try {
    Sense360.notificationClicked(getApplicationContext(), clickData);
  } catch (InvalidNotificationDataException e) {
    // Null object or null notification ID passed
  }

By default, Sense360 SDK may display its own notifications with surveys.

Custom notification channel

On devices running Android Oreo, all notifications must be assigned a Notification channel. By default, the Sense360 Android SDK sends survey notifications to the Survey Opportunities channel, which the SDK manages. Surveys sent to this channel have an importance of NotificationManager.IMPORTANCE_DEFAULT.

To send notifications to a custom channel you manage, do so by calling the Sense360.setNotificationPreferences() method as in this sample code:

String channelId = "channelId123";
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(new NotificationChannel(channelId, "channelName", NotificationManager.IMPORTANCE_DEFAULT));
Sense360.setNotificationPreferences(getApplicationContext(), new NotificationPrefs(channelId));

You must manage the custom notification channel you are sending survey notifications to. Additionally, ensure that the channel is created before making the call and that it exists whenever a notification is sent, otherwise the SDK creates and sends a notification to the Survey Opportunities channel.

Notification callbacks

Notification callbacks notify you when a notification is sent, clicked, or cancelled (that is, swiped). Integrating surveys via the Sense360 Android SDK does not require implementing the notification callbacks, as they are already provided track the interaction between users and the survey notifications.

Use this example code to register a BroadcastReceiver:

<android ...>
 ...
 <application>
  ...
  <receiver android:name="[Your Receiver Class Name]" android:enabled="true">
  <intent-filter>
   <!--A notification has been sent to the user-->
   <action android:name="com.sense360.android.quinoa.lib.intent.action.NOTIFICATION_SENT"/>
   <!--The user has clicked on the notification-->
   <action android:name="com.sense360.android.quinoa.lib.intent.action.NOTIFICATION_CLICKED"/>
   <!--The user has removed the notification by swiping right -->
   <action android:name="com.sense360.android.quinoa.lib.intent.action.NOTIFICATION_CANCELED"/>
   <!--Sense360 has removed the notification-->
   <action android:name="com.sense360.android.quinoa.lib.intent.action.NOTIFICATION_REMOVED"/>
  </intent-filter>
  </receiver>
  ...
 </application>
 ...
</android>

If you register for multiple actions, use this intent.getAction() method to determine what happened:

import com.sense360.android.quinoa.lib.helpers.IntentActions;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
            
public class MyReceiver extends BroadcastReceiver {
 @Override
 public void onReceive(Context context, Intent intent) {
   if (intent.getAction().equals(IntentActions.ACTION_NOTIFICATION_SENT)) {
   Log.d("MyReceiver", "Sent survey notification to user.");
  } else if (intent.getAction().equals(IntentActions.ACTION_NOTIFICATION_CLICKED)) {
   String surveyUrl = intent.getStringExtra(IntentActions.EXTRA_SURVEY_URL);
   Log.d("MyReceiver", "User clicked survey notification. Survey url is " + surveyUrl);
  }else if (intent.getAction().equals(IntentActions.ACTION_NOTIFICATION_CANCELED)){
   Log.d("MyReceiver", "User cancelled survey notification.");
  }
 }
}