In the browser, you can longClick on URLs. In my WebView, you cannot. How can I make it so you can?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I had this same problem.
Unfortunately, I could not find a way to make the standard browser menu options appear. You have to implement each one yourself. What I did was to register the WebView for context menus with
activity.registerForContextMenu(webView). Then I subclassed the WebView and overrode this method:If you want to do something other than a context menu, then use an
OnLongClickListener. However you want to intercept the long click event, theHitTestResultis the key. That’s what will allow you to figure out what the user clicked on and do something with it.I haven’t actually implemented “Save Link” myself, I just included it as an example here. But to do so you would have to do all the processing yourself; you’d have to make an HTTP GET request, receive the response, and then store it somewhere on the user’s SD card. There is no way that I know of to directly invoke the Browser app’s download activity. Your “Save Link” code will look something like this: