1

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 というエラーが表示されます。

4

1 に答える 1

0

cordova プラグインに連絡して、Android デバイスから登録済みのメール アドレスを取得してみてください

https://github.com/apache/cordova-plugin-contacts

function onSuccess(contacts) {
    alert('Found ' + navigator.contacts.length + ' navigator.contacts.');
};

function onError(contactError) {
    alert('onError!');
};

// find all contacts with 'Bob' in any name field
var options      = new ContactFindOptions();
options.filter   = "Bob";
options.multiple = true;
var fields       = ["displayName", "name","email"];
navigator.contacts.find(fields, onSuccess, onError, options);
于 2014-03-10T09:17:41.507 に答える