@hanwha-ss1/plugin 0.1.1 → 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.
@@ -1,15 +1,20 @@
1
1
  package com.plugin.contact;
2
2
 
3
+ import android.Manifest;
3
4
  import android.app.Activity;
4
5
  import android.content.ContentProviderOperation;
5
6
  import android.content.ContentResolver;
6
7
  import android.content.OperationApplicationException;
8
+ import android.content.pm.PackageManager;
7
9
  import android.database.Cursor;
8
10
  import android.net.Uri;
9
11
  import android.os.RemoteException;
10
12
  import android.provider.ContactsContract;
11
13
  import android.util.Log;
12
14
 
15
+ import androidx.core.app.ActivityCompat;
16
+ import androidx.core.content.ContextCompat;
17
+
13
18
  import java.util.ArrayList;
14
19
 
15
20
 
@@ -29,25 +34,37 @@ public class Contact {
29
34
  * 연락처 저장
30
35
  *
31
36
  * @param activity
32
- * @param options name : 성명
33
- * @param options mobilePhoneNumber : 전화번호
34
- * @param options email : 이메일
35
- * @param options departmentName : 소속
36
- * @param options extensionNumber : 내선번호
37
+ * @param name 성명
38
+ * @param mobilePhoneNumber 전화번호
39
+ * @param email 이메일
40
+ * @param departmentName 소속
41
+ * @param extensionNumber 내선번호
37
42
  */
38
43
  public void save(Activity activity, String name, String email, String mobilePhoneNumber, String extensionNumber, String departmentName, OnResult result) {
39
- if(hasContacts(activity, mobilePhoneNumber)) {
40
- if(result != null) {
41
- result.onFail();
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();
42
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;
43
60
  } else {
44
- saveContacts(activity, name, email, mobilePhoneNumber, extensionNumber, departmentName);
45
- result.onSuccess();
61
+ ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_CONTACTS, }, 101);
62
+ return false;
46
63
  }
47
64
  }
48
65
 
49
66
  public boolean hasContacts(Activity activity, String key) {
50
- ArrayList<String> datas = new ArrayList<>();
67
+ ArrayList<String> names = new ArrayList<>();
51
68
  ContentResolver resolver = activity.getContentResolver();
52
69
 
53
70
  Uri phoneUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(key));
@@ -62,13 +79,13 @@ public class Contact {
62
79
  while (cursor.moveToNext()) {
63
80
  int nameIndex = cursor.getColumnIndex(projection[0]);
64
81
  String name = cursor.getString(nameIndex);
65
- datas.add(name);
82
+ names.add(name);
66
83
  }
67
84
  }
68
85
 
69
86
  cursor.close();
70
87
 
71
- return datas.size() > 0;
88
+ return names.size() > 0;
72
89
  }
73
90
 
74
91
  public void saveContacts(Activity activity, String name, String email, String mobilePhoneNumber, String extensionNumber, String departmentName) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanwha-ss1/plugin",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",