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 <project level>/build.gradle, and add

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

Go to <app level>/build.gradle, add these lines:

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

compile “com.google.firebase:firebase-messaging:17.0.0”
compile “com.google.firebase:firebase-ads:15.0.1”

and then at the bottom of build.gradle

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

Note: Firebase Cloud Messaging required to use Android API 14 or higher. For API lower than API 14, use firebase-messaging version 10.2.6 and firebase-ads library is not needed.

Integrate Tapjoy push notification APIs

Create two classes in your app project which extends FirebaseMessagingService and FirebaseInstanceIdService

From those two classes, 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());
    }

    public class FCMTokenService extends FirebaseInstanceIdService {

    @Override
    public void onTokenRefresh() {
    // Get updated InstanceID token. 
    String deviceToken = FirebaseInstanceId.getInstance().getToken();
    Tapjoy.setDeviceToken(deviceToken);
    }

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

<service android:name="<your_FirebaseInstanceIdService_name>">
  <intent-filter>
    <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
  </intent-filter>
</service>
<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.