I'm trying to get text copied into the clipboard using the following listener:
import android.content.ClipboardManager.OnPrimaryClipChangedListener;
import com.orhanobut.logger.Logger;
public class ClipboardListener implements OnPrimaryClipChangedListener
{
public void onPrimaryClipChanged()
{
// do something useful here with the clipboard
// use getText() method
Logger.d("Clipped");
}
}
The listener is initialized as follows:
ClipboardManager clipBoard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
clipBoard.addPrimaryClipChangedListener( new ClipboardListener());
After the text is copied into the clipboard onPrimaryClipChanged
is fired, but I don't know how to get the copied text in this method using ClipboardManager.getPrimaryClip() because the method is not available from the context and is not passed in the param of onPrimaryClipChanged
.