을 읽고 도움이 될 것입니다 : 나는 다음을 다시 변경, https에서 http로 초기 쿠키 요청에 대한 URL을 변경했습니다.
결국에는 구현을 변경하고 alistair가 제안한대로 loopj으로 이동하기로 결정했습니다. 결과는 훨씬 더 우아합니다.
public class AccountList extends ListActivity {
protected AccountManager accountManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
accountManager = AccountManager.get(getApplicationContext());
Account[] accounts = accountManager.getAccountsByType("com.google");
this.setListAdapter(new ArrayAdapter<Account>(this, R.layout.list_item, accounts));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Account account = (Account)getListView().getItemAtPosition(position);
accountManager.invalidateAuthToken("com.google", null);
accountManager.getAuthToken(account, "ah", null, this, new GetAuthTokenCallback(), null);
}
private class GetAuthTokenCallback implements AccountManagerCallback<Bundle> {
public void run(AccountManagerFuture<Bundle> result) {
AsyncHttpClient client = new AsyncHttpClient();
PersistentCookieStore myCookieStore = new PersistentCookieStore(getBaseContext());
client.setCookieStore(myCookieStore);
try {
Bundle bundle;
bundle = result.getResult();
Intent intent = (Intent)bundle.get(AccountManager.KEY_INTENT);
if(intent != null) {
// User input required
startActivity(intent);
} else {
String token = bundle.getString(AccountManager.KEY_AUTHTOKEN);
String url = "http://myapp.appspot.com/_ah/login?continue=http://localhost/&auth=" + token;
client.post(url, new AsyncHttpResponseHandler());
Intent backToMainActivity = new Intent(getApplicationContext(), MainActivity.class);
startActivity(backToMainActivity);
}
} catch (OperationCanceledException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AuthenticatorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
loopj는 영구 쿠키의 저장 공간을 제공하기 때문에
, 나는 다른 활동에 할 일은 초기화하는 것입니다 : 이것은 내 로그인 활동 (내가 loopj API에 의해 주어진 영구 쿠키의 저장 장치에 클라이언트를 연결하고있어주의)이다 클라이언트에 저장하고 영구 쿠키 저장소에 연결합니다. 이렇게하면 로그인 활동에서 얻은 모든 쿠키가 새 클라이언트에 제공됩니다.
AsyncHttpClient client = new AsyncHttpClient();
client.setCookieStore(new PersistentCookieStore(this));
이 BTW &가 참고 : :이 loopj 라이브러리가 쿠키를 저장하기 위해 SharedPreferences
API를 사용하며 PersistentCookieStore
으로 잘 감싸고 초기화는 다음과 같이 보인다.
출처
2012-12-23 11:28:57
Uri
내 대답이 실제로 맞았습니까? – alistair
네, 정확한 위치로 정확히 지적했는데, 그 이유는 제가 업 그레 이드 된 이유입니다. 약간 설명이 부족했습니다. – Uri