Search in sources :

Example 6 with OperationCanceledException

use of android.accounts.OperationCanceledException in project apps-android-commons by commons-app.

the class CommonsApplication method revalidateAuthToken.

public Boolean revalidateAuthToken() {
    AccountManager accountManager = AccountManager.get(this);
    Account curAccount = getCurrentAccount();
    if (curAccount == null) {
        // This should never happen
        return false;
    }
    accountManager.invalidateAuthToken(AccountUtil.accountType(), getMWApi().getAuthCookie());
    try {
        String authCookie = accountManager.blockingGetAuthToken(curAccount, "", false);
        getMWApi().setAuthCookie(authCookie);
        return true;
    } catch (OperationCanceledException | NullPointerException | IOException | AuthenticatorException e) {
        e.printStackTrace();
        return false;
    }
}
Also used : Account(android.accounts.Account) OperationCanceledException(android.accounts.OperationCanceledException) AuthenticatorException(android.accounts.AuthenticatorException) AccountManager(android.accounts.AccountManager) IOException(java.io.IOException)

Example 7 with OperationCanceledException

use of android.accounts.OperationCanceledException in project Android-AccountChooser by frakbot.

the class ChooseTypeAndAccountActivity method run.

@Override
public void run(final AccountManagerFuture<Bundle> accountManagerFuture) {
    try {
        final Bundle accountManagerResult = accountManagerFuture.getResult();
        final Intent intent = (Intent) accountManagerResult.getParcelable(AccountManager.KEY_INTENT);
        if (intent != null) {
            mPendingRequest = REQUEST_ADD_ACCOUNT;
            mExistingAccounts = AccountManager.get(this).getAccounts();
            intent.setFlags(intent.getFlags() & ~Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivityForResult(intent, REQUEST_ADD_ACCOUNT);
            return;
        }
    } catch (OperationCanceledException e) {
        setResult(Activity.RESULT_CANCELED);
        finish();
        return;
    } catch (IOException e) {
    } catch (AuthenticatorException e) {
    }
    Bundle bundle = new Bundle();
    bundle.putString(AccountManager.KEY_ERROR_MESSAGE, "error communicating with server");
    setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
    finish();
}
Also used : Bundle(android.os.Bundle) OperationCanceledException(android.accounts.OperationCanceledException) AuthenticatorException(android.accounts.AuthenticatorException) Intent(android.content.Intent) IOException(java.io.IOException)

Example 8 with OperationCanceledException

use of android.accounts.OperationCanceledException in project AndroidSDK-RecipeBook by gabu.

the class Recipe098 method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // GoogleTransportを作る
    mTransport = GoogleTransport.create();
    GoogleHeaders headers = (GoogleHeaders) mTransport.defaultHeaders;
    // "[company-id]-[app-name]-[app-version]"という形式で
    // アプリケーション名をセット
    headers.setApplicationName("gabu-recipe-98");
    // バージョンをセット
    headers.gdataVersion = "3";
    // AtomParserを作る
    AtomParser parser = new AtomParser();
    // GoogleDocumentsListのネームスペースをセット
    parser.namespaceDictionary = Namespace.DICTIONARY;
    // GoogleTransportにAtomParserをセット
    mTransport.addParser(parser);
    // HttpTransportにApacheHttpTransportのインスタンスをセット
    // これをやっておかないとExceptionが発生します。
    HttpTransport.setLowLevelHttpTransport(ApacheHttpTransport.INSTANCE);
    // AccountManagerを取得
    AccountManager manager = AccountManager.get(this);
    // Googleアカウントの一覧を取得
    Account[] accounts = manager.getAccountsByType("com.google");
    // サンプルなので暫定的に1つ目を取得
    Account acount = accounts[0];
    // 認証のためのauth tokenを取得
    AccountManagerFuture<Bundle> f = manager.getAuthToken(acount, DOCS_AUTH_TOKEN_TYPE, null, this, null, null);
    try {
        Bundle b = f.getResult();
        mAuthToken = b.getString(AccountManager.KEY_AUTHTOKEN);
    //            Log.d(TAG, "authToken=" + mAuthToken);
    } catch (OperationCanceledException e) {
        e.printStackTrace();
    } catch (AuthenticatorException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // GoogleTransportにauth tokenをセット
    // これで認証ヘッダを自動的に付けてくれます。
    ((GoogleHeaders) mTransport.defaultHeaders).setGoogleLogin(mAuthToken);
    // Googleドキュメントの一覧を取得するURLを作成
    String url = GOOGLE_DOCS_API_URL + "default/private/full/-/document";
    // GoogleTransportからGETリクエストを生成
    HttpRequest request = mTransport.buildGetRequest();
    // URLをセット
    request.setUrl(url);
    try {
        // HTTPリクエストを実行してレスポンスをパース
        DocumentListFeed feed = request.execute().parseAs(DocumentListFeed.class);
        // DocsAdapterを生成
        DocsAdapter adapter = new DocsAdapter(getApplicationContext(), 0, feed.entries);
        // ListViewにDocsAdapterをセット
        ListView listView = (ListView) findViewById(R.id.list_view);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(mOnItemClickListener);
    } catch (IOException e) {
        handleException(e);
    }
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) Account(android.accounts.Account) GoogleHeaders(com.google.api.client.googleapis.GoogleHeaders) Bundle(android.os.Bundle) OperationCanceledException(android.accounts.OperationCanceledException) AuthenticatorException(android.accounts.AuthenticatorException) IOException(java.io.IOException) AtomParser(com.google.api.client.xml.atom.AtomParser) ListView(android.widget.ListView) AccountManager(android.accounts.AccountManager)

Example 9 with OperationCanceledException

use of android.accounts.OperationCanceledException in project AndroidSDK-RecipeBook by gabu.

the class Recipe101 method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mTransport = GoogleTransport.create();
    GoogleHeaders headers = (GoogleHeaders) mTransport.defaultHeaders;
    // "[company-id]-[app-name]-[app-version]"という形式で
    // アプリケーション名をセット
    headers.setApplicationName("gabu-recipe-101");
    // バージョンをセット
    headers.gdataVersion = "2";
    // AtomParserを作る
    AtomParser parser = new AtomParser();
    // GoogleCalendarのネームスペースをセット
    parser.namespaceDictionary = Namespace.DICTIONARY;
    // GoogleTransportにAtomParserをセット
    mTransport.addParser(parser);
    // HttpTransportにApacheHttpTransportのインスタンスをセット
    // これをやっておかないとExceptionが発生します。
    HttpTransport.setLowLevelHttpTransport(ApacheHttpTransport.INSTANCE);
    // AccountManagerを取得
    AccountManager manager = AccountManager.get(this);
    // Googleアカウントの一覧を取得
    Account[] accounts = manager.getAccountsByType("com.google");
    // サンプルなので暫定的に1つ目を取得
    Account acount = accounts[0];
    // 認証のためのauth tokenを取得
    AccountManagerFuture<Bundle> f = manager.getAuthToken(acount, CAL_AUTH_TOKEN_TYPE, null, this, null, null);
    try {
        Bundle b = f.getResult();
        mAuthToken = b.getString(AccountManager.KEY_AUTHTOKEN);
    //            Log.d(TAG, "authToken=" + mAuthToken);
    } catch (OperationCanceledException e) {
        e.printStackTrace();
    } catch (AuthenticatorException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // GoogleTransportにauth tokenをセット
    // これで認証ヘッダを自動的に付けてくれます。
    ((GoogleHeaders) mTransport.defaultHeaders).setGoogleLogin(mAuthToken);
    // GoogleTransportからGETリクエストを生成
    HttpRequest request = mTransport.buildGetRequest();
    // Googleカレンダーの一覧を取得するURLを作成
    // 共有しているカレンダーも含む
    //        String url = GOOGLE_CAL_API_URL + "default/allcalendars/full";
    // 自分がオーナーのカレンダーのみ
    String url = GOOGLE_CAL_API_URL + "default/owncalendars/full";
    // URLをセット
    request.setUrl(url);
    try {
        // HTTPリクエストを実行してレスポンスをパース
        CalendarFeed feed = request.execute().parseAs(CalendarFeed.class);
        for (CalendarEntry entry : feed.entries) {
            Log.d(TAG, entry.title + ", " + entry.id);
        }
        // サンプルのためカレンダーの1つ目を取得
        CalendarEntry entry = feed.entries.get(0);
        // このuserIDがカレンダーを一意に特定するIDになります。
        String userID = entry.getUserID();
        // 何も指定せずに予定の一覧を取得
        url = GOOGLE_CAL_API_URL + userID + "/private/full";
        debug(request, url);
    // 2010年6月の予定の一覧を取得
    //            url = createMonthlyUrl(userID, 2010, 6);
    //            debug(request, url);
    // 2010年6月30日の予定の一覧
    //            url = createDailyUrl(userID, 2010, 6, 30);
    //            debug(request, url);
    } catch (IOException e) {
        handleException(e);
    }
}
Also used : HttpRequest(com.google.api.client.http.HttpRequest) Account(android.accounts.Account) GoogleHeaders(com.google.api.client.googleapis.GoogleHeaders) Bundle(android.os.Bundle) OperationCanceledException(android.accounts.OperationCanceledException) AuthenticatorException(android.accounts.AuthenticatorException) IOException(java.io.IOException) AtomParser(com.google.api.client.xml.atom.AtomParser) AccountManager(android.accounts.AccountManager)

Example 10 with OperationCanceledException

use of android.accounts.OperationCanceledException in project android by owncloud.

the class ManageAccountsActivity method createAccount.

@Override
public void createAccount() {
    AccountManager am = AccountManager.get(getApplicationContext());
    am.addAccount(MainApp.getAccountType(), null, null, null, this, new AccountManagerCallback<Bundle>() {

        @Override
        public void run(AccountManagerFuture<Bundle> future) {
            if (future != null) {
                try {
                    Bundle result = future.getResult();
                    String name = result.getString(AccountManager.KEY_ACCOUNT_NAME);
                    AccountUtils.setCurrentOwnCloudAccount(getApplicationContext(), name);
                    mAccountListAdapter = new AccountListAdapter(ManageAccountsActivity.this, getAccountListItems(), mTintedCheck);
                    mListView.setAdapter(mAccountListAdapter);
                    runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            mAccountListAdapter.notifyDataSetChanged();
                        }
                    });
                } catch (OperationCanceledException e) {
                    Log_OC.d(TAG, "Account creation canceled");
                } catch (Exception e) {
                    Log_OC.e(TAG, "Account creation finished in exception: ", e);
                }
            }
        }
    }, mHandler);
}
Also used : Bundle(android.os.Bundle) OperationCanceledException(android.accounts.OperationCanceledException) AccountManager(android.accounts.AccountManager) AccountListAdapter(com.owncloud.android.ui.adapter.AccountListAdapter) OperationCanceledException(android.accounts.OperationCanceledException)

Aggregations

OperationCanceledException (android.accounts.OperationCanceledException)15 IOException (java.io.IOException)13 AuthenticatorException (android.accounts.AuthenticatorException)11 Bundle (android.os.Bundle)11 Account (android.accounts.Account)8 AccountManager (android.accounts.AccountManager)7 Intent (android.content.Intent)3 AccountsException (android.accounts.AccountsException)2 Cursor (android.database.Cursor)2 UserHandle (android.os.UserHandle)2 GoogleHeaders (com.google.api.client.googleapis.GoogleHeaders)2 HttpRequest (com.google.api.client.http.HttpRequest)2 AtomParser (com.google.api.client.xml.atom.AtomParser)2 AccountManagerCallback (android.accounts.AccountManagerCallback)1 PendingIntent (android.app.PendingIntent)1 ContentProviderClient (android.content.ContentProviderClient)1 ContentProviderOperation (android.content.ContentProviderOperation)1 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 RemoteException (android.os.RemoteException)1