-
Notifications
You must be signed in to change notification settings - Fork 32
/
getAllContacts.android.js
58 lines (54 loc) · 1.59 KB
/
getAllContacts.android.js
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
47
48
49
50
51
52
53
54
55
56
57
58
require('globals'); // necessary to bootstrap tns modules on the new thread
var Contact = require("./contact-model");
var helper = require("./contact-helper");
/* pass debug messages to main thread since web workers do not have console access */
function console_log(msg) {
postMessage({
type: 'debug',
message: msg
});
}
function console_dump(msg) {
postMessage({
type: 'dump',
message: msg
});
}
module.exports = function (contactFields) {
try {
var c = helper.getContext().getContentResolver().query(android.provider.ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
if (c !== null && c.moveToFirst() && c.getCount() > 0) {
var cts = [];
while (!c.isLast()) {
var contactModel = new Contact();
contactModel.initializeFromNative(c, contactFields);
cts.push(contactModel);
c.moveToNext()
}
if (c.isLast()) {
var contactModel = new Contact();
contactModel.initializeFromNative(c, contactFields);
cts.push(contactModel);
}
c.close();
return {
data: cts,
response: "fetch"
}
} else {
if (c) {
c.close();
}
return {
data: null,
response: "fetch"
}
}
} catch (e) {
// console.log('error', e)
return {
data: null,
response: "fetch"
}
}
}