-
Notifications
You must be signed in to change notification settings - Fork 112
/
IntercomIntentService.java
46 lines (37 loc) · 1.52 KB
/
IntercomIntentService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
}
}
}
}