19

Google の Android ドキュメント ( http://developer.android.com/reference/android/accounts/AccountManager.html#addAccountExplicitly(android.accounts.Account, java.lang.String, android.os.Bundle) ) は次のように述べています。

戻り値

アカウントが正常に追加された場合は true、アカウントが既に存在する場合、アカウントが null である場合、または別のエラーが発生した場合は false

私は偽になっています。具体的には、これを引き起こす可能性のある他のエラーは何ですか?

4

3 に答える 3

1

AccountManagerServiceは、アカウントを管理する実際のシステム サービスですが、AccountManagerすべてのバインドされたサービス関連のものをフードの下に隠す単なるプロキシです。

addAccountInternalメソッド from メソッドの以下のソース コードは、このメソッドの実行の代わりにfor thenがスローされることAccountManagerServiceを除いて、ほぼ一目瞭然です。nullaccountIllegalArgumentException

private boolean addAccountInternal(UserAccounts accounts, Account account, String password,
        Bundle extras, boolean restricted, int callingUid) {
    if (account == null) {
        return false;
    }
    synchronized (accounts.cacheLock) {
        final SQLiteDatabase db = accounts.openHelper.getWritableDatabase();
        db.beginTransaction();
        try {
            long numMatches = DatabaseUtils.longForQuery(db,
                    "select count(*) from " + TABLE_ACCOUNTS
                            + " WHERE " + ACCOUNTS_NAME + "=? AND " + ACCOUNTS_TYPE+ "=?",
                    new String[]{account.name, account.type});
            if (numMatches > 0) {
                Log.w(TAG, "insertAccountIntoDatabase: " + account
                        + ", skipping since the account already exists");
                return false;
            }
            ContentValues values = new ContentValues();
            values.put(ACCOUNTS_NAME, account.name);
            values.put(ACCOUNTS_TYPE, account.type);
            values.put(ACCOUNTS_PASSWORD, password);
            values.put(ACCOUNTS_LAST_AUTHENTICATE_TIME_EPOCH_MILLIS, System.currentTimeMillis());
            long accountId = db.insert(TABLE_ACCOUNTS, ACCOUNTS_NAME, values);
            if (accountId < 0) {
                Log.w(TAG, "insertAccountIntoDatabase: " + account
                        + ", skipping the DB insert failed");
                return false;
            }
            if (extras != null) {
                for (String key : extras.keySet()) {
                    final String value = extras.getString(key);
                    if (insertExtraLocked(db, accountId, key, value) < 0) {
                        Log.w(TAG, "insertAccountIntoDatabase: " + account
                                + ", skipping since insertExtra failed for key " + key);
                        return false;
                    }
                }
            }
            db.setTransactionSuccessful();

            logRecord(db, DebugDbHelper.ACTION_ACCOUNT_ADD, TABLE_ACCOUNTS, accountId,
                    accounts, callingUid);

            insertAccountIntoCacheLocked(accounts, account);
        } finally {
            db.endTransaction();
        }
        sendAccountsChangedBroadcast(accounts.userId);
    }
    if (accounts.userId == UserHandle.USER_OWNER) {
        addAccountToLimitedUsers(account);
    }
    return true;
}

結論:必要なアカウントが既に存在する場合、または何らかの SQLite データベース エラーによってアカウント関連の情報がデータベースに保存されなかった場合addAccountExplicitlyに返されます。false

于 2016-08-11T13:47:42.047 に答える