|
@ -1,25 +1,21 @@
|
1
|
1
|
package com.ai.ipu.mobile.plugin;
|
2
|
2
|
|
3
|
3
|
import org.json.JSONArray;
|
4
|
|
|
5
|
4
|
import android.app.Activity;
|
6
|
5
|
import android.content.Intent;
|
7
|
6
|
import android.database.Cursor;
|
8
|
7
|
import android.net.Uri;
|
9
|
8
|
import android.provider.ContactsContract;
|
10
|
9
|
import android.util.Log;
|
11
|
|
|
12
|
10
|
import com.ai.ipu.mobile.frame.IIpuMobile;
|
13
|
11
|
import com.ai.ipu.mobile.frame.plugin.Plugin;
|
14
|
12
|
import com.ailk.common.data.impl.DataMap;
|
15
|
13
|
|
16
|
|
public class MobileContactDetail extends Plugin
|
17
|
|
{
|
|
14
|
public class MobileContactDetail extends Plugin{
|
18
|
15
|
|
19
|
|
public MobileContactDetail(IIpuMobile ipumobile)
|
20
|
|
{
|
|
16
|
public MobileContactDetail(IIpuMobile ipumobile){
|
21
|
17
|
super(ipumobile);
|
22
|
|
}
|
|
18
|
}
|
23
|
19
|
|
24
|
20
|
/**
|
25
|
21
|
* @Title: getContacts
|
|
@ -28,40 +24,36 @@ public class MobileContactDetail extends Plugin
|
28
|
24
|
* @param param
|
29
|
25
|
* @throws
|
30
|
26
|
*/
|
31
|
|
public void getContacts(JSONArray param)
|
32
|
|
{
|
|
27
|
public void getContacts(JSONArray param){
|
33
|
28
|
Intent intent = new Intent(Intent.ACTION_PICK);
|
34
|
29
|
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
|
35
|
30
|
startActivityForResult(intent, 1);
|
36
|
31
|
}
|
37
|
32
|
|
38
|
33
|
@Override
|
39
|
|
public void onActivityResult(int reqCode, int resultCode, Intent data)
|
40
|
|
{
|
|
34
|
public void onActivityResult(int reqCode, int resultCode, Intent data){
|
41
|
35
|
super.onActivityResult(reqCode, resultCode, data);
|
42
|
36
|
|
43
|
|
switch (reqCode)
|
44
|
|
{
|
|
37
|
switch (reqCode){
|
45
|
38
|
case 1:
|
46
|
|
if (resultCode == Activity.RESULT_OK)
|
47
|
|
{
|
48
|
|
|
|
39
|
if (resultCode == Activity.RESULT_OK){
|
49
|
40
|
Uri contactData = data.getData();
|
50
|
|
Cursor c = this.context.managedQuery(contactData, null, null,
|
51
|
|
null, null);
|
|
41
|
Cursor c = this.context.managedQuery(contactData, null, null,null, null);
|
52
|
42
|
String contactId = contactData.getLastPathSegment();
|
53
|
43
|
DataMap dataMap = new DataMap();
|
54
|
|
if (c.moveToFirst())
|
55
|
|
{
|
56
|
|
// 姓名
|
57
|
|
dataMap.put("name", this.getContactName(c));
|
58
|
|
// 手机号
|
59
|
|
dataMap.put("phoneNumber",
|
60
|
|
this.getContactPhoneNumber(c, contactId));
|
61
|
|
// 查找该联系人的email信息
|
62
|
|
dataMap.put("email", this.getContactEmail(c, contactId));
|
63
|
|
|
|
44
|
if (c.moveToFirst()){
|
|
45
|
dataMap.put("name", this.getContactName(c)); // 姓名
|
|
46
|
/*
|
|
47
|
* update by wanyao
|
|
48
|
* 获取多个号码,以及类型
|
|
49
|
* 获取多个邮箱,以及类型
|
|
50
|
* */
|
|
51
|
DataMap phonedataMap = getContactPhoneNumber(c, contactId); // 手机号
|
|
52
|
dataMap.put("phoneNumber", phonedataMap);
|
|
53
|
DataMap emaildataMap = getContactEmail(c, contactId); // 查找该联系人的email信息
|
|
54
|
dataMap.put("email", emaildataMap);
|
64
|
55
|
String result = dataMap.toString();
|
|
56
|
Log.d("wanyao", "result:" +result);
|
65
|
57
|
callback(result);
|
66
|
58
|
}
|
67
|
59
|
}
|
|
@ -78,27 +70,25 @@ public class MobileContactDetail extends Plugin
|
78
|
70
|
* @return
|
79
|
71
|
* @throws
|
80
|
72
|
*/
|
81
|
|
private String getContactEmail(Cursor c, String contactId)
|
82
|
|
{
|
|
73
|
private DataMap getContactEmail(Cursor c, String contactId){
|
83
|
74
|
// TODO Auto-generated method stub
|
84
|
|
String email = null;
|
|
75
|
DataMap emailDataMap = new DataMap();
|
85
|
76
|
Cursor emails = this.context.getContentResolver().query(
|
86
|
77
|
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
|
87
|
78
|
null,
|
88
|
79
|
ContactsContract.CommonDataKinds.Email.CONTACT_ID + "="
|
89
|
80
|
+ contactId, null, null);
|
90
|
|
int emailIndex = 0;
|
91
|
|
if (emails.getCount() > 0)
|
92
|
|
{
|
93
|
|
emailIndex = emails
|
94
|
|
.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA);
|
|
81
|
int emailIndex = 0;int emailIndex1 = 0;
|
|
82
|
if (emails.getCount() > 0){
|
|
83
|
emailIndex = emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA);
|
|
84
|
emailIndex1 = emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE);
|
95
|
85
|
}
|
96
|
|
while (emails.moveToNext())
|
97
|
|
{
|
98
|
|
email = emails.getString(emailIndex);
|
99
|
|
Log.i(TAG, email);
|
|
86
|
while (emails.moveToNext()){
|
|
87
|
int typename = ContactsContract.CommonDataKinds.Email.getTypeLabelResource(emails.getInt(emailIndex1));
|
|
88
|
String key = this.context.getString(typename);
|
|
89
|
emailDataMap.put(key, emails.getString(emailIndex));
|
100
|
90
|
}
|
101
|
|
return email;
|
|
91
|
return emailDataMap;
|
102
|
92
|
}
|
103
|
93
|
|
104
|
94
|
/**
|
|
@ -111,42 +101,35 @@ public class MobileContactDetail extends Plugin
|
111
|
101
|
* @return
|
112
|
102
|
* @throws
|
113
|
103
|
*/
|
114
|
|
private String getContactPhoneNumber(Cursor c, String contactId)
|
115
|
|
{
|
116
|
|
String hasPhone = c.getString(c
|
117
|
|
.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
|
118
|
|
String phoneNumber = null;
|
119
|
|
if (hasPhone.equalsIgnoreCase("1"))
|
120
|
|
{
|
121
|
|
hasPhone = "true";
|
|
104
|
private DataMap getContactPhoneNumber(Cursor c, String contactId){
|
|
105
|
String hasPhone = c.getString(c.getColumnIndex("has_phone_number"));
|
|
106
|
DataMap phoneDataMap = new DataMap();
|
|
107
|
if (hasPhone.equalsIgnoreCase("1")) {
|
|
108
|
hasPhone = "true";
|
|
109
|
} else {
|
|
110
|
hasPhone = "false";
|
|
111
|
}
|
|
112
|
if (Boolean.parseBoolean(hasPhone)) {
|
|
113
|
Cursor phones = this.context.getContentResolver().query(
|
|
114
|
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
|
115
|
null,
|
|
116
|
"contact_id=" +
|
|
117
|
contactId, null, null);
|
|
118
|
int phoneIndex = 0;int phoneIndex1 = 0;
|
|
119
|
if (phones.getCount() > 0) {
|
|
120
|
phoneIndex = phones.getColumnIndex("data1");
|
|
121
|
phoneIndex1 = phones.getColumnIndex("data2");
|
122
|
122
|
}
|
123
|
|
else
|
124
|
|
{
|
125
|
|
hasPhone = "false";
|
|
123
|
while (phones.moveToNext()) {
|
|
124
|
int typename = ContactsContract.CommonDataKinds.Phone.getTypeLabelResource(phones.getInt(phoneIndex1));
|
|
125
|
String key = this.context.getString(typename);
|
|
126
|
phoneDataMap.put(key, phones.getString(phoneIndex));
|
126
|
127
|
}
|
127
|
|
if (Boolean.parseBoolean(hasPhone))
|
128
|
|
{
|
129
|
|
// 查找该联系人的phone信息
|
130
|
|
Cursor phones = this.context.getContentResolver().query(
|
131
|
|
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
132
|
|
null,
|
133
|
|
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "="
|
134
|
|
+ contactId, null, null);
|
135
|
|
int phoneIndex = 0;
|
136
|
|
if (phones.getCount() > 0)
|
137
|
|
{
|
138
|
|
phoneIndex = phones
|
139
|
|
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
|
140
|
|
}
|
141
|
|
while (phones.moveToNext())
|
142
|
|
{
|
143
|
|
phoneNumber = phones.getString(phoneIndex);
|
144
|
|
Log.d(TAG, phoneNumber);
|
145
|
|
}
|
146
|
|
phones.close();
|
147
|
|
}
|
148
|
|
return phoneNumber;
|
|
128
|
phones.close();
|
|
129
|
}
|
|
130
|
return phoneDataMap;
|
149
|
131
|
}
|
|
132
|
|
150
|
133
|
|
151
|
134
|
/**
|
152
|
135
|
* @Title: getContactName
|
|
@ -155,11 +138,9 @@ public class MobileContactDetail extends Plugin
|
155
|
138
|
* @param c
|
156
|
139
|
* @return
|
157
|
140
|
* @throws
|
158
|
|
*/
|
159
|
|
private String getContactName(Cursor c)
|
160
|
|
{
|
161
|
|
String name = c.getString(c
|
162
|
|
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
|
|
141
|
*/
|
|
142
|
private String getContactName(Cursor c) {
|
|
143
|
String name = c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
|
163
|
144
|
return name;
|
164
|
145
|
}
|
165
|
146
|
|