Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
How to access clipboard data in Android?

How do i get data from clip board. I want to get data and show in toast.Means In my android phone in any edit text .. When will long press and copy some string value .. That's should toast. How can i achieve this ?? In every tutorial i get, they copy from specify editText. I want like where ever in my phone i will copy some text .. I just need to get assess that particular string ... And clipboard.getText();also not working.

I tried

public class ClipBoardDataManager extends BroadcastReceiver {

        public ClipBoardDataManager() {
        }

        @Override
        public void onReceive(Context context, Intent intent) {

            String callNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

            ClipboardManager clipboard = (ClipboardManager) ctx.getSystemService(Context.CLIPBOARD_SERVICE);

            ClipData myClip = ClipData.newPlainText("text", clipboard.getText());
            clipboard.setPrimaryClip(myClip);


            ClipData abc = clipboard.getPrimaryClip();
            ClipData.Item item = abc.getItemAt(0);

            Toast.makeText(ctx,item.toString(),Toast.LENGTH_SHORT).show();


        }
    }

and register.

IntentFilter intentFilter1 = new IntentFilter(String.valueOf(Intent.FILL_IN_CLIP_DATA));

ctx.registerReceiver(clipBoardDataManager,intentFilter1);

Still i am not getting it .. Please help!!!

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Java

ClipboardManager clipBoard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
clipBoard.addPrimaryClipChangedListener(new OnPrimaryClipChangedListener() {

    @Override
    public void onPrimaryClipChanged() {
        ClipData clipData = clipBoard.getPrimaryClip();
        ClipData.Item item = clipData.getItemAt(0);
        String text = item.getText().toString();

        // Access your context here using YourActivityName.this
    }
});

Kotlin

val clipBoardManager = context.getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
clipBoardManager.addPrimaryClipChangedListener {
    val copiedString = clipBoardManager.primaryClip?.getItemAt(0)?.text?.toString()
    // Your code
}

Hope this helps

about 4 years ago · Santiago Trujillo Report

0

Kotlin

Clean, reusable, and simple working solution using Extension function -

fun Context.getFromClipBoard() : String? {
    val clipBoardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
    return clipBoardManager.primaryClip?.getItemAt(0)?.text?.toString()
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!