Android Code Snippet [B4X] Direct Link Google Drive

Hi All.
For example, if you need to view a movie in exoplayer and the movie is on Google Drive, you can switch the Direct Link of Google Drive to Exoplayer ("uri").
Original link

Example code:
B4X:
Dim link_drive As String = "https://drive.google.com/file/d/1VpD4ThDGw5xEjgjd32kECdgfcegklX-P/view?usp=sharing"
  
    Dim splitta() As String = Regex.Split("/d/", link_drive)
    Dim estrai As String = splitta(1)
    Dim risultato_link() As String = Regex.Split("/", estrai)
    Dim link_direct_drive As String = $"https://drive.google.com/uc?export=download&id=${risultato_link(0)}"$
    Log(link_direct_drive)
 

MarcoRome

Expert
Licensed User
Longtime User
If you have files over 100Mb. The following code can be executed (you need an api Key Google Drive)

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim key_drive As String = "YOUR_KEY"
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.
   
   
    'Direct Link Drive Google
    Dim link_drive As String = "https://drive.google.com/file/d/1VpD4ThDGw5xEjgjd32kECdgfcegklX-P/view?usp=sharing

    Dim splitta() As String = Regex.Split("/d/", link_drive)
    Dim estrai As String = splitta(1)
    Dim risultato_link() As String = Regex.Split("/", estrai)


    Dim link_direct_drive As String = $"https://www.googleapis.com/drive/v3/files/${risultato_link(0)}/?key=${key_drive}&alt=media"$
    Log(link_direct_drive)
 
Last edited:
Top