Development (Copy & Paste)
Learn more by watching the videos after each step.
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.
If this attribute is set to true, the activity can be launched in split-screen and freeform modes. Otherwise, it will disable multi-window display. Remember to handle the changes required to fit your UX in small windows when in multi-window mode. For this Code Lab, you do not need to worry about the UX as it is already handled.
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.
NewNote.kt, get a reference to
ClipboardManager class by invoking
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
Step 4: Complete the copy operation
Now, create a new
ClipData of simple text using
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
ClipData by getting the
primaryClip data from the clipboard. From the
primaryClip, acquire the item using
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.
Watch this tutorial video and know how to easily test your app via Remote Test Lab.
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.
To learn more about developing apps for Galaxy Foldable devices, visit: www.developer.samsung.com/galaxy-z