B4J Question Dragging images/text to other apps

DaleA

Member
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.
 

Erel

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

You need to share the image as a file.

The important code:
B4X:
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
    JFiles.Initialize
    For Each f As String In Files
        Dim jf As JavaObject
        jf.InitializeNewInstance("java.io.File", Array(f))
        JFiles.Add(jf)
    Next
    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
 

Attachments

  • DragAndDrop.zip
    15.4 KB · Views: 213
Upvote 0
Top