Android Activity to WebView and WebView to Activity Parameter Passing

后端 未结 2 1823
小蘑菇
小蘑菇 2020-12-19 15:50

I have an application in which an activity communicates with our server and gets the outstanding amount details. I want users to pay the outstanding amount using a payment g

相关标签:
2条回答
  • 2020-12-19 16:02

    You can make use of Intent.putExtra() while navigating using Intents, Shared Preferences and also Bundle. Please read Android documentation for Shared Preferences, Intents, Bundle

    0 讨论(0)
  • 2020-12-19 16:05

    You could achieve what you want using a javascript WebAppInterface as demonstrated here.

    The main concept is that, you create a javascript interface inside the Activity holding your WebView.

    private class WebPayInterface {
        int amount;
        boolean success;
    
        @JavascriptInterface
        public void PaymentFinished(int amount, boolean success) {
            this.amount = amount;
            this.success = success;
    
            // do whatever you want in the parent activity.
        }
    }
    

    Add the interface to your webView

    webView.addJavascriptInterface(new WebPayInterface(), "WebPayInterface");
    

    Finally in your html code using javascript you can call

    WebPayInterface.PaymentFinished(100, true);
    
    0 讨论(0)
提交回复
热议问题