Abhinav Tyagi
Abhinav Tyagi

Reputation: 5256

How to copy text with context to clipboard

I want to know how I can override default text copying mechanism in Android to copy text along with meta data like URL if copying from browser, filename if copying from fine file to clipboard manager?

What would be the approach for implementing this universally on any Android device?

Updated

Use Case:

I can get copied text but not sure how to get the URL without separately copying it?

Upvotes: 2

Views: 840

Answers (2)

Munish Kapoor
Munish Kapoor

Reputation: 3339

There is another way to copy text with url

You can use android WebView within your app and copy text from that WebView then you can use following code to get active url

String webUrl = webView.getUrl();

Hope it will solve your problem

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1006819

What would be the approach for implementing this universally on any Android device?

Android already supports the notion of a clipboard item having multiple pieces of data, as of Android 3.0. ClipData is the wrapper around the clipboard data, and it can have "one or Item instances, each of which can hold one or more representations of an item of data". Hence, there is nothing stopping developers from storing "URL if copying from browser, filename if copying from fine file" along with some text.

However:

  • You have no means of forcing Android app developers to create such clipboard items

  • You have no means of forcing Android app developers to consume such clipboard items (most apps will coerce the ClipData to a text representation and use that)

Upvotes: 2

Related Questions