We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
john_son
8 years agoNew member | Level 2
Fatal error on running finishFromCode in Java 3.0.6
Trying to run method finishOAuth of DropboxConnector class (startOAuth has no problems when running. public DropboxConnector() { DbxAppInfo appInfo = new DbxAppInfo(DropboxHelper.APP_KEY, Drop...
- 8 years agoYou'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 `finishFromCode` method makes a network call to the Dropbox API servers to exchange the authorization code for an access token.)
You would need to make this call on a background thread instead. There are various examples about how to do this on StackOverflow, e.g.:
https://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception
Note that for Android though, the Dropbox Java SDK provides a different app authorization flow anyway, which doesn't use finishFromCode. There's an example Android app here:
https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/android
Your AndroidManifest.xml should be set up as shown here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/AndroidManifest.xml#L33
You start the flow by calling startOAuth2Authentication as shown here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/UserActivity.java#L36
You complete the flow by calling getOAuth2Token as shown here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/DropboxActivity.java#L22
Your app can store and re-use the resulting access token for that user, as the example does here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/DropboxActivity.java#L24
Greg-DB
Dropbox Community Moderator
8 years agoYou'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 `finishFromCode` method makes a network call to the Dropbox API servers to exchange the authorization code for an access token.)
You would need to make this call on a background thread instead. There are various examples about how to do this on StackOverflow, e.g.:
https://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception
Note that for Android though, the Dropbox Java SDK provides a different app authorization flow anyway, which doesn't use finishFromCode. There's an example Android app here:
https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/android
Your AndroidManifest.xml should be set up as shown here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/AndroidManifest.xml#L33
You start the flow by calling startOAuth2Authentication as shown here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/UserActivity.java#L36
You complete the flow by calling getOAuth2Token as shown here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/DropboxActivity.java#L22
Your app can store and re-use the resulting access token for that user, as the example does here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/DropboxActivity.java#L24
You would need to make this call on a background thread instead. There are various examples about how to do this on StackOverflow, e.g.:
https://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception
Note that for Android though, the Dropbox Java SDK provides a different app authorization flow anyway, which doesn't use finishFromCode. There's an example Android app here:
https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/android
Your AndroidManifest.xml should be set up as shown here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/AndroidManifest.xml#L33
You start the flow by calling startOAuth2Authentication as shown here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/UserActivity.java#L36
You complete the flow by calling getOAuth2Token as shown here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/DropboxActivity.java#L22
Your app can store and re-use the resulting access token for that user, as the example does here:
https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/core/examples/android/DropboxActivity.java#L24
- john_son8 years agoNew member | Level 2
Thank you, it helps.
The wierd thing is the project was cloned from Windows Android Studio , where the code works without any issues to Macbook one where the issue immediately happened.
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!