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 of ClipboardManager and ClipData and ClipData.item to
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.
• Object of ClipboardManager is instantiated by calling the getSystemService()
method.
ClipboardManager clipboard = ( ClipboardManager ) getSystemService (CLIPBOARD_SERVICE);
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.
Copying data
Implementation:
ClipData clipdata = ClipData.newPlainText("text", “String”);clipboard.setPrimaryClip(clipdata);
ClipData Form
• Text
• URI
• Intent
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.
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 ( );
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 (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.
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