Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android clipboard broadcast receiver

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.

like image 987
Iori Avatar asked Jan 06 '12 14:01

Iori


1 Answers

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

like image 56
coder_For_Life22 Avatar answered Nov 06 '22 23:11

coder_For_Life22