私はandroid.accountsapisを初めて使用し、それらを使って何かをしようとしていますが、ダミーの問題が発生しているようです...
アプリのオーセンティケーターを作成しましたが、抽象メソッドをまだ実装していません。そのアイコンがシステムの[アカウントの追加]ウィンドウに正常に表示されます。クリックすると、オーセンティケーターのメソッドaddAccountが呼び出されることがわかります。
ここで、このメソッドで簡単なことを行い、以下のコードを記述します。
@Override
public Bundle addAccount(AccountAuthenticatorResponse response,
String accountType, String authTokenType, String[] requiredFeatures,
Bundle options) {
Log.d(LOG_TAG, "RRAuthenticator add account... ");
String accountName = "example@example.com";
Account account = new Account(accountName, accountType);
String password = "example_password";
AccountManager manager = AccountManager.get(context);
manager.addAccountExplicitly(account, password, null);
Bundle bundle = new Bundle();
bundle.putString(AccountManager.KEY_ACCOUNT_NAME, accountName);
bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, accountType);
bundle.putString(AccountManager.KEY_AUTHTOKEN, "example_authtoken");
return bundle;
}
SampleSyncAdapterのデモを見て、そのような動きをします。ただし、アカウントを直接追加して、これらのAPIの使用を練習しています。しかし、システムが回線によってクラッシュしましたmanager.addAccountExplicitly(account, password, null);
。何が問題になっていますか?
後で追加:システムプロセスの例外。システムがクラッシュします。AccountManagerによるNullPointerExceptionスロー。このステートメントにコメントしているので、addAccountExplicitlyメソッドの問題のようです。クラッシュは発生しません。