Dropbox Sync Library

Discussion in 'Old Libraries Archive' started by Erel, Jun 10, 2013.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Dropbox has deprecated this service. Don't use in new projects!

    This library wraps Dropbox Sync API. Using this API it is quite simple to store (and retrieve) data in a folder inside the user's Dropbox account.

    For example if your program creates reports, you can upload the saved reports to the user's Dropbox account. The user will then be able to access the reports from any Dropbox client.

    Dropbox library is responsible for the communication and the synchronization.

    Using this library

    1. Download the Android SDK: https://www.dropbox.com/developers/sync
    Unzip it and copy dropbox-sync-sdk-android.jar to the libraries folder.
    2. Copy the attached wrapper files to the libraries folder.
    3. Log-in to your Dropbox account and go to the developer console: https://www.dropbox.com/developers/apps
    Create a new app and make sure to choose Sync API.
    The app key and app secret values are later required:


    Basic4android code

    The first step it to link an account. If this is the first time that the account is linked then the user will be asked to approve the connection.
    The AccountReady event is raised after the account is linked and is ready.

    You can now upload files, download files or list the existing files.
    The download operation raises the DownloadCompleted event. Other operations do not raise events.
    Note that the root path (/) points to the app folder.
    Folders will be created automatically.
    For example if you upload a file to /some/folder then the folders will be created if needed.

    Sub Process_Globals
    Private manager As DbxAccountManager
    Private key As String = "aaa"
    Private secret As String = "bbb"

    End Sub

    Sub Globals

    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
          manager.Initialize(key, secret, 
    End If
    End Sub

    Sub Button1_Click
    End Sub

    Sub Manager_AccountReady (Success As Boolean)
    Log("Account Ready: " & Success)
    If Success Then
    For Each FileInfo As DbxFileInfo In manager.ListFiles("/")
    Log(FileInfo.Name & ", " & FileInfo.IsFolder)
    End If
    "/""somefile"File.DirRootExternal, "somefile")
    End Sub

    Sub Manager_DownloadCompleted (Success As Boolean, LocalDir As String, LocalFileName As String)
    Log("DownloadCompleted: " & Success)
    End Sub
    Manifest editor code

    SetApplicationAttribute(android:label"@string/app_name"' NEW in v3.0!!!
    activity android:name="com.dropbox.sync.android.DbxAuthActivity" />
    "singleTask" >
        <data android:scheme=
    "db-YOURAPPKEY" /> <!-- NEED TO UPDATE -->
        <action android:name=
    "android.intent.action.VIEW" />
        <category android:name=
    "android.intent.category.BROWSABLE" />
        <category android:name=
    "android.intent.category.DEFAULT" />
    label="Dropbox Sync" />
    Make sure to replace YOURAPPKEY with your app key...

    Resource File (new in V3.0)

    Due to a bug/issue in Dropbox SDK we must set the app name with an XML file.
    Create a file named strings.xml and put it under Objects\res\values.
    The file content should be:
    <?xml version="1.0" encoding="utf-8"?>
    string name="app_name">B4A Example</string>
    Change B4A Example to the correct app name. Set the file to be read-only.

    V3.0 - Works with Dropbox SDK v3.0 v3.1.
    V1.25 - Adds an AutoSync field. Setting this field to true will cause the cache to be synchronized before files are downloaded. The latest files will be downloaded.
    V1.21 - fixes an issue with Sync event.
    v1.20 released. Works with DropBox SDK v2.0

    The library is available here: www.basic4ppc.com/android/files/DropboxSync.zip
    Last edited: Jul 2, 2017
  2. AscySoft

    AscySoft Active Member Licensed User

    nice feature.
    keep them comming
  3. GMan

    GMan Well-Known Member Licensed User

    Very nice feature, missed that :sign0087:

    This line causes an error:
    manager.Initialize(key, value, "manager")
    Value is not assigned before using...
    Last edited: Jun 10, 2013
  4. Erel

    Erel Administrator Staff Member Licensed User

    It should be secret instead of value.
  5. GMan

    GMan Well-Known Member Licensed User

    Thx, so far so good - but after test compiling (without errors) an error occurs while reading the "dropbox-sync-sdk-android.jar": error in opening zip file if i try to compile to the device

    SOLVED - yesterday i download only the jar-file and put it in my Lib-folder.
    After the problems this morning i downloaded the whole SDK and copied the .jar-lib again to my Lib-folder.

    When asking if it should be overwritten i saw, that the file from yesterday has only ~24 kb, the one from today is about 161 KB and works fine....ver special thing, because the download of the jar-lib only yesterday is the same file from the today downloaded archive.

    So, DropBox-Sync works fine, Upload and downlad, connecting etc etc. :cool:

    Again thx to Erel :icon_clap:
    Last edited: Jun 11, 2013
  6. Theera

    Theera Well-Known Member Licensed User

    Hi Erel,
    How to have 1.bal file? I couldn't seek it.
  7. Erel

    Erel Administrator Staff Member Licensed User

    You should create a new layout file. If you are following the code posted above then there should be one button named Button1.
  8. rboeck

    rboeck Well-Known Member Licensed User

    Authentification problems

    in your description everything looks easy, but i miss something:
    in the dropbox app console i have to name my app; is this name free to choose or is this the app Name or the app label?
    Then i have to write two url's:
    OAuth 2 redirect URLs
    How to i get them?
    And last question: How to i know, if my account settings are working?
    Last edited: Jun 27, 2013
  9. Erel

    Erel Administrator Staff Member Licensed User

    1. You are free to choose.
    2. Leave the OAuth URLs field empty.

    Create a small test program as described above. Try to upload a file.

    You can then open your dropbox account and see the file.
  10. GMan

    GMan Well-Known Member Licensed User

    If you have the DropBox-Tool also installed on your PC the task-icon will give you a popup-message that a file was uploaded/updated.
  11. rboeck

    rboeck Well-Known Member Licensed User

    By the first run, when i came to the line

    manager.Initialize(dpAppKey, dpAppSecret, "manager")
    i get in then log :

    java.lang.IllegalStateException: URI scheme in your app's manifest is not set up correctly. You should have a com.dropbox.client2.android.AuthActivity with the scheme: db-xxxxxxxxx <- my Appkey

    I have copied the above text in the manifest file as addition and also pasted the appKey in the manifest.
    Any ideas what went wrong?

  12. GMan

    GMan Well-Known Member Licensed User

    Did you replace the XXXXXXXXX with your code correctly ?
  13. rboeck

    rboeck Well-Known Member Licensed User


    it was the 'db-' at the appkey in the manifest; i pasted my key, but only the key without db-...
    Now my app is running an i have to check the new possibilities...
    Greetings and many thanks
    Scunkaneli likes this.
  14. GMan

    GMan Well-Known Member Licensed User

  15. hypergreatthing

    hypergreatthing Member Licensed User

    Thank you very much for this library. This solves an issue i'm trying to work around. However i have the following questions:
    What exactly is the purpose of DbxAccountManager.Sync?
    Along those same lines, i see a method for downloading and uploading. There should be a way to manually loop through the listfiles and do a islatest on them, but isn't the whole purpose of syncing more along the lines of setting a folder in your app directory as a synced folder, then everything you put in there will be pushed and synced to the dropbox remote folder?
    Looking at the dropbox api, there's references to DbxFileSystem.PathListener that you can setup so that it will auto update a path/folder.

    I'm planning on diving into this very shortly. I just wanted to check if
    a) I'm doing it wrong thinking that i should be manually pushing and checking for updates.
    b) there's no planned updates for this library to include pathlisteners in the near future.

  16. Erel

    Erel Administrator Staff Member Licensed User

    Normally you do not need to call Sync. The folder is synced automatically.
    You can call Sync to force the folder to sync now.

    Note that when you call Download you will always get the latest version.
    You do not need to do anything manually.

    Maybe in the future. For now I don't think that they are needed as you always get the latest version when you call Download.
  17. dealsmonkey

    dealsmonkey Active Member Licensed User

    Thanks for this libary Erel. I needed an easy way to get a file from the device to a PC and this does the job perfectly :)
  18. hypergreatthing

    hypergreatthing Member Licensed User

    Question then: In your example you download a file from dropbox. There is no folder option, or is there? I tried to download a file from dropbox, then modified the one on dropbox (in the App Folder, under the [user created program] folder). I replaced a 5 meg file with one that was like 16k. The dropbox web interface showed it was replaced. I tried to add another button in your example that called manager.sync but nothing happened to the local file that was downloaded.

    I'll try out calling a manager.download without a specified filename and see if it writes the dropbox directory instead and keeps it synced.

    I don't think that worked. Passing a Null value for the file produces a file called "NULL".

    Am i missing something here like, the requirement to have the dropbox app installed to auto-sync downloaded or uploaded files?
  19. Erel

    Erel Administrator Staff Member Licensed User

    It will only be updated after you call Download again.

    Download, which is a background operation, first checks whether the cached file (not your file) is up to date and downloads it if necessary. It then copies it to the location you specified.
  20. hypergreatthing

    hypergreatthing Member Licensed User

    Ok. That's what i thought. And that works well.

    I'm used to the dropbox on pc app where if a phone uploads a picture for instance, it will automatically detect a new file and auto download to your computer.

    When i said manually before, i meant if i want a file to be pushed to dropbox, i have to execute the manager.uploadfile function. There's no way to establish a auto-sync folder where any changes inside that folder on the device locally or on dropbox will fire off a sync between the two.

    Thank you.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice