Push Notifications

1. FCM Configuration Guide

Add the application project in Firebase Console and download the config file google-services.json and update the API key and Sender ID on LTV dashboard.

See how to get sender Id and API key here.

To set up Firebase SDK for push notification in your app, add downloaded google-services.json file in your project root directory.

Go to buildscript > dependencies, and add

    classpath 'com.google.gms:google-services:4.0.1’

Go to app level build.gradle, and add:

maven { 
  url ‘https://maven.google.com’ 
  name ‘Google’ 
}

implementation "com.google.firebase:firebase-messaging:23.0.0"

finally add:

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

For Firebase v23.0.0 you need to use minSdkVersion 26 or minSdkVersion 19 and Java 8.

You can set the Java version in your app level build.gradle like so (VERSION_1_8 == Java 8):

    compileOptions {
      sourceCompatibility JavaVersion.VERSION_1_8
      targetCompatibility JavaVersion.VERSION_1_8
    }

Integrate Tapjoy push notification APIs

Create a class in your app project which extends FirebaseMessagingService

From this class, call the two Tapjoy push notification APIs

java
    Tapjoy.setReceiveRemoteNotification(remoteMessage.getData());
    Tapjoy.setDeviceToken(deviceToken);

For example:

java
    public class FCMMessageService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
       Tapjoy.setReceiveRemoteNotification(remoteMessage.getData());
    }

This class should also override a method where the device token should be set. setDeviceToken should only be called after Tapjoy connects. If Tapjoy is not yet connected you should store the device token and set it later in the connect success callback.

For example:

java
  @Override
  public void onNewToken(String deviceToken) {
  2    // Get updated InstanceID token.    
  3    if (deviceToken != null) {
  4        if (Tapjoy.isConnected()) {
  5            Tapjoy.setDeviceToken(deviceToken);        
  6        } else {
  7            token = deviceToken;        
  8        }
  9    }
  10}

Go to your app AndroidManifest.xml, add the following code:

<service android:name="<your_FirebaseMessagingService_name">
 <intent-filter>
   <action android:name="com.google.firebase.MESSAGING_EVENT"/>
 </intent-filter>
</service>

Before sending push notification, you need to configure the API server key and sender ID on Tapjoy Dashboard. Please configure your key by going to "Settings" > "App Settings" on the top of the Tapjoy dashboard and then selecting "Push Certificate" from the left menu bar.

You can find your Sender ID and API Key in Firebase Console.

Notes on Push

Can I use another push provider or my own push server simultaneously with Tapjoy?

Yes. Please refer to this article.

My Push certificate is about to expire soon.

Please replace your current certificate with a new one before it expires.

2. Sending a Custom Payload

You can send a custom payload (a string you enter into the dashboard that the user does not see) when sending a push notification with Tapjoy. This custom payload can be any arbitrary string, and your app can parse and react to this string in any way you program your application to respond. Typical use cases include rewarding the user with currency for responding to the push and sending the user to a specific place in the application via a custom URL scheme. For information on how your app can send the custom push payload, please see the custom payload documentation.

To enable your application to read information sent via this method you need to implement some code. Custom payload is delivered via Intent’s StringExtra. Considering the purpose, add proper code to onCreate and onNewIntent of your app’s Main Activity (Launcher activity) like following:

  // called when the user clicks the push message
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    ...
    String payload = getIntent().getStringExtra(Tapjoy.INTENT_EXTRA_PUSH_PAYLOAD);
    if (payload != null) {
      Log.d("Tapjoy", "Tapjoy push notification payload: " + payload);
    }
    ...
  }

  // called when the user gets push message while playing the app
  @Override
  protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);

    String payload = getIntent().getStringExtra(Tapjoy.INTENT_EXTRA_PUSH_PAYLOAD);
    if (payload != null) {
      Log.d("Tapjoy", "Tapjoy push notification with payload: " + payload);
    }
  }

3. Customizing Notification Icon

Application icon will be displayed as a default notification icon when you send push notifications (FCM message) through Tapjoy dashboard.

You may change notification icon by specifying a resource in <application> tag of AndroidManifest.xml file of application project as follows:

//notification bar small icon. 
<meta-data android:name="com.tapjoy.notification.icon" android:resource="@drawable/{id}"/>  

//notification panel large icon. (above 11.6.0)  
<meta-data android:name="com.tapjoy.notification.icon.large" android:resource="@drawable/{id}"/>  

//The icon which is using partial alpha value below android 5.0 (above 11.6.0)
<meta-data android:name="com.tapjoy.notification.icon.compat" android:resource="@drawable/{id}"/>

4. Push Opt out API for Android SDK 11.1+

You can opt out users who don’t want to receive push notifications by using this API.
You should connect to Tapjoy SDK first by using Tapjoy.connect call before use this.

java
    // To get the current status
    boolean Tapjoy.isPushNotificationDisabled();

    // To set/unset push notification disabled
    void Tapjoy.setPushNotificationDisabled(boolean);

We recommend you to add a toggle or checkbox UI to your app’s setting page.