Skip to content

Use Cases for publishing using Project ID

Launch a project using Notification

Generate the Project ID

Generate the project_id of the project which you want to launch via a notification. For more information, see Publish using Project ID.

Ensure to send the correct project_id with the correct app version in the notification.

Create a Cloud Notification

For this example, consider a notification created using Firebase.

  1. Compose a notification. firebase_notif
  2. Add the Whatfix Mobile project ID. firebase_project_id

Before publishing the notification, you need to add a code snippet in the Android project to launch the Whatfix Mobile project via the created notification.

Launch Whatfix Mobile via Notification

To launch the Whatfix Mobile project via notification, you have to process the project_id passed in the Firebase dashboard, inside your Android project.

  1. Process the Firebase data in your Firebase service class

Android

public class LeapFirebaseService extends FirebaseMessagingService {
 
 ย  @Override
 ย  public void onMessageReceived(RemoteMessage remoteMessage) {
 ย  ย  ย  ย super.onMessageReceived(remoteMessage);
 
 ย  ย  ย  ย RemoteMessage.Notification remoteNotification = remoteMessage.getNotification();
 ย  ย  ย  ย if (remoteNotification != null) {
 
 ย  ย  ย  ย  ย  ย //1. Receive the data from Firebase
 ย  ย  ย  ย  ย  ย Map<String, String> data = remoteMessage.getData();
 ย  ย  ย  ย  ย  ย String projectId = data.get("project_id");
 
 ย  ย  ย  ย  ย  ย //2. Create an intent (with project_id data as extra) and specify the destination
 ย  ย  ย  ย  ย  ย Intent intent = new Intent(this, DestinationActivity.class);
 ย  ย  ย  ย  ย  ย intent.putExtra("project_id", projectId);
 
 ย  ย  ย  ย  ย  ย //3. Since we are launching a notification, we need to create a PendingIntent
 ย  ย  ย  ย  ย  ย PendingIntent pendingIntent = PendingIntent.getActivity(this,
 ย  ย  ย  ย  ย  ย  ย  ย  ย  ย REQUEST_CODE,
 ย  ย  ย  ย  ย  ย  ย  ย  ย  ย intent,
 ย  ย  ย  ย  ย  ย  ย  ย  ย  ย PendingIntent.FLAG_UPDATE_CURRENT);
 
 ย  ย  ย  ย  ย  ย //4. Create a notification with the above created PendingIntent
 ย  ย  ย  ย  ย  ย Notification notification = getNotification(this,
 ย  ย  ย  ย  ย  ย  ย  ย  ย  ย remoteNotification.getTitle(),
 ย  ย  ย  ย  ย  ย  ย  ย  ย  ย remoteNotification.getBody(),
 ย  ย  ย  ย  ย  ย  ย  ย  ย  ย "Launch",
 ย  ย  ย  ย  ย  ย  ย  ย  ย  ย pendingIntent); // "Launch" is the action button text
 
 ย  ย  ย  ย  ย  ย //5. Let's launch the notification
 ย  ย  ย  ย  ย  ย NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
 ย  ย  ย  ย  ย  ย notificationManager.notify(NOTIFICATION_ID, notification);
 ย  ย  ย  ย }
 ย  ย }
 ย  ย }

Swift

import UIKit
import Firebase
import FirebaseMessaging
import UserNotifications
 
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
 ย  ย  ย  ย // Override point for customization after application launch.
 
 ย  ย  ย  ย FirebaseApp.configure()
 
 ย  ย  ย  ย Messaging.messaging().delegate = self
 
 ย  ย  ย  ย UNUserNotificationCenter.current().delegate = self
 
 ย  ย  ย  ย let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
 
 ย  ย  ย  ย UNUserNotificationCenter.current().requestAuthorization(
 ย  ย  ย  ย  ย  ย  ย  ย options: authOptions,
 ย  ย  ย  ย  ย  ย  ย  ย completionHandler: { _, _ in }
 ย  ย  ย  ย  ย  ย )
 
 ย  ย  ย  ย application.registerForRemoteNotifications()
 
 ย  ย  ย  ย return true
 ย  ย }
  1. Launch the Whatfix Mobile project Launch the project in the destination screen using Leap.embedProject(String project_id).

Android

class DestinationActivity extends Activity {
 
 ย @Override
 ย protected void onNewIntent(Intent intent) {
 ย  ย super.onNewIntent(intent);
 
 ย  ย //1. Since the intent destination was here, we will handle the received intent here
 ย  ย if (intent != null && intent.hasExtra("project_id")) {
 
 ย  ย  ย  //2. Get the project_id from intent
 ย  ย  ย  String projectId = intent.getStringExtra("project_id");
 
 ย  ย  ย  //3. Verify the project_id is not null or not empty
 ย  ย  ย if (projectId != null && !projectId.isEmpty()) {
 
 ย  ย  ย  ย //4. Launch the project_id via Leap SDK's 'embedProject' method
 ย  ย  ย  ย Leap.embedProject(projectId);
 ย  ย  ย }
 ย  ย }
 ย }
}

Swift

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
 
 ย  ย  ย  ย  ย if let projectId = userInfo["projectId"] as? String {
 ย  ย  ย  ย  ย Leap.shared.embedProject(projectId)
 ย  ย  ย  ย }
 ย  ย }

Run on your device

  1. Publish the notification

  1. Check your app When a notification comes up on your app, view the Whatfix Mobile content.

Android

iOS