-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAccountList.java
More file actions
42 lines (30 loc) · 971 Bytes
/
AccountList.java
File metadata and controls
42 lines (30 loc) · 971 Bytes
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
package com.seltzlab.mobile;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.accounts.Account;
import android.accounts.AccountManager;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
public class AccountList extends Plugin {
@Override
public PluginResult execute(String action, JSONArray args, String callbackId) {
try {
JSONObject obj = args.getJSONObject(0);
AccountManager am = AccountManager.get(this.ctx);
Account[] accounts;
if (obj.has("type"))
accounts = am.getAccountsByType(obj.getString("type"));
else
accounts = am.getAccounts();
JSONArray res = new JSONArray();
for (int i = 0; i < accounts.length; i++) {
Account a = accounts[i];
res.put(a.name);
}
return new PluginResult(PluginResult.Status.OK, res);
} catch (JSONException e) {
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}
}