Android 网页记录

    implementation 'com.just.agentweb:agentweb:4.1.4' // (必选)
    implementation 'com.just.agentweb:filechooser:4.1.4'// (可选)
    implementation 'com.download.library:Downloader:4.1.4'// (可选)

/**
 * Created by cenxiaozhong on 2017/5/26.
 * <p>
 * source code  https://github.com/Justson/AgentWeb
 */

public class WebPayActivity extends AppCompatActivity {


    protected AgentWeb mAgentWeb;
    private LinearLayout mLinearLayout;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_web_pay;
    }


    @Override
    protected void initWidget() {
        super.initWidget();
        mLinearLayout = (LinearLayout) this.findViewById(R.id.container);


        mAgentWeb = AgentWeb.with(this)
                .setAgentWebParent(mLinearLayout, new LinearLayout.LayoutParams(-1, -1))
                .useDefaultIndicator()
                .setWebChromeClient(mWebChromeClient)
                .setWebViewClient(mWebViewClient)
                .setMainFrameErrorView(R.layout.agentweb_error_page, -1)
                .setSecurityType(AgentWeb.SecurityType.STRICT_CHECK)
                .setOpenOtherPageWays(DefaultWebClient.OpenOtherPageWays.ASK)//打开其他应用时,弹窗咨询用户是否前往其他应用
                .interceptUnkownUrl() //拦截找不到相关页面的Scheme
                .createAgentWeb()
                .ready()
                .go(getUrl());

        mAgentWeb.getJsInterfaceHolder().addJavaObject("app", new JavaScriptinterface());
    }

    class JavaScriptinterface {

        @JavascriptInterface
        public void signComplete() {
            mAgentWeb.getUrlLoader().loadUrl(Constants2.Host + "/ipage_success.html");
        }

        @JavascriptInterface
        public void signError() {
            mAgentWeb.getUrlLoader().loadUrl(Constants2.Host + "/ipage_error.html");
        }

    }

    private WebViewClient mWebViewClient = new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            return super.shouldOverrideUrlLoading(view, request);
        }

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

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            mAgentWeb.getJsAccessEntrace().quickCallJs("sign",
                    getIntent().getStringExtra("singInfo"),
                    Constants2.Host + "/ipage_success.html",
                    Constants2.Host + "/ipage_error.html ");
        }
    };


    private WebChromeClient mWebChromeClient = new WebChromeClient() {
        @Override
        public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
        }
    };

    public String getUrl() {
        return getIntent().getStringExtra("url");
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (mAgentWeb.handleKeyEvent(keyCode, event)) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onPause() {
        mAgentWeb.getWebLifeCycle().onPause();
        super.onPause();

    }

    @Override
    protected void onResume() {
        mAgentWeb.getWebLifeCycle().onResume();
        super.onResume();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        Log.i("Info", "onResult:" + requestCode + " onResult:" + resultCode);
        super.onActivityResult(requestCode, resultCode, data);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        AgentWebConfig.clearDiskCache(this);
        mAgentWeb.getWebLifeCycle().onDestroy();

    }

    @Override
    public void onBackPressed() {
        if (mAgentWeb.getWebCreator().getWebView().canGoBack()) {
            mAgentWeb.getWebCreator().getWebView().goBack();
        } else {
            finish();
        }
    }

    public static void newIntent(BaseActivity mContext, String url, String singInfo) {
        Intent intent = new Intent();
        intent.setClass(mContext, WebPayActivity.class);
        intent.putExtra("url", url);
        intent.putExtra("singInfo", singInfo);
        mContext.startActivity(intent);
    }
}

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值