Android Question Copying a file from Google Drive

toby

Well-Known Member
Licensed User
Longtime User
Could someone kindly provide me with a working example that first prompts user to select a file on Google Drive and then copies it to somewhere accessible by the app?

Thanks in advance for your helps!!!


toby
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use ContentChooser from the Phone library. The user can select files from Google Drive:
B4X:
Sub Process_Globals
   Private cc As ContentChooser
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     cc.Initialize("cc")
   End If
End Sub

Sub Activity_Click
   cc.Show("*/*", "choose")
End Sub

Sub cc_Result (Success As Boolean, Dir As String, FileName As String)
   If Success Then
     File.Copy(Dir, FileName, File.DirInternal, "newfile")
     Log("file copied")
   End If
End Sub
 
Upvote 0

toby

Well-Known Member
Licensed User
Longtime User
You can use ContentChooser from the Phone library. The user can select files from Google Drive:
B4X:
Sub Process_Globals
   Private cc As ContentChooser
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     cc.Initialize("cc")
   End If
End Sub

Sub Activity_Click
   cc.Show("*/*", "choose")
End Sub

Sub cc_Result (Success As Boolean, Dir As String, FileName As String)
   If Success Then
     File.Copy(Dir, FileName, File.DirInternal, "newfile")
     Log("file copied")
   End If
End Sub

@Erel, if the filename is known, for example, abc.db, how to modify the code accordingly.

Thanks again

Toby
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You need to use the Google Drive API to do this.
 
Upvote 0
Top