サンプルの AWS Android SDK アプリである UserPreferenceDemo のコードの一部を使用しています。新しい DynamoDB テーブルを作成できるように、サンプル アプリが動作しています。ただし、アプリに同じコードを実装しようとすると、AmazonClientManager クラスに「認証情報が期限切れになりました」というログ メッセージが表示され、アプリがクラッシュします。
テーブルの作成に使用するコードは次のとおりです。
final Button submit = (Button) findViewById(R.id.bSubmitComplete)
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.i(TAG, "submitBttn clicked.");
new DynamoDBManagerTask()
.execute(DynamoDBManagerType.CREATE_TABLE);
}
});
メッセージをログに記録するコードは次のとおりです。
public Response validateCredentials() {
Response ableToGetToken = Response.SUCCESSFUL;
if (AmazonSharedPreferencesWrapper
.areCredentialsExpired(this.sharedPreferences)) {
synchronized (this) {
if (AmazonSharedPreferencesWrapper
.areCredentialsExpired(this.sharedPreferences)) {
Log.i(LOG_TAG, "Credentials were expired.");
AmazonTVMClient tvm = new AmazonTVMClient( this.sharedPreferences, PropertyLoader.getInstance().getTokenVendingMachineURL(), PropertyLoader.getInstance().useSSL() );
ableToGetToken = tvm.anonymousRegister();
if (ableToGetToken.requestWasSuccessful()) {
ableToGetToken = tvm.getToken();
if (ableToGetToken.requestWasSuccessful()) {
Log.i(LOG_TAG, "Creating New Credentials.");
initClients();
}
}
}
}
} else if (ddb == null) {
synchronized (this) {
if (ddb == null) {
Log.i(LOG_TAG, "Creating New Credentials.");
initClients();
}
}
}
return ableToGetToken;
}