What is Clip Data in Android
description
Transcript of What is Clip Data in Android
Android Clipboard
facebook.com/apex.tgi
twitter.com/ApextgiNoida
pinterest.com/apextgi
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 ofClipboardManagerandClipDataandClipData.itemto use the copying and pasting framework.
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.
• ObjectofClipboardManageris instantiated by calling thegetSystemService() method.
ClipboardManagerclipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
Copying data
• The next thing that is need to do is to instantiate theClipDataobject by calling the respective type of data method of
theClipDataclass.
• In case of text data, thenewPlainText( ) method will be called. After that have to set that data as the clip of
theClipbaoardManagerobject.
Copying data
Implementation:
ClipDataclipdata=ClipData.newPlainText("text", “String”);
clipboard.setPrimaryClip(clipdata);
ClipDataForm
• Text
• URI
• Intent
ClipDataForm
• Text :newPlainText(label,text):
ReturnsaClipDataobject whose singleClipData.Itemobject contains a text string.
• URI :newUri(resolver, label, URI):
Returns aClipDataobject whose singleClipData.Itemobject contains a URI.
• Intent :newIntent(label, intent):
Returns aClipDataobject whose singleClipData.Itemobject contains Intent.
Data Pasting
• In order to paste the data, we will first get the clip by calling thegetPrimaryClip( ) method. And from that click will get the item
inClipData.Itemobject and from the object we will get the data.
ClipDataclipdata=clipboard.getPrimaryClip( );
ClipData.Itemitem =clipdata.getItemAt(0);
String text =item.getText( ).toString( );
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.
Methods & Description
• setPrimaryClip(ClipDataclip):
This method sets the current primary clip on the clipboard.
• setText(CharSequencetext):
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.
Thank You
Apex TG India Pvt. Ltd. E-20 Sec-63Noida
Apex TG India
E-20 , Sector 63, Noida
0120 – 4029000/9024/9025/9027
+91-9953584548
Email id: [email protected] Connected with us for more PPT on Android