|
18 | 18 | import com.getcapacitor.annotation.PermissionCallback;
|
19 | 19 | import java.util.HashMap;
|
20 | 20 | import java.util.Map;
|
| 21 | +import java.util.concurrent.ExecutorService; |
| 22 | +import java.util.concurrent.Executors; |
21 | 23 |
|
22 | 24 | @CapacitorPlugin(
|
23 | 25 | name = "Contacts",
|
@@ -102,20 +104,34 @@ public void getContacts(PluginCall call) {
|
102 | 104 | if (!isContactsPermissionGranted()) {
|
103 | 105 | requestContactsPermission(call);
|
104 | 106 | } else {
|
105 |
| - HashMap<String, ContactPayload> contacts = implementation.getContacts( |
106 |
| - new GetContactsProjectionInput(call.getObject("projection")) |
107 |
| - ); |
108 |
| - |
109 |
| - JSArray contactsJSArray = new JSArray(); |
110 |
| - |
111 |
| - for (Map.Entry<String, ContactPayload> entry : contacts.entrySet()) { |
112 |
| - ContactPayload value = entry.getValue(); |
113 |
| - contactsJSArray.put(value.getJSObject()); |
114 |
| - } |
115 |
| - |
116 |
| - JSObject result = new JSObject(); |
117 |
| - result.put("contacts", contactsJSArray); |
118 |
| - call.resolve(result); |
| 107 | + ExecutorService executor = Executors.newSingleThreadExecutor(); |
| 108 | + |
| 109 | + executor.execute(new Runnable() { |
| 110 | + @Override |
| 111 | + public void run() { |
| 112 | + HashMap<String, ContactPayload> contacts = implementation.getContacts( |
| 113 | + new GetContactsProjectionInput(call.getObject("projection")) |
| 114 | + ); |
| 115 | + |
| 116 | + JSArray contactsJSArray = new JSArray(); |
| 117 | + for (Map.Entry<String, ContactPayload> entry : contacts.entrySet()) { |
| 118 | + ContactPayload value = entry.getValue(); |
| 119 | + contactsJSArray.put(value.getJSObject()); |
| 120 | + } |
| 121 | + |
| 122 | + JSObject result = new JSObject(); |
| 123 | + result.put("contacts", contactsJSArray); |
| 124 | + |
| 125 | + bridge.getActivity().runOnUiThread(new Runnable() { |
| 126 | + @Override |
| 127 | + public void run() { |
| 128 | + call.resolve(result); |
| 129 | + } |
| 130 | + }); |
| 131 | + } |
| 132 | + }); |
| 133 | + |
| 134 | + executor.shutdown(); |
119 | 135 | }
|
120 | 136 | }
|
121 | 137 |
|
|
0 commit comments