|
30 | 30 | public class IntercomBridge extends CordovaPlugin { |
31 | 31 |
|
32 | 32 | @Override protected void pluginInitialize() { |
33 | | - this.setUpIntercom(); |
34 | | - Bridge.getApi().ping(); |
| 33 | + cordova.getActivity().runOnUiThread(new Runnable() { |
| 34 | + @Override public void run() { |
| 35 | + setUpIntercom(); |
| 36 | + if (Bridge.getApi() != null) { |
| 37 | + Bridge.getApi().ping(); |
| 38 | + } |
| 39 | + } |
| 40 | + }); |
35 | 41 | } |
36 | 42 |
|
37 | 43 | @Override public void onStart() { |
38 | | - //We also initialize intercom here just in case it has died. If Intercom is already set up, this won't do anything. |
39 | | - this.setUpIntercom(); |
| 44 | + cordova.getActivity().runOnUiThread(new Runnable() { |
| 45 | + @Override public void run() { |
| 46 | + //We also initialize intercom here just in case it has died. If Intercom is already set up, this won't do anything. |
| 47 | + setUpIntercom(); |
40 | 48 |
|
41 | | - if (Intercom.client().openGCMMessage(cordova.getActivity().getIntent().getData())) { |
42 | | - cordova.getActivity().getIntent().setData(null); |
43 | | - } |
| 49 | + if (Intercom.client().openGCMMessage(cordova.getActivity().getIntent().getData())) { |
| 50 | + cordova.getActivity().getIntent().setData(null); |
| 51 | + } |
| 52 | + } |
| 53 | + }); |
44 | 54 | } |
45 | 55 |
|
46 | 56 | @Override public void onNewIntent(Intent intent) { |
47 | 57 | cordova.getActivity().setIntent(intent); |
48 | 58 | } |
49 | 59 |
|
50 | 60 | private void setUpIntercom() { |
51 | | - cordova.getActivity().runOnUiThread(new Runnable() { |
52 | | - @Override public void run() { |
53 | | - try { |
54 | | - Context context = IntercomBridge.this.cordova.getActivity().getApplicationContext(); |
| 61 | + try { |
| 62 | + Context context = IntercomBridge.this.cordova.getActivity().getApplicationContext(); |
55 | 63 |
|
56 | | - HeaderInterceptor.setCordovaVersion(context, "1.1.6"); |
| 64 | + HeaderInterceptor.setCordovaVersion(context, "1.1.6"); |
57 | 65 |
|
58 | | - ApplicationInfo app = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); |
59 | | - Bundle bundle = app.metaData; |
| 66 | + ApplicationInfo app = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); |
| 67 | + Bundle bundle = app.metaData; |
60 | 68 |
|
61 | | - //Get app credentials from config.xml or the app bundle if they can't be found |
62 | | - String apiKey = IntercomBridge.this.preferences.getString("intercom-android-api-key", bundle.getString("intercom_api_key")); |
63 | | - String appId = IntercomBridge.this.preferences.getString("intercom-app-id", bundle.getString("intercom_app_id")); |
| 69 | + //Get app credentials from config.xml or the app bundle if they can't be found |
| 70 | + String apiKey = IntercomBridge.this.preferences.getString("intercom-android-api-key", bundle.getString("intercom_api_key")); |
| 71 | + String appId = IntercomBridge.this.preferences.getString("intercom-app-id", bundle.getString("intercom_app_id")); |
64 | 72 |
|
65 | | - Intercom.initialize(IntercomBridge.this.cordova.getActivity().getApplication(), apiKey, appId); |
66 | | - } catch (Exception e) { |
67 | | - System.err.println("[Intercom-Cordova] ERROR: Something went wrong when initializing Intercom. Have you set your APP_ID and ANDROID_API_KEY?"); |
68 | | - } |
69 | | - } |
70 | | - }); |
| 73 | + Intercom.initialize(IntercomBridge.this.cordova.getActivity().getApplication(), apiKey, appId); |
| 74 | + } catch (Exception e) { |
| 75 | + System.err.println("[Intercom-Cordova] ERROR: Something went wrong when initializing Intercom. Have you set your APP_ID and ANDROID_API_KEY?"); |
| 76 | + } |
71 | 77 | } |
72 | 78 |
|
73 | 79 | private enum Action { |
|
0 commit comments