B4A Library Dropbox Chooser

As Dropbox sync is apparently deprecated, I though I would have a go at wrapping the Android Native version of The Dropbox chooser, and here it is.

It's simple enough to use, you first need to register an app with dropbox and get an app key from here:
https://www.dropbox.com/developers , follow the process of creating a new app and get your app key.

To use the chooser, you don't need an HTTPS site and no need to apply for approval as all data transfer is done under user control.

Required Files:

The three attached files are:

DropboxChooserSource.zip - contains the source for the DropboxChooserWrapper (in B4a) and an example of it's use.

DropboxChooserExample.zip - contains just the main activity example (same as in the source without the Library classes)

DropboxChooserLibJars.zip - Contains the compiled library from the source zip - DropboxChooserWrapper.jar and xml files.

You also need the DropboxChooserLib which is the API from dropbox exported from an Eclipse project. It is just over 3MB so too large to upload to the forum, you can get it from my google drive here: DropboxChooserLib

Finally, you also need the android-support-v4.jar which you can get via your SDK manager if you haven't already.



Copy the 3 jar files and 1 XML file to your addl libs folder. Don't select the DropboxChooserWrapper in the libs tab if you are running the full source project.

Also depends on JavaObject.


Classes:

There are two classes in the Dropbox chooser Lib:

DropboxChooser which has two methods:

Initialize(Module As Object,EventName As string,AppKey As String)

Show(ShowType As String)
See the Dropbox documentation for explanation of the types

DropboxChooserResult which has 5 methods:

GetLink As String

GetIcon As String

GetName As String

GetSize As Long

GetThumbnails As Map

Again see the Dropbox documentation (or source project) for an explanation

Results:

All results return a URL which you can then download using HTTPUtils2

Unfortunately it appears that the Dropbox Saver API for Android is a long time coming, it was supposed to be being released soon in 2013.

Have fun
 

Attachments

  • DropboxChooserExample.zip
    7.7 KB · Views: 409
  • DropboxChooserLibJars.zip
    8.3 KB · Views: 384
  • DropboxChooserSource.zip
    10.2 KB · Views: 363
Last edited:

tcgoh

Active Member
Licensed User
Longtime User
Hi stevelo5,

Thanks for the dropbox chooser. I managed to use your example to connect to my dropbox, but could you kindly show me how to download a text file from dropbox to my device.

Thanks
 

stevel05

Expert
Licensed User
Longtime User
Hi, I'm just going out and probably won't have time to make a demo today, but you need to use HTTPUtils2 with the link obtained by Result.Getlink in the Dropbox_Result sub.

Let me know if you have problems with that.
 

tcgoh

Active Member
Licensed User
Longtime User
Tks Stevel05,

This is what I do:
Dim job1 As HttpJob
job1.Initialize("job1",Me)
B4X:
Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
           Dim out As  OutputStream
          out = File.OpenOutput(File.DirRootExternal,"alltest.txt",False)
           File.Copy2(Job.GetInputStream,out)
           out.Close
   Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
   End If
   Job.Release
End Sub

Sub Dropbox_Result(Result As DropboxChooserResult)
    Log(Result.GetLink)
    Dim M As Map = Result.GetThumbnails
    For Each Item As String In M.Keys
        Log(M.Get(Item))
    Next
        downloadurl = Result.GetLink
        job1.Download(downloadurl)
        Log("url "  & downloadurl)
End Sub

Thanks
 

Mahares

Expert
Licensed User
Longtime User
Tks Stevel05,

Although your code works, should't not be more simplified like this. Note, I did not have to enter the file name in the download:
B4X:
Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
           Dim out As  OutputStream
           out = File.OpenOutput(File.DirRootExternal,downloadurl.SubString(downloadurl.LastIndexOf("/")+1),False)
           File.Copy2(Job.GetInputStream,out)
           out.Close
   Else
      Log("Error: " & Job.ErrorMessage)
      ToastMessageShow("Error: " & Job.ErrorMessage, True)
   End If
   Job.Release
End Sub

Sub Dropbox_Result(Result As DropboxChooserResult)
        downloadurl = Result.GetLink
        job1.Download(downloadurl)
'        Log("url "  & downloadurl)
End Sub
 

tcgoh

Active Member
Licensed User
Longtime User
Tks Mahares for the simplified code. I need to change the file name to be used in my APP.
 
Top