Download - What is Clip Data in Android
![Page 1: What is Clip Data in Android](https://reader033.vdocuments.site/reader033/viewer/2022061222/54c1b9194a79590b2d8b4798/html5/thumbnails/1.jpg)
Android Clipboard
facebook.com/apex.tgi
twitter.com/ApextgiNoida
pinterest.com/apextgi
![Page 2: What is Clip Data in Android](https://reader033.vdocuments.site/reader033/viewer/2022061222/54c1b9194a79590b2d8b4798/html5/thumbnails/2.jpg)
Fundamentals
• Android provides the clipboard framework for copying and pasting different
types of data. The data could be text, images, binary stream data or other
complex data types.
• It provides the library of ClipboardManager and ClipData and ClipData.item to
use the copying and pasting framework.
![Page 3: What is Clip Data in Android](https://reader033.vdocuments.site/reader033/viewer/2022061222/54c1b9194a79590b2d8b4798/html5/thumbnails/3.jpg)
Use of Clipboard
• In order to use clipboard framework, need to put data into clip object, and then
put that object into system wide clipboard.
• Object of ClipboardManager is instantiated by calling the getSystemService()
method.
ClipboardManager clipboard = ( ClipboardManager ) getSystemService (CLIPBOARD_SERVICE);
![Page 4: What is Clip Data in Android](https://reader033.vdocuments.site/reader033/viewer/2022061222/54c1b9194a79590b2d8b4798/html5/thumbnails/4.jpg)
Copying data
• The next thing that is need to do is to instantiate the ClipData object by calling
the respective type of data method of the ClipData class.
• In case of text data, the newPlainText ( ) method will be called. After that have
to set that data as the clip of the ClipbaoardManager object.
![Page 5: What is Clip Data in Android](https://reader033.vdocuments.site/reader033/viewer/2022061222/54c1b9194a79590b2d8b4798/html5/thumbnails/5.jpg)
Copying data
Implementation:
ClipData clipdata = ClipData.newPlainText("text", “String”);clipboard.setPrimaryClip(clipdata);
![Page 6: What is Clip Data in Android](https://reader033.vdocuments.site/reader033/viewer/2022061222/54c1b9194a79590b2d8b4798/html5/thumbnails/6.jpg)
ClipData Form
• Text
• URI
• Intent
![Page 7: What is Clip Data in Android](https://reader033.vdocuments.site/reader033/viewer/2022061222/54c1b9194a79590b2d8b4798/html5/thumbnails/7.jpg)
ClipData Form
• Text : newPlainText(label, text):
Returns a ClipData object whose single ClipData.Item object contains a text string.
• URI : newUri(resolver, label, URI):
Returns a ClipData object whose single ClipData.Item object contains a URI.
• Intent : newIntent(label, intent):
Returns a ClipData object whose single ClipData.Item object contains Intent.
![Page 8: What is Clip Data in Android](https://reader033.vdocuments.site/reader033/viewer/2022061222/54c1b9194a79590b2d8b4798/html5/thumbnails/8.jpg)
Data Pasting
• In order to paste the data, we will first get the clip by calling the getPrimaryClip
( ) method. And from that click will get the item in ClipData.Item object and
from the object we will get the data.
ClipData clipdata = clipboard.getPrimaryClip ( );ClipData.Item item = clipdata.getItemAt (0);
String text = item.getText ( ).toString ( );
![Page 9: What is Clip Data in Android](https://reader033.vdocuments.site/reader033/viewer/2022061222/54c1b9194a79590b2d8b4798/html5/thumbnails/9.jpg)
Methods & Description
• getPrimaryClip ( ):
This method just returns the current primary clip on the clipboard
• getPrimaryClipDescription ():
This method returns a description of the current primary clip on the clipboard but not a
copy of its data.
• hasPrimaryClip ():
This method returns true if there is currently a primary clip on the clipboard.
![Page 10: What is Clip Data in Android](https://reader033.vdocuments.site/reader033/viewer/2022061222/54c1b9194a79590b2d8b4798/html5/thumbnails/10.jpg)
Methods & Description
• setPrimaryClip (ClipData clip):
This method sets the current primary clip on the clipboard.
• setText(CharSequence text):
This method can be directly used to copy text into the clipboard.
• getText ( ):
This method can be directly used to get the copied text from the clipboard.
![Page 11: What is Clip Data in Android](https://reader033.vdocuments.site/reader033/viewer/2022061222/54c1b9194a79590b2d8b4798/html5/thumbnails/11.jpg)
Thank You
Apex TG India Pvt. Ltd. E-20 Sec-63 Noida
Apex TG India
E-20 , Sector 63, Noida
0120 – 4029000/9024/9025/
9027
+91-9953584548
Email id: [email protected]
Stay Connected with us for more PPT on Android