Android Question Dropbox download not working

Brad Henderson

Member
Licensed User
I have access to my Dropbox account and retrieved an accesstoken. However when I try to download a file nothing happens, no error and it doesn't trigger a "dbxFiles_DownloadFinished" event. I tried putting the download inside a try/catch but that didn't provide an exception either. Can anyone see something that I have missed?

Thank you.
Brad


my code is:
B4X: Copy
#Region  Project Attributes 
    #ApplicationLabel: DrpBx.Test
    #VersionCode: 1
    #VersionName: 
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
     #AdditionalJar:dropbox-android-sdk-6.0.0.aar
    #AdditionalJar:dropbox-core-sdk-6.0.0
    #AdditionalJar: androidx.legacy:legacy-support-core-utils
    #AdditionalJar: jackson-core-2.7.4.jar
    #MultiDex: true
#End Region

Sub Process_Globals
    Dim auth As DbxAuth
    Dim Dropbox As DropboxV2
    Dim client As DbxClientV2
    Dim config As DbxRequestConfig
    Dim dbxFiles As DbxUserFilesRequests
    Dim dbxSharing As DbxUserSharingRequests
    Dim dbxUsers As DbxUserUsersRequests
    Dim token As String
    Dim dbxPath As String = "Apps\DrpBx.Test\SubFolder\"
    Dim MyPath As String=File.DirInternal
    Dim MyFile As String ="TestLogfile.txt"
End Sub
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    auth.Initialize("App_Key")
    dummy = "sl.BuNxatYjIkXBIN ... etc" .....Short term token from     "auth.startOAuth2Authentication"
    If dummy <> "" Then
        token = dummy
        Log("Token available (Activity Create. Try to enable Dropbox with this token")
        config.Initialize("",token,"de-de",5)
        Dim dbxhost As DbxHost
        dbxhost.Initialize
        client.Initialize("Dropbox",config,token,dbxhost)
        dbxFiles = client.files
        dbxFiles.setEventname("dbxFiles")
        dbxSharing = client.sharing
        dbxSharing.setEventname("dbxSharing")
        dbxUsers = client.users
        dbxUsers.setEventname("dbxUsers")
        DropboxEnabled = True
    Else
        DropboxEnabled = False
    End If
    Dropbox.Initialize("")
End Sub

I then try to download a file from Dropbox from a button click

B4X: Copy
Private Sub BtnDownload_Click
    Try
        dbxFiles.download(dbxPath & MyFile, MyPath, MyFile)
    Catch
        Log(LastException)
    End Try

End Sub

There is no Exception triggered in the Try.

This Sub is never activated:

B4X: Copy
Sub dbxFiles_DownloadFinished(success As Boolean, meta As FileMetadata, error As String)
    If meta = Null Then
        Log($"dbxFiles_DownloadFinished(${success}, ${error})"$)
    Else
        Log($"dbxFiles_DownloadFinished(${success}, ${meta}, ${error})"$)
    End If
    If error.Contains("Exception") Then
        Log(LastException)
    End If
    ToastMessageShow("Download Completed",True)
End Sub

My Manifest is:
Code: Copy
AddManifestText(
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
AddApplicationText(<activity
android:name="com.dropbox.core.android.AuthActivity"
android:configChanges="orientation|keyboard"
    android:exported="true"
android:launchMode="singleTask" >
<intent-filter>
<data android:scheme="db-5iyw0lvn7jpvw4w" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.
AddManifestText(<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="33" />
)
 
Solution
Thanks for all your help Don,

I found the problem. I was assigning my path to the Dropbox folder as:
B4X: Copy
Dim dbxPath As String = "\Apps\DrpBx.Test\My Folder\appdata\"

and I should have assigned:
Code: Copy
Dim dbxPath As String = "/My Folder/appdata"

It didn't display any errors but it also didn't download any data??
Thanks again
Upvote 0
Thanks DonManfred,

I found an error in this line, the path was incorrect, replaced with null and it worked.
B4X: Copy
dbxFiles.listFolder("MyPath",False,True,False,True,True)
-
However when I try to read the file with:
B4X: Copy
Public LogFile As List
LogFile.Initialize
LogFile = File.ReadList(MyPath,MyFile)

The read returns no lines. ( I have 7 lines in the original file in Dropbox.)

I confirmed the file did copy with:

B4X: Copy
If File.Exists(MyPath,MyFile ) Then
   ToastMessageShow("File Found",True)
   LogFile = File.ReadList(MyPath,MyFile)
   Log(LogFile.Get(0))
Else
   ToastMessageShow("File NOT Found",True)
End If

Thanks again DonManfred
 
Upvote 0
Sorry I didn't explain.
B4X: Copy
Dim MyPath As String=File.DirInternal
Dim MyFile As String ="TestLogfile.txt"

So I am trying to use File.Readlist on the downloaded file situated on the device after it.
 
Upvote 0
I also tried it with a sqlite .db file of 5.6MB and still it shows 0 bytes on the device. The Log shows:
B4X: Copy
download()
files.download(after new File())
files.download(create fos)
files.download(fos created)

Searched these results without finding a clue. It seems to me that this
B4X: Copy
dbxFiles.download(dbxPath & MyFile, MyPath & "/",MyFile)
appears to create the name but doesn't download any actual data.

In my manifest my "sdk android:minSdkVersion="21" so does this mean it is not a permissions issue?
Is it expected that the dbxFiles_DownloadFinished sub is triggered?

Thank you for any help
Brad
 
Upvote 0
Thanks for all your help Don,

I found the problem. I was assigning my path to the Dropbox folder as:
B4X: Copy
Dim dbxPath As String = "\Apps\DrpBx.Test\My Folder\appdata\"

and I should have assigned:
Code: Copy
Dim dbxPath As String = "/My Folder/appdata"

It didn't display any errors but it also didn't download any data??
Thanks again
 
Upvote 0
Solution
Back
Top