Skip to content

Instantly share code, notes, and snippets.

@ashumkin
Last active March 20, 2019 08:08
Show Gist options
  • Select an option

  • Save ashumkin/3e2e213d657162ae26d364a85c64b472 to your computer and use it in GitHub Desktop.

Select an option

Save ashumkin/3e2e213d657162ae26d364a85c64b472 to your computer and use it in GitHub Desktop.
Rebuild fmx.jar

Patch Delphi's WebBrowser to avoid geolocation request denial. https://forums.fusetools.com/t/geolocation-not-enabled-in-webview-on-android/1374/4

Goto %BDS%\source\rtl\androiddex\java\fmx\src\com\embarcadero\firemonkey\webbrowser\ Patch WebBrowser.java with WebBrowser.java.patch (or just take WebBrowser.java applied) Run fmx.jar-rebuild.cmd. N.B. it rebuilds fmx.jar for Debug config only!

Open Delphi project. Disable fmx-dexed.jar in Libraries in Android Debug (see N.B. above) configuration. Add updated/just rebuilt %BDS%\lib\androd\debug\fmx.jar to Libraries. Build and deploy project.

N.B. you have to clean project (or just delete %platform%\%config%\fmx-dexed-.jar file) if you make new changes and rebuild fmx.jar for those changes to be applied.

set JAVA_HOME=c:\Program Files\Java\jdk1.8.0_66
set SDK=c:\Program Files\Embarcadero\Studio\20.0\PlatformSDKs
if "x%BDS%" == "x" set BDS=c:\Program Files\Embarcadero\Studio\20.0
cd %BDS%\source\rtl\androiddex\java\fmx\src
PATH %JAVA_HOME%\bin\;%PATH% & javac com\embarcadero\firemonkey\webbrowser\*.java -cp "%SDK%\android-sdk-windows\platforms\android-26\android.jar"
rem copy "%BDS%\lib\android\debug\fmx.jar" "%BDS%\lib\android\debug\fmx.jar.bak"
jar -vuf "%BDS%\lib\android\debug\fmx.jar" com\embarcadero\firemonkey\webbrowser\OnWebViewListener.class com\embarcadero\firemonkey\webbrowser\WebBrowser.class com\embarcadero\firemonkey\webbrowser\WebBrowser$1.class com\embarcadero\firemonkey\webbrowser\WebClient.class
package com.embarcadero.firemonkey.webbrowser;
import android.content.Context;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.GeolocationPermissions.Callback;
public class WebBrowser extends WebView {
private WebClient mWebClient;
private WebChromeClient mWebChromeClient;
public WebBrowser(Context context) {
super(context);
mWebClient = new WebClient();
this.setWebViewClient(mWebClient);
mWebChromeClient = new WebChromeClient() {
@Override
public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
callback.invoke(origin, true, false);
}
};
this.setWebChromeClient(mWebChromeClient);
this.setFocusable(true);
}
public void SetWebViewListener(OnWebViewListener listener){
mWebClient.SetWebViewListener(listener);
}
//@Override
//public boolean performLongClick() {
// return true;
//}
}
--- WebBrowser.java.bak 2018-11-19 07:55:00.000000000 +0300
+++ WebBrowser.java 2019-03-20 10:47:08.599956100 +0300
@@ -3,6 +3,7 @@
import android.content.Context;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
+import android.webkit.GeolocationPermissions.Callback;
public class WebBrowser extends WebView {
@@ -13,7 +14,12 @@
super(context);
mWebClient = new WebClient();
this.setWebViewClient(mWebClient);
- mWebChromeClient = new WebChromeClient();
+ mWebChromeClient = new WebChromeClient() {
+ @Override
+ public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
+ callback.invoke(origin, true, false);
+ }
+ };
this.setWebChromeClient(mWebChromeClient);
this.setFocusable(true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment