0

I have a java application intended for a specific purpose. As part of the application, I want to pull the clipboard data from the attached Android Device. Is there any way to retrieve data residing in the Android Device's clipboard into the Java Application? I do not have any android app running on the device.

Is there any way to achieve the same via Appium?

Kris_28
  • 31
  • 7

2 Answers2

0

You can Access Android clipboard content.for sharing the content to your java application you need a connection between android and your java app.i think you can do it with a TCP socket connection.

ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); 

for setting text to clipboard you can use this.

clipboard.setText("Text to copy");

for getting data from clipboard use this.

clipboard.getText();

after getting your data from clipboard send it to your java application via Socket

Akhil Jayakumar
  • 2,262
  • 14
  • 25
  • I do not have any android application running on the device. Should I have to use ClipboardManager inside my Java application. Is it compatible? What if the device is not directly connected to host where java application is running? – Kris_28 Jan 04 '16 at 05:30
0

Yes, you could make your android app listen for ACTION_BATTERY_CHANGED broadcast. This broadcast's intent contains whether you are connected through plug or USB. You can find the sample code here.

Once you know you are connected through USB, you could access the ClipBoardManager like this, and copy it's contents to a file.

Then finally you could just pull the file using adb, as shown here.

Suggestion:

If you know that your mobile and desktop application are on the same network, you could just POST your clipboard data to a server running on your desktop app, or make a Socket Connection.

Community
  • 1
  • 1
Eric B.
  • 4,622
  • 2
  • 18
  • 33
  • Thanks for the response. But, I do not have any control on the android app that is running on the device. And ClipBoardManager cannot be used from a Java application directly. – Kris_28 Jan 04 '16 at 09:35