Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
AppDev
8 years agoExplorer | Level 3
Get a list of files from dropbox to android application
Hi everybody, I'm new to dropbox developing and I need help with it please. I wrote an android application that needs to get a list of files listing in dropbox. I used the tutorial and part of the co...
Greg-DB
Dropbox Community Moderator
8 years ago[Cross-linking for reference: https://stackoverflow.com/questions/52017573/get-a-list-of-dropbox-files-to-android-application ]
You appear to be using the old SDK/code for Dropbox API v1, which is retired.
You should use the latest version of the official Java SDK, which uses Dropbox API v2:
https://github.com/dropbox/dropbox-sdk-java
To list files with that, you should use listFolder and listFolderContinue as shown here:
https://github.com/dropbox/dropbox-sdk-java#try-some-api-requests
- AppDev8 years agoExplorer | Level 3
Thank you so much for your reply! You are right, I was using API v1, I was sure I used v2...
I corrected it and followed the tutorials and the linked you gave me, but it still not working... :(
I need to make authentication every time, so my code now looks like this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Auth.startOAuth2Authentication(MainActivity.this, getString(R.string.APP_KEY));
}@Override
protected void onResume()
{
super.onResume();
String accessToken = Auth.getOAuth2Token();
if ((accessToken != null) && (accessToken != ""))
{
// Create Dropbox client
DbxRequestConfig config = DbxRequestConfig.newBuilder("dropbox/MyAppName").build();
DbxClientV2 client = new DbxClientV2(config, accessToken);
// Get files and folder metadata from Dropbox root directory
ListFolderResult result = null;
try
{
result = client.files().listFolder("");
while (true)
{
for (Metadata metadata : result.getEntries())
{
System.out.println(metadata.getPathLower());
}
if (!result.getHasMore())
{
break;
}
result = client.files().listFolderContinue(result.getCursor());
}
}
catch (DbxException e)
{
e.printStackTrace();
}
}
}The authentication is working, but in the onResume() method, after executing the:
DbxClientV2 client = new DbxClientV2(config, accessToken);The application died. I even tried to use the accessToken as hard coded, without the authentication, and the application still died after I tried to create the dropbox client...
What am I doing wrong now? :(
Thank you in advance.
- Greg-DB8 years ago
Dropbox Community Moderator
What exception/output are you getting with the crash?
- AppDev8 years agoExplorer | Level 3
I'm not sure how to get my exception since I'm very new to all this and not getting to any catch code, but when I call
DbxClientV2 client = new DbxClientV2(config, accessToken);The method
public DbxClientV2(DbxRequestConfig requestConfig, String accessToken) {
this(requestConfig, accessToken, DbxHost.DEFAULT, (String)null);
}In DbxClientv2.class is executing, and after that method loop() in looper.java executing the
finally {
if (traceTag != 0) {
Trace.traceEnd(traceTag);
}
}The msg I get is:
{ when=-6s733ms what=100 obj=ActivityRecord{df633d6 token=android.os.BinderProxy@147a79f {com.example.downloadfilestry/com.example.downloadfilestry.MainActivity}} target=android.app.ActivityThread$H }
And traceTag is 0.
After that the app stop running and on debug I get:
cause = com.android.internal.os.ZygoteInit$MethodAndArgsCaller
The code is not getting to catch, so I don't really know what to paste here...
Is it enough to understand the error?
If not, can you please direct me what to do?
In case my integration is wrong, I'll paste here what I did:
On libs folder I pasted the dropbox-core-sdk-3.0.8.jar file. on build.gradle file I added
dependencies {
............
implementation files ('libs/dropbox-core-sdk-3.0.8.jar')
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
}On the manifest file I added
.........
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
.......
<application
........
<activity android:name=".MainActivity">
.........
</activity>
<activity
android:name="com.dropbox.core.android.AuthActivity"
android:configChanges="orientation|keyboard"
android:launchMode="singleTask">
<intent-filter>
<data android:scheme="db-MY APP KEY" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>I added the app key also to the strings in values
Maybe I was wrong here?
Thank you for all your help.
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!