I'm searching for solution to disable copy/paste completely for EditText in android. I've tried no. of post and blogs but nothing working completely. Note that, it's working on some devices, but with same o/s on HTC device with with o/s 4.0.1, it's not working when user press on entered text three times once. Below is the sample class which I'm using for EditText, right now.
public class CustomEditText extends EditText{
boolean canPaste() {
return false;
}
@Override
public boolean isSuggestionsEnabled() {
return false;
}
public CustomEditText(Context context) {
super(context);
init();
}
public CustomEditText(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CustomEditText(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
this.context = context;
init();
}
private void init() {
this.setCustomSelectionActionModeCallback(new ActionModeCallbackInterceptor());
this.setLongClickable(false);
this.setSelected(false);
}
private class ActionModeCallbackInterceptor implements ActionMode.Callback {
public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; }
public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; }
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; }
public void onDestroyActionMode(ActionMode mode) {}
}
}
Note: I've check this solution EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event