title: Phonegap plugin (Version >=3.0) to retrieve registered email address of an Android device
body: <p>I need to get the registered email of an Android device within my Cordova App. I currently have a Cordova 3.3.0 app working; and I could only find the Cordova plugin for version 2.5 at <a href="https://github.com/seltzlab/AccountList-Phonegap-Android-Plugin" rel="nofollow">this place</a>
  This plugin is not compatible with the version I am currently using. Has anyone provided an updated plugin for this?</p>
  
  <p>How to update this plugin which is built for 2.5, to make it compatible to 3.3.0? </p>
  
  <p>The plugin actually needs permission from android.permission.GET_ACCOUNTS</p>
  
  <p><strong>UPDATE:</strong> I did the following to the AccountList.java file</p>
  
  <pre><code>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 android.content.Context;
  
  import org.apache.cordova.*;
  
  import org.apache.cordova.CordovaInterface;
  import org.apache.cordova.CordovaPlugin;
  import org.apache.cordova.CordovaWebView;
  import org.apache.cordova.PluginResult;
  
  public class AccountList extends CordovaPlugin {
  
  private Context ctx;
  
  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 &lt; 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);
  }
  }
  }
  </code></pre>
  
  <p>where, the original is -</p>
  
  <pre><code>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 &lt; 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);        
  }   
  }}
  </code></pre>
  
  <p>and my script in the HTML file is as follows -</p>
  
  <pre><code>  &lt;script type="text/javascript" charset="utf-8" src="accountlist.js"&gt;&lt;/script&gt;
  
          &lt;script type="text/javascript" charset="utf-8"&gt;
          function getAccs(){
          alert("get the Accounts function starts")
  
          cordova.define("com.seltzlab.mobile.AccountList")
  
          window.plugins.AccountList.get(
                  {
                      type: 'gmail' // if not specified get all accounts
                  }, 
                  function (result) {
                      alert(res.length);
              for (i in res)
                  alert(res[i]);
                  },
                  function (error) {
                      alert(error);
                  }
              );
  
          }
          &lt;/script&gt;
  </code></pre>
  
  <p>I am getting an error saying AccountList is undefined. </p>