@hanwha-ss1/plugin 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
package="com.plugin.openbrowser">
|
|
4
4
|
|
|
5
5
|
<uses-permission android:name="android.permission.INTERNET"/>
|
|
6
|
+
<uses-permission android:name="android.permission.READ_CONTACTS"/>
|
|
7
|
+
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
|
|
6
8
|
|
|
7
9
|
<application>
|
|
8
10
|
<activity
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
package com.plugin.contact;
|
|
2
2
|
|
|
3
|
+
import android.Manifest;
|
|
3
4
|
import android.app.Activity;
|
|
4
|
-
import android.content.
|
|
5
|
+
import android.content.ContentProviderOperation;
|
|
6
|
+
import android.content.ContentResolver;
|
|
7
|
+
import android.content.OperationApplicationException;
|
|
8
|
+
import android.content.pm.PackageManager;
|
|
9
|
+
import android.database.Cursor;
|
|
10
|
+
import android.net.Uri;
|
|
11
|
+
import android.os.RemoteException;
|
|
5
12
|
import android.provider.ContactsContract;
|
|
6
13
|
import android.util.Log;
|
|
7
14
|
|
|
15
|
+
import androidx.core.app.ActivityCompat;
|
|
16
|
+
import androidx.core.content.ContextCompat;
|
|
17
|
+
|
|
18
|
+
import java.util.ArrayList;
|
|
19
|
+
|
|
8
20
|
|
|
9
21
|
public class Contact {
|
|
10
22
|
|
|
@@ -13,29 +25,135 @@ public class Contact {
|
|
|
13
25
|
return value;
|
|
14
26
|
}
|
|
15
27
|
|
|
28
|
+
public interface OnResult {
|
|
29
|
+
void onSuccess();
|
|
30
|
+
void onFail();
|
|
31
|
+
}
|
|
32
|
+
|
|
16
33
|
/**
|
|
17
34
|
* 연락처 저장
|
|
18
35
|
*
|
|
19
36
|
* @param activity
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
24
|
-
* @param
|
|
37
|
+
* @param name 성명
|
|
38
|
+
* @param mobilePhoneNumber 전화번호
|
|
39
|
+
* @param email 이메일
|
|
40
|
+
* @param departmentName 소속
|
|
41
|
+
* @param extensionNumber 내선번호
|
|
25
42
|
*/
|
|
26
|
-
public void save(Activity activity, String name, String email, String mobilePhoneNumber, String extensionNumber, String departmentName) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
public void save(Activity activity, String name, String email, String mobilePhoneNumber, String extensionNumber, String departmentName, OnResult result) {
|
|
44
|
+
if(checkPermission(activity)) {
|
|
45
|
+
if (hasContacts(activity, mobilePhoneNumber)) {
|
|
46
|
+
if (result != null) {
|
|
47
|
+
result.onFail();
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
saveContacts(activity, name, email, mobilePhoneNumber, extensionNumber, departmentName);
|
|
51
|
+
result.onSuccess();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private boolean checkPermission(Activity activity) {
|
|
57
|
+
if (ContextCompat.checkSelfPermission(activity, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED
|
|
58
|
+
&& ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
|
|
59
|
+
return true;
|
|
60
|
+
} else {
|
|
61
|
+
ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS, }, 101);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public boolean hasContacts(Activity activity, String key) {
|
|
67
|
+
ArrayList<String> names = new ArrayList<>();
|
|
68
|
+
ContentResolver resolver = activity.getContentResolver();
|
|
69
|
+
|
|
70
|
+
Uri phoneUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(key));
|
|
71
|
+
|
|
72
|
+
String[] projection = {
|
|
73
|
+
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
Cursor cursor = resolver.query(phoneUri, projection, null, null, null);
|
|
77
|
+
|
|
78
|
+
if (cursor != null) {
|
|
79
|
+
while (cursor.moveToNext()) {
|
|
80
|
+
int nameIndex = cursor.getColumnIndex(projection[0]);
|
|
81
|
+
String name = cursor.getString(nameIndex);
|
|
82
|
+
names.add(name);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
cursor.close();
|
|
87
|
+
|
|
88
|
+
return names.size() > 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public void saveContacts(Activity activity, String name, String email, String mobilePhoneNumber, String extensionNumber, String departmentName) {
|
|
92
|
+
new Thread() {
|
|
93
|
+
@Override
|
|
94
|
+
public void run() {
|
|
95
|
+
try {
|
|
96
|
+
ArrayList<ContentProviderOperation> list = new ArrayList<>();
|
|
97
|
+
|
|
98
|
+
list.add(
|
|
99
|
+
ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
|
|
100
|
+
.withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
|
|
101
|
+
.withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
|
|
102
|
+
.build());
|
|
103
|
+
|
|
104
|
+
list.add(
|
|
105
|
+
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
|
106
|
+
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
|
107
|
+
|
|
108
|
+
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
|
|
109
|
+
.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name)
|
|
110
|
+
.build());
|
|
111
|
+
|
|
112
|
+
list.add(
|
|
113
|
+
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
|
114
|
+
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
|
115
|
+
|
|
116
|
+
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
|
|
117
|
+
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, mobilePhoneNumber)
|
|
118
|
+
.withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE)
|
|
119
|
+
.build());
|
|
120
|
+
|
|
121
|
+
list.add(
|
|
122
|
+
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
|
123
|
+
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
|
124
|
+
|
|
125
|
+
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
|
|
126
|
+
.withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, extensionNumber)
|
|
127
|
+
.withValue(ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_WORK)
|
|
128
|
+
.build());
|
|
129
|
+
|
|
130
|
+
list.add(
|
|
131
|
+
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
|
132
|
+
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
|
133
|
+
|
|
134
|
+
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
|
|
135
|
+
.withValue(ContactsContract.CommonDataKinds.Email.DATA, email)
|
|
136
|
+
.withValue(ContactsContract.CommonDataKinds.Email.TYPE, ContactsContract.CommonDataKinds.Email.TYPE_WORK)
|
|
137
|
+
.build());
|
|
138
|
+
|
|
139
|
+
list.add(
|
|
140
|
+
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
|
|
141
|
+
.withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
|
|
142
|
+
|
|
143
|
+
.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
|
|
144
|
+
.withValue(ContactsContract.CommonDataKinds.Organization.COMPANY, departmentName)
|
|
145
|
+
.withValue(ContactsContract.CommonDataKinds.Organization.TYPE, ContactsContract.CommonDataKinds.Organization.TYPE_WORK)
|
|
146
|
+
.build());
|
|
147
|
+
|
|
148
|
+
activity.getContentResolver().applyBatch(ContactsContract.AUTHORITY, list);
|
|
39
149
|
|
|
150
|
+
list.clear();
|
|
151
|
+
} catch (OperationApplicationException e) {
|
|
152
|
+
e.printStackTrace();
|
|
153
|
+
} catch (RemoteException e) {
|
|
154
|
+
e.printStackTrace();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}.start();
|
|
40
158
|
}
|
|
41
|
-
}
|
|
159
|
+
}
|
|
@@ -30,6 +30,22 @@ public class ContactPlugin extends Plugin{
|
|
|
30
30
|
if(implementation == null) {
|
|
31
31
|
implementation = new Contact();
|
|
32
32
|
}
|
|
33
|
-
implementation.save(getActivity(), name, email, mobile, phone, department)
|
|
33
|
+
implementation.save(getActivity(), name, email, mobile, phone, department, new Contact.OnResult() {
|
|
34
|
+
@Override
|
|
35
|
+
public void onSuccess() {
|
|
36
|
+
JSObject ret = new JSObject();
|
|
37
|
+
ret.put("result", true);
|
|
38
|
+
ret.put("message", "완료");
|
|
39
|
+
call.resolve(ret);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Override
|
|
43
|
+
public void onFail() {
|
|
44
|
+
JSObject ret = new JSObject();
|
|
45
|
+
ret.put("result", false);
|
|
46
|
+
ret.put("message", "존재하는 번호입니다.");
|
|
47
|
+
call.resolve(ret);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
34
50
|
}
|
|
35
51
|
}
|