cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Are you an educator? Well we want to hear from you, so check out some tools we think might help you out here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

simple Android example for APIv2 required

simple Android example for APIv2 required

MarioEM
Helpful | Level 6

I have implemented an Android code for Downloading / Uploading files to Dropbox App folder based on the old, simple DBRoulette example, which works perfectly well under Dropbox APIv1.

 

I have spent many hours trying to modify the "official" APIv2 example code from: 

https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/android

without much success.

Is there a simple example source code for APIv2, similar to DBRoulette example, that can be used to replace the old APIv1 implementation ?   

1 Accepted Solution

Accepted Solutions

Re: simple Android example for APIv2 required

MarioEM
Helpful | Level 6

Hello Greg,

That was a good suggestion with the link that included the appropriate tip!

I already had the correct Write and Read permissions in the AndroidManifest, but I forgot about the new Android rule introduced since version 23 that requires app users to manually accept the external write storage permission.

It is all working well now, both file Upload and Download.

Thanks for your help.

I had to modify the example Download code to obtain the required metadata for the specific Dropbox file:

    protected FileMetadata doInBackground(String... params) {
        String fileName = params[0];

        try {
            FileMetadata metadata = (FileMetadata) mDbxClient.files().getMetadata("/" + fileName);

Please comment if the above code is the correct way to do it. 

View solution in original post

5 Replies 5

Re: simple Android example for APIv2 required

Greg-DB
Dropboxer
We don't have another Android example app, aside from the one you linked to.

What issues are you running in to?

Re: simple Android example for APIv2 required

MarioEM
Helpful | Level 6

Hello Greg,

I am having problems uploading the single selected file from a fixed Android folder called "em" to a Dropbox apps folder. I have implemented the code exactly as per example app: UploadFileTask.java

Here is the problem section of the code after some modifications:

 

    @Override
    protected FileMetadata doInBackground(String... params) {
        String remoteFileName = params[0];

        if (remoteFileName != null) {
            File outPath = Environment.getExternalStorageDirectory();
            String remoteFolderPath = outPath.getAbsolutePath() + "/" + "em";
            File localFile = new File(remoteFolderPath, remoteFileName);

            try (InputStream inputStream = new FileInputStream(localFile)) {
                return mDbxClient.files().uploadBuilder(remoteFolderPath + "/" + remoteFileName)
                        .withMode(WriteMode.OVERWRITE)
                        .uploadAndFinish(inputStream);
            } catch (DbxException | IOException e) {
                mException = e;
            }
        }

        return null;
    }

The remoteFolderPath string is "/storage/emulated/0/em"  and the remoteFileName string is "EM.db"

The localFile is  /storage/emulated/0/em/EM.db

The EM.db file does exist in that particular folder and the storage path is identical to the one generated in the APIv1 code, which worked perfectly well.

I am getting an error message: ..."/storage/emulated/0/em/EM.db: open failed: EACCES Permission denied"

I tried it with several different files and different folders without success. The same error al the time.

Can you see any problems with this code ?

Another issue: the above example code requires a minimum Android SdkVersion = 19. My app currently uses minimum SdkVersion = 14 which works well with the old APIv1 code:

fis = new FileInputStream(file);
mApi.putFileOverwrite(file, fis, file.length(),
etc. as per DBRoulete app. example.

 Can you plese suggest how to resolve these issues and how to overcome Android SdkVersion restrictions.

Thanks.

Re: simple Android example for APIv2 required

Greg-DB
Dropboxer
The "EACCES Permission denied" error appears to be an Android error about a lack of permission to read/write the local data. That's not about Dropbox itself exactly, but it looks like you need to make sure you have write permissions, e.g., as covered here:

https://stackoverflow.com/questions/8854359/exception-open-failed-eacces-permission-denied-on-androi...

Also, the Android sample app only supports 19+, so you may need to change some of the for 14+. What exactly isn't working for you? That's again more about Android itself so I may not be able to offer much insight there unfortunately.

Re: simple Android example for APIv2 required

MarioEM
Helpful | Level 6

Hello Greg,

That was a good suggestion with the link that included the appropriate tip!

I already had the correct Write and Read permissions in the AndroidManifest, but I forgot about the new Android rule introduced since version 23 that requires app users to manually accept the external write storage permission.

It is all working well now, both file Upload and Download.

Thanks for your help.

I had to modify the example Download code to obtain the required metadata for the specific Dropbox file:

    protected FileMetadata doInBackground(String... params) {
        String fileName = params[0];

        try {
            FileMetadata metadata = (FileMetadata) mDbxClient.files().getMetadata("/" + fileName);

Please comment if the above code is the correct way to do it. 

View solution in original post

Re: simple Android example for APIv2 required

Greg-DB
Dropboxer
Thanks, I'm glad to hear you were able to get that working. Yes, that code looks fine.
Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropboxer
  • User avatar
    MarioEM Helpful | Level 6
What do Dropbox user levels mean?
Need more support?