Development (Copy & Paste)

Step 1: Open the project file

Open Android Studio and click Open an Existing Project.

Locate the downloaded Android Project (SimpleNotes_CopyPaste) from the directory and click OK.


Step 2: Make the app resizable

To ensure that the app works in multi-window mode, you need to add an attribute in the manifest’s <activity> element. If you set android:resizeableActivity to true, the activity can be launched in multi-window, pop-up view and adapt different screen size.

android:resizeableActivity= "true"

Step 3: Get a reference to ClipboardManager class

ClipboardManager provides methods to get and set the current primary clipboard data expressed as a ClipData object, which defines the protocol for data exchange between applications. In NewNote.kt, get a reference to ClipboardManager class by invoking getSystemService(CLIPBOARD_SERVICE).

val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager


Step 4: Complete the copy operation

Now, create a new ClipData of simple text using newPlainText of ClipboardManager and pass it on setPrimaryClip to complete the copy operation.

val clip: ClipData = ClipData.newPlainText("simple text", textData)
clipboard.setPrimaryClip(clip)


Step 5: Get the text data from the clipboard

Return the ClipData by getting the primaryClip data from the clipboard. From the primaryClip, acquire the item using getItemAt(0).

val item = clipboard.primaryClip?.getItemAt(0)


Step 6: Run the app

After building the APK, you can run the optimized app on a Galaxy Fold or Galaxy Z Fold2 and test it by copying and pasting texts between apps in multi-window mode. If you don’t have any physical device, you can also test it on a Remote Test Lab device.


You're done!

Congratulations! You have successfully achieved the goal of this Code Lab activity. Now, you can implement multi-window features on your app by yourself! But, if you're having trouble, you may check out the link below.

Multi-Window Complete Code 39.27 MB

To learn more about developing apps for Galaxy Foldable devices, visit: www.developer.samsung.com/galaxy-z