Android Question Handling LongClick in WebView

andrewj

Active Member
Licensed User
Longtime User
Hi,
I want to capture a long press on a URL in a WebView and offer "open in new tab" and "download" options, as well as just "open". I can detect the LongPress, but this doesn't have any URL information.

1. Is there a known way to get the URL at this point?
2. I thought about maybe simulating a single press from within my LongPress code, which will trigger the OverRideURL event, and I can do my handling there, but I can't find out how to simulate a click in code.

Any ideas?
Thanks
Andrew
 

DonManfred

Expert
Licensed User
Longtime User
Why you want to simulate a click in a LongClick event to use OverRideURL when you can use OverRideURL in LongClick directly!?
 
Upvote 0

andrewj

Active Member
Licensed User
Longtime User
Hi Manfred,
I don't quite understand what you're saying. When I'm in the LongClick event I don't know the URL, and OverrideURL doesn't fire if I've done a long click. Am I doing something wrong? Could you perhaps post a couple of lines of code to explain what I should do?

Thanks
Andrew
 
Upvote 0

andrewj

Active Member
Licensed User
Longtime User
Hi,
I'm actually using the flingableWebView, but it has the same problem. LongPress just provides X and Y coordinates, not the URL.
Am I missing something?
Andrew
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Hi,
I'm actually using the flingableWebView, but it has the same problem. LongPress just provides X and Y coordinates, not the URL.
Am I missing something?

If i interprete the Link above correctly then should should have a look at the FlingableWebView´s Properties.

B4X:
dim url as string
url = flingableWebView1.URL

FlingableWebView
Version:
0.02
  • FlingableWebView
    Events:
    • DoubleTap (X As Float, Y As Float) As Boolean
    • Fling (MovementX As Float, VelocityX As Float, MovementY As Float, VelocityY As Float) As Boolean
    • LongPress (X As Float, Y As Float)
    • OverrideUrl (Url As String) As Boolean
    • PageFinished (Url As String)
    • SingleTap (X As Float, Y As Float) As Boolean
    • UserAndPasswordRequired (Host As String, Realm As String) As String()
    Methods:
    • Back
    • BringToFront
    • CaptureBitmap As BitmapWrapper
    • Forward
    • Initialize (arg1 As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • LoadHtml (Html As String)
    • LoadUrl (Url As String)
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • StopLoading
    • Zoom (In As Boolean) As Boolean
    Permissions:
    • android.permission.INTERNET
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • JavaScriptEnabled As Boolean
    • Left As Int
    • Tag As Object
    • Top As Int
    • Url As String [read only]
    • Visible As Boolean
    • Width As Int
    • ZoomEnabled As Boolean
 
Last edited:
Upvote 0

andrewj

Active Member
Licensed User
Longtime User
I don't think you can do that, but you can tap on it and grab the URL on OverrideUrl
B4X:
Sub WebView1_OverrideUrl(Url As String) As Boolean
    ToastMessageShow(Url, False)
End Sub
That doesn't help. First I have to do a long press, then I have to do a short press at the same location. That's exactly what I'm trying to avoid.

Surely there's a way of either getting the URL during the long press, or "faking" the additional short press.

Any ideas?
Andrew
 
Upvote 0

andrewj

Active Member
Licensed User
Longtime User
Hi
It turned out to be relatively simple. From the flingableWebView longpress event I fire a timer which in turn sends a Down and Up pair of motion events back to the same point on the webview using Reflection. Then I can handle the longpress in the normal OverRideUrl event. You have to use a timer to make sure the longpress finishes processing first. It's working now.

Andrew
 
Upvote 0
Top