Skip to content

Commit

Permalink
Merge pull request #166 from intercom/jtreanor/gcm_interoperability
Browse files Browse the repository at this point in the history
Enable compatibility with other Android GCM providers
  • Loading branch information
jtreanor authored Mar 30, 2017
2 parents 2c4b021 + 84d2fb2 commit b2aaab9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
11 changes: 11 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<platform name="android">
<source-file src="src/android/IntercomBridge.java" target-dir="src/io/intercom/android/sdk" />
<source-file src="src/android/CordovaHeaderInterceptor.java" target-dir="src/io/intercom/android/sdk" />
<source-file src="src/android/IntercomIntentService.java" target-dir="src/io/intercom/android/sdk" />

<framework src="src/android/intercom.gradle" custom="true" type="gradleReference" />
<framework src="src/android/build-extras-intercom.gradle" custom="true" type="gradleReference" />
Expand All @@ -60,6 +61,16 @@
<param name="onload" value="true" />
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<service
android:name="io.intercom.android.sdk.IntercomIntentService"
android:exported="false">
<intent-filter
android:priority="999">
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
</intent-filter>
</service>
</config-file>
</platform>

</plugin>
46 changes: 46 additions & 0 deletions src/android/IntercomIntentService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.intercom.android.sdk;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;

import java.util.List;

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

public class IntercomIntentService extends IntentService {
private final IntercomPushClient intercomPushClient = new IntercomPushClient();

public IntercomIntentService() {
super("Intercom Cordova Intent Service");
}

@Override
protected void onHandleIntent(Intent intent) {
if (intercomPushClient.isIntercomPush(intent.getExtras())) {
intercomPushClient.handlePush(getApplication(), intent.getExtras());
return;
}

Intent passThroughIntent = new Intent(intent);
passThroughIntent.setComponent(null);

List<ResolveInfo> services = getPackageManager().queryIntentServices(passThroughIntent, 0);
for (ResolveInfo info : services) {
try {
Class serviceClass = Class.forName(info.serviceInfo.name);
if (serviceClass == this.getClass()) {
continue;
}

Context applicationContext = getApplicationContext();
passThroughIntent.setClass(applicationContext, serviceClass);
applicationContext.startService(passThroughIntent);
return;
} catch (ClassNotFoundException e) {
// Class not found. Try the next service
}
}
}
}

0 comments on commit b2aaab9

Please sign in to comment.