Submit form doesn't work on webview targetSdkVersion 29

165 views Asked by At

** After upgrading targetsdk version 29, I had to convert my application that works with XWalkView to Android Webview because the application did not work on Android 10. Now my application opens but the form is not submit. That's why the payment screen doesn't open. I wrote the code example below in my PayActivity.**

myInterface = new WebAppInterface(PayActivity.this,getApplicationContext());
    payWebView.addJavascriptInterface(myInterface, "NativePay");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
    WebSettings webSettings = payWebView.getSettings();
    payWebView.getSettings().setDomStorageEnabled(true);
    payWebView.getSettings().setAllowFileAccessFromFileURLs(true);
    payWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
    payWebView.getSettings().setAllowContentAccess(true);
    payWebView.getSettings().setJavaScriptEnabled(true);
    payWebView.getSettings().setDatabaseEnabled(true);
    payWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    payWebView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading (WebView view, String url) {
            return true;
        }
        public void onPageFinished(WebView view, String url) {
            if (url.contains("/payment/online_odeme_basarili")) {
                setResult(RESULT_OK);
                finish();
            } else if (url.contains("/payment/online_odeme_basarisiz")) {
                setResult(RESULT_FIRST_USER);
                finish();
            }
        
        }

    });
  
    payWebView.loadUrl("https://" + MainActivity.domainURL + "/payment/online_odeme/" + "1233 + "/" + "123" + "/"  + "01", null);

build.gradle

  compileSdkVersion 29
  buildToolsVersion '29.0.2'
defaultConfig {
    applicationId "..."
    minSdkVersion 16
    targetSdkVersion 29
    versionCode 6
    versionName "1.0.4"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

My Form like this

<form id="bankPost" method="post" action="<?php echo $url; ?>" style="width: 100%;display: block;">
<input type="hidden" name="exmple" value="12">
<input type="submit" class="button-confirm" value="Accept"></form>


   
1

There are 1 answers

0
Nur ARSLAN On

Problem is solved.

I added the following codes to my PayActivity.

@Override
protected void onPause() {
    super.onPause();
    if (payWebView != null) {
        payWebView.pauseTimers();
    }
}

@Override
protected void onResume() {
    super.onResume();
    if (payWebView != null) {
        payWebView.resumeTimers();
    }
}