What exactly is "label" parameter in ClipData in Android?

hackjutsu picture hackjutsu · Oct 19, 2015 · Viewed 16.9k times · Source

According to the Android documentation, ClipData use "label" as a kind of representation to the copied data.

ClippedData is a complex type containing one or Item instances, each of which can hold one or more representations of an item of data. For display to the user, it also has a label and iconic representation.

And then it further explains "label" as User-visible label for the clip data in some API docs. However, I'm still confused about the usage of the label.

How is this label visible to users? How should I use it? What should I set for this label when I call the ClipData factory method newPlainText(CharSequence label, CharSequence text)? for example:

private void copyToClipBoard() {

    ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
    ClipData clip = ClipData.newPlainText(
            "text label", // What should I set for this "label"?
            "content to be copied");
    clipboard.setPrimaryClip(clip);
    Toast.makeText(AboutActivity.this, "Saved to clip board", Toast.LENGTH_SHORT).show();
}

Answer

Gaurav picture Gaurav · Oct 19, 2015
ClipData clip = ClipData.newPlainText(
            "text label", 
            "content to be copied");

here text label describes what data is in clip

eg.

ClipData clip = ClipData.newPlainText(
            "user Name",
            user.getName()); 

we can retrive this by using

clip.getDescription ();