Android: How to listen for longclick events in any text area in other applications?

I am trying to develop an Android application that provides an additional option when pasting data anywhere.

I know how to capture data from the clipboard. I just need to know how to listen for longclick events in any text area in other applications, such as browsers, facebook, twitter ... etc., so that my application runs, giving the user the ability to paste data into the clipboard after processing this , as an alternative to insert it in the usual way.

+4
source share
2 answers

We have come a long way since you asked this question, but there are actually two ways to do this:

  • refer to ClipboardManager.addPrimaryClipChangedListener() and register as a listener when the user copies the text. can be found in the documentation

  • Add the ACTION_PROCESS_TEXT Intent filter ACTION_PROCESS_TEXT that the user can select the custom action that you created / launched the application. More details can be found in the blog post.

0
source

You need to add an intent filter to the operation in question, for example:

  <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 process the data sent to you in the intention of 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); } 
-1
source

All Articles