Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ ext {
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
intercomSdkVersion = project.hasProperty('intercomSdkVersion') ? rootProject.ext.intercomSdkVersion : '15.11.0'
intercomSdkVersion = project.hasProperty('intercomSdkVersion') ? rootProject.ext.intercomSdkVersion : '15.+'
firebaseMessagingVersion = project.hasProperty('firebaseMessagingVersion') ? rootProject.ext.firebaseMessagingVersion : '24.1.0'
}

buildscript {
Expand Down Expand Up @@ -57,4 +58,5 @@ dependencies {
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
implementation "io.intercom.android:intercom-sdk:$intercomSdkVersion"
implementation "com.google.firebase:firebase-messaging:$firebaseMessagingVersion"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpike88 have you tried defining the firebase-messaging dep in your app's build.gradle instead ?

}
7 changes: 7 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
>
<application>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, you should be able to define this in your app layer, not in the plugin.

<service android:name="com.getcapacitor.community.intercom.intercom.MessagingService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.getcapacitor.community.intercom;
package com.getcapacitor.community.intercom.intercom;

import android.app.Activity;
import android.app.Application;
Expand Down Expand Up @@ -219,8 +219,12 @@ public void displayCarousel(PluginCall call) {
@PluginMethod
public void setUserHash(PluginCall call) {
String hmac = call.getString("hmac");
Intercom.client().setUserHash(hmac);
call.resolve();
try {
Intercom.client().setUserHash(hmac);
call.resolve();
} catch (Exception e) {
call.reject("Failed to send user hash to Intercom", e);
}
}

@PluginMethod
Expand Down Expand Up @@ -272,6 +276,17 @@ private void setUpIntercom() {
String apiKey = config.getPluginConfiguration("Intercom").getString("androidApiKey");
String appId = config.getPluginConfiguration("Intercom").getString("androidAppId");

switch (IntercomPushManager.getInstalledModuleType()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about this part as I can't test. but do we really need to tell Intercom to cache a sender id? if so, something to investigate and move to the app layer as well.

case FCM: {
String senderId = config.getPluginConfiguration("Intercom").getString("senderId");
// with FCM enabled, a senderId can be provided
if(!senderId.isEmpty()) {
IntercomPushManager.cacheSenderId(this.getActivity().getApplicationContext(), senderId);
}
break;
}
}

// init intercom sdk
Intercom.initialize(this.getActivity().getApplication(), apiKey, appId);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.getcapacitor.community.intercom.intercom;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this MessagingService could be implemented in the MainActivity if using the app's AndroidManifest


import androidx.annotation.NonNull;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

import java.util.Map;

import io.intercom.android.sdk.push.IntercomPushClient;

public class MessagingService extends FirebaseMessagingService {
private final IntercomPushClient intercomPushClient = new IntercomPushClient();
@Override
public void onMessageReceived(RemoteMessage message) {
Map messageData = message.getData();
if (intercomPushClient.isIntercomPush(messageData)) {
intercomPushClient.handlePush(getApplication(), messageData);
} else {
super.onMessageReceived(message);
}
}

@Override
public void onNewToken(@NonNull String s) {
super.onNewToken(s);
intercomPushClient.sendTokenToIntercom(this.getApplication(), s);
}
}