开发者

Android getAuthToken returning null

I'm using getAuthToken() to get a Token a then login in a Google App Engine aplication.

It used to work, untill today, i dont know why getAuthToken() is returning null.

I checked the account i pass to it, and it's ok. So I can't imagine what's happening.

private class GetAuthTokenTask extends AsyncTask<Account, Object, String> {
        String TAG="GetAuthTokenTask";
        @Override
        protected String doInBackground(Account... accounts) {
            AccountManager manager = AccountManager.get(getApplicationContext());
            Account account = accounts[0];
            String token = this.buildToken(manager, account);
            manager.invalidateAuthToken(account.type, token);
            return this.buildToken(manager, account);
        }

        private String buildToken(AccountManager manager, Account account) {
            try {

                AccountManagerFuture<Bundle> future = manager.getAuthToken (account, "ah", false, null, null);
                Bundle bundle 开发者_开发问答= future.getResult();
                System.out.println("Token: "+bundle.getString(AccountManager.KEY_AUTHTOKEN) +"\n");
                return bundle.getString(AccountManager.KEY_AUTHTOKEN);
             } catch (OperationCanceledException e) {
                    Log.w(TAG, e.getMessage());
             } catch (AuthenticatorException e) {
                    Log.w(TAG, e.getMessage());
             } catch (IOException e) {
                    Log.w(TAG, e.getMessage());
             }
             return null;
        }

        protected void onPostExecute(String authToken) {
            //Log.i("onPostExecute","GetCookieTask");
            new GetCookieTask().execute(authToken);    
        }
    }

Edit

I found the solution myself:

In the getAuthToken() method I changed the third parameter to true, so it will show a warning in the status bar asking for permission. I don't know why Android didn't ask before, like just after I installed the application.


The getAuthToken(Account, String, boolean, AccountManagerCallback<Bundle>, Handler) method is deprecated.

Use getAuthToken(Account, String, Bundle, Activity, AccountManagerCallback<Bundle>, Handler) or getAuthToken(Account, String, Bundle, boolean, AccountManagerCallback<Bundle>, Handler) instead.

First one works for me.

Android Documentation


copied from the question edit:

I found the solution myself:

In the getAuthToken() method I changed the third parameter to true, so it will show a warning in the status bar asking for permission. I don't know why Android didn't ask before, like just after I installed the application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