Cordova アプリ内で Android デバイスの登録済み電子メールを取得する必要があります。現在、Cordova 3.3.0 アプリが動作しています。バージョン 2.5 の Cordova プラグインはこの場所でしか見つかりませんでした 。このプラグインは、現在使用しているバージョンと互換性がありません。誰かがこれのために更新されたプラグインを提供しましたか?
2.5 用に構築されたこのプラグインを更新して、3.3.0 と互換性を持たせるにはどうすればよいですか?
プラグインは実際には android.permission.GET_ACCOUNTS からの許可を必要とします
更新: AccountList.java ファイルに対して次のことを行いました
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 < 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);
}
}
}
ここで、オリジナルは -
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);
}
}}
HTMLファイルのスクリプトは次のとおりです-
<script type="text/javascript" charset="utf-8" src="accountlist.js"></script>
<script type="text/javascript" charset="utf-8">
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);
}
);
}
</script>
AccountList is undefined というエラーが表示されます。