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.
Manifest editor code
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:
Change B4A Example to the correct app name. Set the file to be read-only.
Edit:
V3.0 - Works with Dropbox SDKv3.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.b4x.com/android/files/DropboxSync.zip
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.
B4X:
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, "manager")
End If
Activity.LoadLayout("1")
End Sub
Sub Button1_Click
manager.LinkAccount
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)
Next
End If
manager.DownloadFile("/", "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
B4X:
SetApplicationAttribute(android:label, "@string/app_name") ' NEW in v3.0!!!
AddApplicationText(
<activity android:name="com.dropbox.sync.android.DbxAuthActivity" />
<activity
android:name="com.dropbox.client2.android.AuthActivity"
android:launchMode="singleTask" >
<intent-filter>
<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" />
</intent-filter>
</activity>
<service
android:name="com.dropbox.sync.android.DbxSyncService"
android:enabled="true"
android:exported="false"
android: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:
B4X:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">B4A Example</string>
</resources>
Edit:
V3.0 - Works with Dropbox SDK
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.b4x.com/android/files/DropboxSync.zip
Last edited: