Preventing the Android “long press” to save images

流过昼夜 提交于 2019-12-10 17:28:14

问题


I've written a web-app in HTML and Javascript for iPhone and Android which involves the dragging and dropping images.

You initiate the drag by holding your finger over the image for about a second. However, Android then pops up the message giving me the option to save the image, set it as wallpaper etc.

How can I prevent Android from doing this? Is there a metatag I can use? Some javascript?


回答1:


Javascript has a function to prevent the default action of a browser for the event in question.

In your javascript try:

event.preventDefault();

See: https://developer.mozilla.org/en/DOM/event.preventDefault




回答2:


Use this event:

            $(document).on('contextmenu', function (e) {
                // stop long touch hold from poping up context menus
                return false;
            });



回答3:


In your activity that shows the webview, try extending GestureDetector.SimpleOnGestureListener. Then override the onLongPress(MotionEvent e) method and doing nothing.

If that doesn't work, you might have to create a custom webview that inherets from webview and overrides onLongPress there.

Or maybe you could try


WebView wv =(WebView) findViewById()
wv.setClickable(false)



来源:https://stackoverflow.com/questions/3480709/preventing-the-android-long-press-to-save-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!