8

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

I have this code which gives 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 tell to send any phone state to the myreciever class now I want to get text from clipboard manager. is there any intent.action state which can call myreciever class when someone copies text.

Any kind of help or code will be appreciated.

1
  • @lori would you help me how did you do that because i couldn't find Commented Jul 11, 2014 at 13:00

2 Answers 2

14

Since there is now Action intent for clipboard, what you will need to do is create a broadcast receiver to start when your app is started on when the device first boots up. And then start a service to monitor the state of the clipboard.

This is a PERFECT project on google code that will show you EXACTLY what to do.

My Clip tutorial

4
  • 1
    Dude you genious man thankx a lot...:D this exactly what i need
    – Iori
    Commented Jan 6, 2012 at 16:12
  • No problem =) Glad to have helped Commented Jan 6, 2012 at 17:12
  • Hi @coder_For_Life22 I couldnt checkout the code at the link u have given..could u share the link from wer i could dwnld the source
    – Sudarshan
    Commented Feb 25, 2013 at 11:39
  • my-clips is too complicated.I do not understand what this project.please help me.**I need this** :( Please take a simple example. Commented Nov 13, 2013 at 13:22
0

I'm agree with "coder_For_Life22":"Since there is now Action intent for clipboard, ...".
I found two ways for monitoring "clipboard":
1-A way like what says "coder_For_Life22".
2-Using "ClipboardManager.OnPrimaryClipChangedListener()" method.
But both of them have issues :
In first way if user copy a word for example "Text" and then (even after sometimes and in another App) again copy the same word,you can not detect it.
Second way, is a solution for using android 3.0 api 11 and not lower.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.