|
11 | 11 | import com.phonegap.api.PluginResult; |
12 | 12 |
|
13 | 13 | public class ContactView extends Plugin { |
14 | | - private static final int PICK_CONTACT = 1; |
15 | | - private String name = null; |
16 | | - public String callback; |
17 | | - |
| 14 | + private static final int PICK_CONTACT = 1; |
| 15 | + private String name = null; |
| 16 | + public String callback; |
| 17 | + |
18 | 18 | @Override |
19 | 19 | public PluginResult execute(String action, JSONArray args, String callbackId) { |
20 | 20 | startContactActivity(); |
21 | | - PluginResult mPlugin = new PluginResult(PluginResult.Status.NO_RESULT); |
| 21 | + PluginResult mPlugin = new PluginResult(PluginResult.Status.NO_RESULT); |
22 | 22 | mPlugin.setKeepCallback(true); |
23 | 23 | this.callback = callbackId; |
24 | 24 | return mPlugin; |
25 | 25 | } |
26 | 26 |
|
27 | 27 | public void startContactActivity() { |
28 | | - Intent intent = new Intent(Intent.ACTION_PICK); |
29 | | - intent.setType(ContactsContract.Contacts.CONTENT_TYPE); |
30 | | - this.ctx.startActivityForResult((Plugin) this, intent, PICK_CONTACT); |
31 | | - } |
32 | | - |
| 28 | + Intent intent = new Intent(Intent.ACTION_PICK); |
| 29 | + intent.setType(ContactsContract.Contacts.CONTENT_TYPE); |
| 30 | + this.ctx.startActivityForResult((Plugin) this, intent, PICK_CONTACT); |
| 31 | + } |
| 32 | + |
33 | 33 | @Override |
34 | 34 | public void onActivityResult(int reqCode, int resultCode, Intent data) { |
35 | | - switch (reqCode) { |
36 | | - case (PICK_CONTACT) : |
37 | | - if (resultCode == Activity.RESULT_OK) { |
38 | | - Uri contactData = data.getData(); |
39 | | - Cursor c = this.ctx.managedQuery(contactData, null, null, null, null); |
40 | | - if (c.moveToFirst()) { |
41 | | - name = c.getString(c.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)); |
42 | | - this.success(new PluginResult(PluginResult.Status.OK, name), this.callback); |
43 | | - } |
44 | | - } |
45 | | - break; |
46 | | - } |
47 | | - } |
| 35 | + switch (reqCode) { |
| 36 | + case (PICK_CONTACT): |
| 37 | + if (resultCode == Activity.RESULT_OK) { |
| 38 | + Uri contactData = data.getData(); |
| 39 | + Cursor c = this.ctx.managedQuery(contactData, null, null, null, |
| 40 | + null); |
| 41 | + if (c.moveToFirst()) { |
| 42 | + name = c.getString(c |
| 43 | + .getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)); |
| 44 | + this.success( |
| 45 | + new PluginResult(PluginResult.Status.OK, name), |
| 46 | + this.callback); |
| 47 | + } |
| 48 | + } |
| 49 | + break; |
| 50 | + } |
| 51 | + } |
48 | 52 |
|
49 | 53 | } |
0 commit comments