Notifications Android

Configure Push and In-app notifications.

Configure push notifications via Helpshift

urbanAirshipNotif.png

Helpshift enables you to send notifications to your users. This is particularly useful when you have multiple users on multiple platforms like iOS and Android. Notifications are useful to tell your users when you reply to an issue that they submitted. When the app is backgrounded, the notification that is sent from Helpshift appears as a notification.

Refer to the following link for documentation on GCM Push:- Google Cloud Messaging for Android

For Helpshift Admin Interface

To enable the Helpshift system to send push notifications to your users you will have to add your GCM Key and Bundle Name via the helpshift admin interface.

Enter your Google Push notifications credentials per app, via the Settings page > App listing in the left navigation > Scroll down to Push Notifications settings section for the app.

helpshift-push-notifications.png

The API key can be found at your Google API Console.

GCM Console.png

Configure the Helpshift Unity SDK to handle notifications

In built support

Helpshift Unity plugin now comes with built-in support for Push notifications. If you want to use the Helpshift push notification handling, please call the HelpshiftSdk.registerForPush(string yourGcmSenderId) API inside your applications init code. Also you need to uncomment the permissions in the AndroidManifest for Helpshift. Go to Assets->Plugins->Android->helpshift->AndroidManifext.xml. Uncomment the following permissions :

<!-- App receives GCM messages. -->
<!--permission android:name="${applicationId}.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /-->
<!-- GCM requires a Google account. -->
<!--uses-permission android:name="android.permission.GET_ACCOUNTS" /-->
<!-- Keeps the processor from sleeping when a message is received. -->
<!--uses-permission android:name="android.permission.WAKE_LOCK" /-->

<!--receiver android:name="com.helpshift.gcm.HSGcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
        <category android:name="${applicationId}" />
    </intent-filter>
</receiver>
<service android:name="com.helpshift.gcm.HSGcmIntentService" /-->

If you are using gradle build system then ${applicationId} is automatically replaced during build time.

Otherwise, manually replace ${applicationId} with your app's bundle identifier.

Manual support

If you have integrated push notifications to receive updates from the Helpshift's push notification service, please use the HelpshiftSdk.registerDeviceToken(string deviceToken) API to register the device token with the Helpshift SDK.

Once this is done, you can use the HelpshiftSdk.handlePushNotification(Dictionary<string, object> pushNotificationData) API to send the payload received in the notification.

To check whether this notification is being sent from the Helpshift's push notification service, please check the origin field of the notification. If it is "helpshift", the notification is a Helpshift notification. For example

GCM.SetRegisteredCallback ((string registrationId) => {
        help.registerDeviceToken(registrationId);
});

GCM.SetMessageCallback ((Dictionary<string, object> table) => {
        if(table["origin"].Equals("helpshift")) {
                help.handlePushNotification((table);
        }
});

If your application is not running and it receives a push notification then it will start the application in background (by invoking the push notification receiver registered in java). In this case, UnityEngine might not be initialized and the C# api HelpshiftSdk.handlePushNotification might not be useful.

If you are unable to delegate the push notification payload from the Java receiver class to C# api's then, for such cases, you can use the native Java api HelpshiftUnity.handlePush(Context context, Intent intent) to handle push notifications from Helpshift.

In Java implementation of the receiver for push notifications, you can use this api as in the following example.

public class MyGcmIntentService extends GCMBaseIntentService {
    @Override
    protected void onMessage(Context context, Intent intent) {
    Log.v(TAG, "onMessage");
    try {
        if (intent.getExtras().getString("origin").equals("helpshift")) {
            Log.d(TAG, "Got Helpshift push notification");
            HelpshiftUnity.handlePush(context, intent);
        }
    } 
    catch (Exception e) {
        Log.e(TAG, "Exception : " + e.getMessage());
    }
}

Support with other push notification plugins

If you are using any other plugin for push notifications like prime31,onesignal etc. you can use HelpshiftSdk.registerDeviceToken(string deviceToken) API to register the device token. You need to call this API from the registrationSucceededEvent in your plugin. The following is an example for prime31 plugin.

For Example :

void registrationSucceededEvent( string registrationId )
{
    Debug.Log( "registrationSucceededEvent: " + registrationId );
    HelpshiftLog.e ("Helpshift-HS", registrationId);
    help.registerDeviceToken (registrationId);
}

Once this is done, you can use the HelpshiftSdk.handlePushNotification(Dictionary<string, object> pushNotificationData) API to send payload which you receive in the notificationReceivedEvent callback in your plugin.

To check whether this notification is being sent from the Helpshift's push notification service, please check the origin field of the notification. If it is "helpshift", the notification is a Helpshift notification.

If you are using other push notification service do not uncomment the permissions in the Helpshift AndroidManifest.xml located at Assets/Plugins/Android/helpshift/AndroidManifest.xml.

In-app notifications

In-app notifications are similar to notifications in the notification drawer . Unlike push notifications, they appear only when you app is running.

These notifications are sent when an agent replies to a customer's issue. Your customers can go straight into the conversation screen when they tap on the notification.

If the GCM/FCM device token is registered for push notifications, then in-app notifications will be disabled. In-app notifications are disabled to avoid duplicate notifications from both push notifications and in-app notifications.

Configuring in-app notifications

If you do not want the in-app notifications support provided by the Helpshift SDK, please set this flag to "no". The default value of this flag is "yes" i.e in-app notifications will be enabled.
Read more about in-app notifications in the Notifications section.

Flag
enableInAppNotification
Values
"yes" / "no"
Default
"yes"

Example:

using Helpshift;
.
.
.
private HelpshiftSdk help;
this.help = HelpshiftSdk.getInstance();
Dictionary<string, string> configMap = new Dictionary<string, string>();
configMap.Add("unityGameObject", "DemoControl");
configMap.Add("enableInAppNotification", "yes");
help.install("<YOUR_API_KEY>", "<YOUR_HELPSHIFT_DOMAIN>", "<YOUR_APP_ID>", configMap);

Showing notification count when replies are sent to the user

Via Helpshift API

If you want to show your user notifications for replies sent by the Agent to their Issues, you can use notification counts provided by the Helpshift SDK. These give you the total number of unread messages and display that number as a badge. You can get notification counts asynchronously by implementing the Helpshift delegate method didReceiveUnreadMessageCount. Notifications are typically displayed as badges inside your app where a user clicks on the help section. These badges can be displayed anywhere in your app's interface to tell the user that they have unread replies/messages from you.

You can implement the "didReceiveUnreadMessageCount" delegate method like the following example:

API:
using Helpshift;
.
.
.
private HelpshiftSdk help;
this.help = HelpshiftSdk.getInstance();
help.requestUnreadMessagesCount(true);

Delegate:
public void didReceiveUnreadMessagesCount(int count) {
    // your code here
}

Via In-App Notifications

If you want to use the in-app notifications mechanism to get the count of unread notifications, you can implement the didReceiveInAppNotificationCount message handler on the Game object which you have registered at the time of install.

For example

public void didReceiveInAppNotificationCount(string count) {
    Debug.Log("In-app Notification count : " + count);
}