In Dropbox API v1 I used:
String userName = dropboxAccount.getAccountInfo().userName;
to get the user name and display it on the screen.
Now I'm using API v2, so I tried the following code:
public String getLoggedAccount()
{
String userAccountStr;
if (sDbxClient == null)
return "N/A";
try
{
userAccountStr = sDbxClient.users().getCurrentAccount().getAccountId();
userAccountStr += ", ";
userAccountStr += sDbxClient.users().getCurrentAccount().getEmail();
userAccountStr += ", ";
return userAccountStr;
}
catch(IllegalArgumentException e)
{
mException = e;
}
catch(NullPointerException e)
{
mException = e;
}
catch (com.dropbox.core.DbxException e)
{
mException = e;
}
return "N/A";
}
but it's crashing on the "getAccountId()" line, and never get to any on the 'catch' lines.
What may be the problem?
========== ========= ========= ========== ==========
Here is some more information:
I took the Anroid example project that comes with the new Dropbox API v2 and right after the line:
sDbxClient = new DbxClientV2(requestConfig, accessToken);
I added a call to the following function:
private static String getLoggedAccount()
{
if (sDbxClient == null)
return "N/A";
FullAccount dbxAccountInfo;
try
{
dbxAccountInfo = sDbxClient.users().getCurrentAccount();
}
catch (DbxException ex)
{
System.err.println("Error making API call: " + ex.getMessage());
System.exit(1);
return "N/A";
}
System.out.print(dbxAccountInfo.toStringMultiline());
}
It's crash on the getCurrentAccount() line, and never reach the catch. In the Logcat window I see this FATAL EXCEPTION:
03-14 14:11:52.400 7870-7870/com.dropbox.core.examples.android I/System.out: debugger has settled (1465) 03-14 14:11:52.468 7870-7870/com.dropbox.core.examples.android W/System: ClassLoader referenced unknown path: /data/app/com.dropbox.core.examples.android-2/lib/arm
03-14 14:12:11.779 7870-7870/com.dropbox.core.examples.android E/AndroidRuntime: FATAL EXCEPTION: main Process: com.dropbox.core.examples.android, PID: 7870 java.lang.RuntimeException: Unable to resume activity {com.dropbox.core.examples.android/com.dropbox.core.examples.android.UserActivity}: android.os.NetworkOnMainThreadException at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3103) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: android.os.NetworkOnMainThreadException at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1273) at java.net.InetAddress.lookupHostByName(InetAddress.java:431) at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252) at java.net.InetAddress.getAllByName(InetAddress.java:215) at com.android.okhttp.internal.Network$1.resolveInetAddresses(Network.java:29) at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:188) at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:157) at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:100) at com.android.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:357) at com.android.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:340) at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330) at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:248) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:437) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:114) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:245) at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218) at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java) at com.dropbox.core.http.StandardHttpRequestor.getOutputStream(StandardHttpRequestor.java:123) at com.dropbox.core.http.StandardHttpRequestor.access$000(StandardHttpRequestor.java:28) at com.dropbox.core.http.StandardHttpRequestor$Uploader.(StandardHttpRequestor.java:133) at com.dropbox.core.http.StandardHttpRequestor.startPost(StandardHttpRequestor.java:72) at com.dropbox.core.http.StandardHttpRequestor.startPost(StandardHttpRequestor.java:28) at com.dropbox.core.DbxRequestUtil.startPostRaw(DbxRequestUtil.java:237) at com.dropbox.core.v2.DbxRawClientV2$1.execute(DbxRawClientV2.java:107) at com.dropbox.core.v2.DbxRawClientV2.executeRetriable(DbxRawClientV2.java:284) at com.dropbox.core.v2.DbxRawClientV2.rpcStyle(DbxRawClientV2.java:102) at com.dropbox.core.v2.users.DbxUserUsersRequests.getCurrentAccount(DbxUserUsersRequests.java:120) at com.dropbox.core.examples.android.DropboxClientFactory.getLoggedAccount(DropboxClientFactory.java:31) at com.dropbox.core.examples.android.DropboxClientFactory.init(DropboxClientFactory.java:91) at com.dropbox.core.examples.android.DropboxActivity.initAndLoadData(DropboxActivity.java:43) at com.dropbox.core.examples.android.DropboxActivity.onResume(DropboxActivity.java:32) at com.dropbox.core.examples.android.UserActivity.onResume(UserActivity.java:63) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1258) at android.app.Activity.performResume(Activity.java:6327) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3092) .. 03-14 14:16:13.708 7870-7870/? I/Process: Sending signal. PID: 7870 SIG: 9
Does it helps?