B4J Question DragAndDrop file types

mtselection

Member
Licensed User
Longtime User
Hi

I need to use the draganddrop library to analyze binary (hex) file types with different extensions from the file manger.

Is this possible?

Thanks for the support

Maurizio
 

DonManfred

Expert
Licensed User
Longtime User
I need to use the draganddrop library to analyze binary (hex) file types with different extensions from the file manger.
You need to copy the file first to read any bytes from them.

You need to adapt the code here to do what you want.

B4X:
Sub DropTarget_DragOver(e As DragEvent)
    If IsValidDropEvent(e) Then e.AcceptTransferModes(TransferMode.COPY)
End Sub

Sub IsValidDropEvent(e As DragEvent) As Boolean
    If e.GetDragboard.HasFiles Then
        Dim files As List = e.GetDragboard.GetFiles
        If files.Size = 1 Then
            Dim filename As String = files.Get(0)
            
            ' Copy and read the file here and check if you accept this file.
            ' return true if yes, false if not.
            
            Return filename.EndsWith(".txt")
        End If
    End If
    Return False
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Alternatively you can just this event and do nothing if you want to do nothing with the file.

B4X:
Sub DropTarget_DragDropped(e As DragEvent)
    Log("drag dropped")
    Dim filename As String = e.GetDragboard.GetFiles.Get(0)
    Try
        TextArea1.Text = File.ReadString(filename, "")
    Catch
        TextArea1.Text = LastException
    End Try
    Label1.Text = filename
    e.SetDropCompleted(True)
End Sub
 
Upvote 1
Top