1

enter image description here` public class WebActivity extends BaseActivity implements PusherManager.PusherEventListener {

private ToolbarView toolbarView;
private WebView webview;
private ProgressDialog dialog;

private boolean isBRIePAYTransaction;
private String link, title, strHtmlData;
private boolean isUnlinked = false;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web);

    initData();
    inflateToolbar();

    webview = (WebView) findViewById(R.id.webview);
    webview.getSettings().setJavaScriptEnabled(true); // Set the java
    webview.getSettings().setAllowFileAccess(false);

    webview.clearHistory(); // Clearing history and cache of _webview
    webview.clearFormData(); // Clears the data in _webview
    webview.clearCache(true); // Clears cache in _webview
    webview.requestFocus(View.FOCUS_DOWN);

    if (!TextUtils.isEmpty(link)) {
        webview.loadUrl(link);
    } else if (!TextUtils.isEmpty(strHtmlData)) {
        //this will be used when html text is passed in the intent instead of link
        webview.loadData(strHtmlData, "text/html; charset=utf-8", "UTF-8");
    }

    dialog = ProgressDialog.show(WebActivity.this, "", "Loading...");
    dialog.setCancelable(true);
    webview.setWebViewClient(new WebViewClientDemo());
}

private void initData() {
    title = getIntent().getStringExtra(IntentParam.WebView.TITLE);
    link = getIntent().getStringExtra(IntentParam.WebView.LINK);
    strHtmlData = getIntent().getStringExtra(IntentParam.WebView.HTML_DATA);
    isBRIePAYTransaction = getIntent().getBooleanExtra(IntentParam.WebView.IS_BRI_ePAY_TRANSACTION, false);
    if (isBRIePAYTransaction) {
        PusherManager.getInstance().register(this);

        findViewById(R.id.ctv_do_not_press_back).setVisibility(View.VISIBLE);
        findViewById(R.id.rl_parent_done_toolbar).setVisibility(View.VISIBLE);

        CustomTextView tvDone = (CustomTextView) findViewById(R.id.done_web_activity);
        tvDone.setVisibility(View.VISIBLE);
        tvDone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}

private void inflateToolbar() {

    toolbarView = findViewById(R.id.toolbar_view_web_activity);

    toolbarView.setToolbarTitle(getResources().getString(R.string.settings_title));


    if (TextUtils.isEmpty(title)) {
        toolbarView.setToolbarTitle(getString(R.string.loader_loading));
    } else {
        toolbarView.setToolbarTitle(title);
    }

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    // drawer
    int id = item.getItemId();

    switch (id) {
        case android.R.id.home:
            finish();
            break;
    }

    return super.onOptionsItemSelected(item);
}

@Override
public void onPusherEvent(String eventName, String data) {
    if (eventName.equals(PusherManager.EVENT_TRANSACTION)) {
        RechargeResponse rechargeResponse = (new Gson()).fromJson(data, RechargeResponse.class);

        Intent briEPAYRechargeResponse = new Intent();
        briEPAYRechargeResponse.putExtra(IntentParam.WebView.BRI_ePAY_RECHARGE_RESPONSE, rechargeResponse);
        setResult(IntentParam.RequestCode.CREATE_BRI_EPAY_TRANSACTION, briEPAYRechargeResponse);
        finish();
    }
}

@Override
protected void onDestroy() {
    if (isBRIePAYTransaction)
        PusherManager.getInstance().unRegister(this);

    super.onDestroy();
}

private class WebViewClientDemo extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

        handleUrlResponceFromLinkaja(url);

        if (url.startsWith("tel:")) {
            Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
            startActivity(intent);
            view.reload();
            return true;
        } else if (url.startsWith("mailto:")) {
            MailTo mt = MailTo.parse(url);
            Intent i = newEmailIntent(mt.getTo(), mt.getSubject(), mt.getBody(), mt.getCc());
            startActivity(i);
            view.reload();
            return true;
        } else {
            view.loadUrl(url);
        }
        return true;
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);

        if (TextUtils.isEmpty(title)) {
            if (!TextUtils.isEmpty(view.getTitle())) {
                toolbarView.setToolbarTitle(view.getTitle());
            }
        }

        if (dialog != null) {
            dialog.dismiss();
        }
    }

    @Override
    public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
        super.onReceivedError(view, request, error);
        if (dialog != null) {
            dialog.dismiss();
        }
    }

    @Override
    public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
        super.onReceivedHttpError(view, request, errorResponse);
    }


    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
        // ignore ssl error
        if (handler != null) {
            handler.proceed();
        } else {
            super.onReceivedSslError(view, null, error);
        }

    }


    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
    }
}

private void handleUrlResponceFromLinkaja(String url) {

    if (url.contains("src=linkaja") && url.contains("mandateID=")) {
        showProgressDialog(null);
    } else if (url.contains("source=linkaja") && url.contains("success=true")) {
        if (url.contains("action=delink")) {
            isUnlinked = true;
        }
        PreferenceManager.setOnceUserLinkedLinkaja(true);
        UserApiManager.getInstance().fetchUserData();
        dismissProgressDialog();
        closeWebview();
    } else if (url.contains("source=linkaja") && url.contains("success=false")) {
        dismissProgressDialog();
        String content;
        if (url.contains("action=delink")) {
            content = getResources().getString(R.string.linkaja_delinking_failed_msg);
        } else {
            content = getResources().getString(R.string.linkaja_linking_failed_msg);
        }
        showErrorMsgDialog(content);
    }

}

private void closeWebview() {
    Intent intent = new Intent();
    intent.putExtra(IntentParam.LinkajaFragment.IS_UNLINKED, isUnlinked);
    setResult(RESULT_OK, intent);
    finish();
}

private Intent newEmailIntent(String address, String subject, String body, String cc) {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_EMAIL, new String[]{address});
    intent.putExtra(Intent.EXTRA_TEXT, body);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    intent.putExtra(Intent.EXTRA_CC, cc);
    intent.setType("message/rfc822");
    return intent;
}

private void showErrorMsgDialog(String message) {

    if (!TextUtils.isEmpty(message)) {
        final CustomDialogFragment customDialogFragment = CustomDialogFragment.getInstance(StringValues.EMPTY,
                message, getString(R.string.okay), null);
        customDialogFragment.setListeners(new CustomDialogFragment.CustomDialogClickedListener() {
            @Override
            public void onPositiveButtonClicked(String inputText) {
                customDialogFragment.dismiss();
                closeWebview();
            }

            @Override
            public void onNegativeButtonClicked() {
            }

            @Override
            public void onDismiss() {
            }
        });

        customDialogFragment.show(getSupportFragmentManager(), CustomDialogFragment.class.getName());
    } else {
        closeWebview();
    }
}

}`i am tring to load url in webview enter link description here

