What is Clip Data in Android

11
Android Clipboard facebook.com/apex.tgi twitter.com/ ApextgiNoida pinterest.com/ apextgi

description

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.www.apextgi.in

Transcript of What is Clip Data in Android

Page 2: What is Clip Data in Android

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.

Page 3: What is Clip Data in Android

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);

Page 4: What is Clip Data in Android

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.

Page 5: What is Clip Data in Android

Copying data

Implementation:

ClipDataclipdata=ClipData.newPlainText("text", “String”);

clipboard.setPrimaryClip(clipdata);

Page 6: What is Clip Data in Android

ClipDataForm

• Text

• URI

• Intent

Page 7: What is Clip Data in Android

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.

Page 8: What is Clip Data in Android

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( );

Page 9: What is Clip Data in Android

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

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.

Page 11: What is Clip Data in Android

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