We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
carminelaf
8 years agoNew member | Level 2
Android API get account email
I am not able to get the user account email after the authentication:
I have this code (in Kotlin) on my onResume
mDBApi!!.session.finishAuthentication()
val accessToken = mDBApi!!.session.oAuth2AccessToken
val client = DbxClientV2(DbxRequestConfig.newBuilder("dropbox/MyAppName").build(), accessToken)
val email = client.users().currentAccount.email
but the getCurrentAccount() throws me 'android.os.NetworkOnMainThreadException'.
How can I solve this to get the user account email?
1 Reply
- Greg-DB8 years ago
Dropbox Community Moderator
You're getting a NetworkOnMainThreadException, which means you're trying to make a network call on the main thread, which isn't allowed on Android. (The Dropbox API methods each make a network call to the Dropbox API servers.) You should make this call on a background thread instead. This isn't specific to Dropbox, so there are several answers about how to do this on StackOverflow, e.g.:
https://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception
There's also an example of doing this in the Android sample app included with the Dropbox API v2 Java SDK:
https://github.com/dropbox/dropbox-sdk-java/blob/7ecc15cf0f51d6ae2ba5cdb334aac2c2f3474b87/examples/android/src/main/java/com/dropbox/core/examples/android/GetCurrentAccountTask.java#L12
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!