4

I'm trying to develop an Android application that provides an extra option when pasting data anywhere.

I know how to capture data from the clipboard. I just need to know how to listen to longclick events in any text area in other applications such as browsers,facebook,twitter...etc so that my application would be triggered giving the user the option to paste the data on the clipboard after processing it, as an alternative to pasting it in the normal way.

RivieraKid
  • 5,923
  • 4
  • 38
  • 47
Doaa A.
  • 129
  • 1
  • 2
  • 11
  • Umm I am pretty sure that would require a modified OS, I don't think the clipboard manager can be replaced like an intent for SMS and such. – Seth Hikari May 10 '11 at 02:37
  • Though this : http://dylantaylor.wordpress.com/clippy/ claims that it has a service that monitors the clipboard for changes, you could do the same and post an notification that take the clipboard content. – Seth Hikari May 10 '11 at 02:38

2 Answers2

0

We've come a long way since you asked this question but there are actually 2 ways to do that:

  1. call to to ClipboardManager.addPrimaryClipChangedListener() and sign up as a listener when a user copies text. can be found in the Documentation

  2. Add the ACTION_PROCESS_TEXT Intent Filter so the user can pick a custom action you created/start your app. More can be found in this Blog Post

Roee
  • 1,155
  • 3
  • 15
  • 24
-1

You need to add an intent filter to the activity in question, like so:

        <activity android:name=".PostActivity">
            <intent-filter>
              <action android:name="android.intent.action.SEND" />
              <category android:name="android.intent.category.DEFAULT" />
              <data android:mimeType="text/plain" />
            </intent-filter>       
        </activity>

Then you just need to handle the data sent to you in the intent in your Activity

Uri data = getIntent().getData();
Bundle extras = getIntent().getExtras();
String messageText = "";
if (data != null) {
  messageText = data.toString();
} else if (extras != null) {
  messageText = extras.getString(Intent.EXTRA_TEXT);
}
dmon
  • 30,048
  • 8
  • 87
  • 96