Please help me to solve this problem. This is my code
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
clipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
clipboard.addPrimaryClipChangedListener(this);
return START_STICKY;
}
@Override
public void onPrimaryClipChanged() {
Log.d("log",clipboard.getPrimaryClip()+"");
ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
String clipText = item.getText().toString();
Log.d("log",clipText);
new SendClipBoardData().execute(postClipDataUrl,clipText);
}
Sometimes i'm getting error at ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);
Error: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference
The clipboard.getPrimaryClip()
returns ClipData { text/plain {NULL} }
,
but when i paste the same copied text in my note, i can see the text, i can't detect the problem,sometimes it work sometimes not.
And one more question, when copy works fine, i'm getting copied text result two or three times,but my event is working one time, what it can be ? Thanks in advance.