Broadcast receiver

I want to make a simple service (which will work in the background), when any user copies something from a browser or SMS, etc., there will be a toast showing that the text

I have this code that gives a toast when there is a phone call

public class MyPhoneReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras(); if (extras != null) { // this code is for to accept the telephone call String state = extras.getString(TelephonyManager.EXTRA_STATE); if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { String phoneNumber = extras.getString(TelephonyManager.EXTRA_INCOMING_NUMBER); Toast.makeText(context, phoneNumber, Toast.LENGTH_SHORT).show(); } } } } 

and this code in manifest.xml

 <action android:name="android.intent.action.PHONE_STATE"></action> 

Now this code says to send the state of the phone to the myreciever class, now I want to get the text from the clipboard manager. is there any intent.action state that intent.action class can call when someone copies text.

Any help or code would be appreciated.

+7
source share
2 answers

Since the intent is Action on the clipboard, you will need to create a broadcast receiver to start when your application starts, when the device boots first. Then start the clipboard status monitoring service.

This is a PERFECT project in Google code that will show you exactly what to do.

My video tutorial

+13
source

I agree with "coder_For_Life22": "Since now there is the intention of Action for the clipboard ...".
I found two ways to monitor the clipboard:
1-way, like what coder_For_Life22 says.
2-Using the ClipboardManager.OnPrimaryClipChangedListener () method.
But both of them have problems :
In the first case, if the user copies a word, for example, β€œText,” and then (even after sometimes in another application) copy the same word again, you will not be able to detect it.
The second way is a solution for using android 3.0 api 11 and not lower.

0
source

All Articles