/* Copyright 2021 Google LLC. SPDX-License-Identifier: Apache-2.0 */ // Make a view draggable to share a file. DragStartHelper takes care of // intercepting drag gestures and attaching the listener. DragStartHelper(draggableView) { view, _ -> // Sets the appropriate MIME types automatically. val dragClipData = ClipData.newUri(contentResolver, "File", fileUri) // Set the visual look of the dragged object. // Can be extended and customized; we use the default here. val dragShadow = View.DragShadowBuilder(view) // Starts the drag. Note that the global flag allows for cross-app dragging. view.startDragAndDrop( dragClipData, dragShadow, null, // Optional extra local state information // Since this is a "content:" URI and not just plain text, we can use the // DRAG_FLAG_GLOBAL_URI_READ to allow other apps to read from our content // provider. Without it, other apps won't receive the drag events. DRAG_FLAG_GLOBAL or DRAG_FLAG_GLOBAL_URI_READ) ) }.attach()