its loading in the browser . and also loading in the IOS webview. its not loading in android webview. I have also implemented the webview SSL error and page load error callback but its not giving any error also

8
  • add some code on how youre handling ssl anroid Commented Nov 21, 2019 at 7:21
  • Did you tried enabling JavaScript? Commented Nov 21, 2019 at 7:21
  • show some code or error logcat Commented Nov 21, 2019 at 7:22
  • android:supportsRtl="true" android:usesCleartextTraffic="true" in your manifest application section, try it Commented Nov 21, 2019 at 7:23
  • @NagendraHariKarthick i have enabled the javascript to true Commented Nov 21, 2019 at 7:23

5 Answers 5

1

Use this.

        startWebView("your url");

//Method
      private void startWebView(String url) {



    webView.setWebViewClient(new WebViewClient() {

        //If you will not use this method url links are opeen in new brower not in webview
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        //Show loader on url load
        public void onLoadResource (final WebView view, String url) {

        }
        public void onPageFinished(WebView view, String url) {

        }

    });
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(url);
}
Sign up to request clarification or add additional context in comments.

Comments

0

I have faced this issue as my device os was lower version and the URL that I was trying has the latest HTML5 code which was causing an error. so I have tried this

https://wiki.mozilla.org/Mobile/GeckoView

Comments

0

Check if you have declared network permission in AndroidManifest.xml

Comments

0

Try this

webview.webViewClient = AppWebViewClient()

Client

  class AppWebViewClient() : WebViewClient() {

        override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {

            view.loadUrl(url)
            return true
        }


    override fun onReceivedSslError(view: WebView, handler: SslErrorHandler, error: SslError) {
        var message = "SSL Certificate error."
        when (error.primaryError) {
            SslError.SSL_UNTRUSTED ->
            message = "The certificate authority is not trusted."
            SslError.SSL_EXPIRED ->
            message = "The certificate has expired.";
            SslError.SSL_IDMISMATCH ->
            message = "The certificate Hostname mismatch.";
            SslError.SSL_NOTYETVALID ->
            message = "The certificate is not yet valid.";
        }
        message += "\"SSL Certificate Error\" Do you want to continue anyway?";
        //Log your message
        handler.proceed()

    }
    }

Comments

0

I am using this code and also your link work perfectly for me just check this code:

final WebView webView=findViewById(R.id.webv);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);
    webView.loadUrl("https://sandbox.m.dana.id/d/ipg/inputphone?ipgForwardUrl=%2Fd%2Fportal%2Fcashier%2Fcheckout%3FbizNo%3D20191120111212800110166711700294814%26timestamp%3D1574243577619%26originSourcePlatform%3DIPG%26mid%3D216620000000451758252%26sign%3DEUuaP%252Bv3VB90wR%252ByxacDNBhc9F0YHQdRkpYwToc7pp%252FKSEphzL7Oonlt4bA0DHUeAjKkMCb%252B7FqUR81OUudGuFOHTh8Y84OKh2dW24VqzQf%252Bw6TM8goPHGHjCGGohEgK1OEBvIsG%252FmNbbUYEuNPPiAGoWgyiYqdNRTexr%252FTzJipYG%252FQGzzFcccEBAca5GxRwocyvgQ80P3p7LEsPcbhLKnVOq64L6ZrGW7kdthIUVxzgip4WVDajrb8%252F9fXXQOM%252BVwGHiaAzah03sRqDF%252FwR%252BElY2Hpllfs%252F1UX8TtkFVnQP8ag%252FrL9OXzWryIVRgsLYXLkYkV4lA6l8Hb13Hfbcow%253D%253D");
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            webView.setVisibility(View.VISIBLE);
        }
    });

these two line is for scaling webview content 100%(Fit to screen):

    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setUseWideViewPort(true);

Add Permission in manifest.xml

<uses-permission android:name="android.permission.INTERNET"/>

6 Comments

the same code is not working for me i have added the my activity code and error i am getting
can you pls check for this link sandbox.m.dana.id/m/portal/cashier/…
it's working perfectly @NitinZagade check my answer i used your link in code
pls copy exact url in comment. the url that is genarated after clicking the first url is diifrent
@NitinZagade make one demo project and then copy my code,run and tell me what happened.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.