Question

I'm trying to integrate dropbox upload in my app. I've read the official examples and I was able to write a client to upload the files. Now there is just one thing that I'd like to fix.. the example first run this line of code:

mDBApi.getSession().startOAuth2Authentication(MainActivity.this);

and then use OnResume to complete the auth:

protected void onResume() {
    super.onResume();
    if (mDBApi.getSession().authenticationSuccessful()) {
        try {
            // Required to complete auth, sets the access token on the session
            mDBApi.getSession().finishAuthentication();

            String accessToken = mDBApi.getSession().getOAuth2AccessToken();
        } catch (IllegalStateException e) {
            Log.i("DbAuthLog", "Error authenticating", e);
        }
    }
    new myOperation().execute("");
}

This works, but I was looking for a way to replace the onResume (that is also called when the app start and cause some exceptions). Is there a way to call a function when the mDBApi.getSession().startOAuth2Authentication(MainActivity.this); ends ?

Thanks for the help, and as usual, if you need further infos please ask

Était-ce utile?

La solution

if this is the only way available by the API, then you have to use it if you have a control over what startOAuth2Authentication do, you can use startActivityForResult() , but its inside API you can't change it.

so i would suggest you handle whatever exceptions you get at onResume() by using some validations, like wrapping whole code inside onResume() with this

if(mDBApi!=null){...
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top