B4J Question Dragging images/text to other apps


Ok, so I know how to drag images from the desktop to my app, and how to drag and drop within my app, but how do I drop a dragged image onto another app? In essence, I get a downloaded image and want to drop it onto a graphics editor (e.g., GIMP or paint.net) for image manipulation. I assume that there is something more that I have to do than when dragging and dropping within my app but I can't seem to figure out what. I've searched the forum but can't find the clues I need so any pointers would be appreciated.


B4X founder
Staff member
Licensed User
Longtime User
See the attached example.

You need to share the image as a file.

The important code:
Sub DragSourceImage_DragDetected (Event As MouseEvent)
    File.Copy(File.DirAssets, "logo.png", xui.DefaultFolder, "logo.png")
    SetFilesAsData(DragAndDropImage, Array(File.Combine(xui.DefaultFolder, "logo.png")))
End Sub

Sub SetFilesAsData (DD As DragAndDrop, Files As List)
    Dim JFiles As List
    For Each f As String In Files
        Dim jf As JavaObject
        jf.InitializeNewInstance("java.io.File", Array(f))
    DD.SetDragModeAndData(TransferMode.COPY, Array As String("application/x-java-file-list"), Array(JFiles))
End Sub
Library is here: https://www.b4x.com/android/forum/threads/jdraganddrop2-drag-and-drop.76168/post-636391


  • DragAndDrop.zip
    15.4 KB · Views: 119
Upvote 0