1

I need to secure my cordova app by disabling the copy/paste options throughout the app. I found the following code which works perfectly fine (i.e. disables the copy/paste options if we touch and hold on any input texts).

public class CopyPasteDisabler extends CordovaPlugin {

    @Override
    public void initialize(CordovaInterface cordova, CordovaWebView webView) {
        super.initialize(cordova, webView);

        webView.getView().setOnLongClickListener(new View.OnLongClickListener() {
             @Override
             public boolean onLongClick(View v) {
                 return true;
             }
         });

    }
}

But the copy/paste options are still showing up when I double tap on any input field texts. I need to disable that too. How could we achieve that?

Thanks

UPDATE 1:

Just figured out a way to disable those options on double tap using GestureDetector. But those options are still showing up on 3 taps. So, the problem still exists there. The new code looks like as follows:

public class CopyPasteDisabler extends CordovaPlugin {

    private GestureDetector mGestureDetector;

    @Override
    public void initialize(CordovaInterface cordova, CordovaWebView webView) {
        super.initialize(cordova, webView);

        mGestureDetector = new GestureDetector(cordova.getActivity(), new DoubleTapGestureDetector());

        webView.getView().setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                return mGestureDetector.onTouchEvent(motionEvent);
            }
        });

        webView.getView().setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                return true;
            }
        });
    }

    private class DoubleTapGestureDetector extends GestureDetector.SimpleOnGestureListener {

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            return true;
        }

        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            return true;
        }
    } 
}

enter image description here

Manoj Shrestha
  • 4,246
  • 5
  • 47
  • 67

2 Answers2

0

You can disable double tap from within Javascript like this :

$("body").nodoubletapzoom();
Iram Bukhari
  • 487
  • 1
  • 5
  • 15