@@ -245,32 +245,33 @@ public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermiss
245245
246246 } else {
247247 String uri = "" ;
248+ URI parsedUri ;
248249 try {
249250 // get current URL for webview
250251 uri = mWebView .getUrl ();
251252 // get parsed URL
252- URI parsedUri = new URI (uri );
253- // create URL string of origin and path
254- String formattedUrl = parsedUri .getHost () + parsedUri .getPath ();
255- String alertMessage = String .format ("Allow %s to use your location?" , formattedUrl );
256- AlertDialog .Builder builder = new AlertDialog .Builder (this .mWebView .getContext ());
257- builder .setMessage (alertMessage );
258- builder .setCancelable (false );
259- builder .setPositiveButton ("Allow" , (dialog , which ) -> {
260- callback .invoke (origin , true , false );
261- });
262- builder .setNegativeButton ("Don't allow" , (dialog , which ) -> {
263- callback .invoke (origin , false , false );
264- });
265- AlertDialog alertDialog = builder .create ();
266- alertDialog .show ();
267- //Delay making `allow` clickable for 500ms to avoid unwanted presses.
268- Button posButton = alertDialog .getButton (AlertDialog .BUTTON_POSITIVE );
269- posButton .setEnabled (false );
270- this .runDelayed (() -> posButton .setEnabled (true ), 500 );
253+ parsedUri = new URI (uri );
271254 } catch (Exception e ) {
272255 System .out .println ("URI " + uri + " is a malformed URL" );
273256 }
257+ // create URL string of origin and path
258+ String formattedUrl = parsedUri .getHost () + parsedUri .getPath ();
259+ String alertMessage = String .format ("Allow %s to use your location?" , formattedUrl );
260+ AlertDialog .Builder builder = new AlertDialog .Builder (this .mWebView .getContext ());
261+ builder .setMessage (alertMessage );
262+ builder .setCancelable (false );
263+ builder .setPositiveButton ("Allow" , (dialog , which ) -> {
264+ callback .invoke (origin , true , false );
265+ });
266+ builder .setNegativeButton ("Don't allow" , (dialog , which ) -> {
267+ callback .invoke (origin , false , false );
268+ });
269+ AlertDialog alertDialog = builder .create ();
270+ alertDialog .show ();
271+ //Delay making `allow` clickable for 500ms to avoid unwanted presses.
272+ Button posButton = alertDialog .getButton (AlertDialog .BUTTON_POSITIVE );
273+ posButton .setEnabled (false );
274+ this .runDelayed (() -> posButton .setEnabled (true ), 500 );
274275 }
275276 }
276277
0 commit comments