com.blankj.utilcode.util.ResourceUtils Java Examples

The following examples show how to use com.blankj.utilcode.util.ResourceUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JMWebViewClient.java    From QPM with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {

    try {
        if (!TextUtils.isEmpty(url) && url.contains(JM_LOCAL_COLLECTOR_JS_PATH)) {
            InputStream inputStream = ConvertUtils.string2InputStream(ResourceUtils.readAssets2String("collector.js"), "utf-8");
            return new WebResourceResponse("application/javascript", "UTF-8", inputStream);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return super.shouldInterceptRequest(view, url);
}
 
Example #2
Source File: JMWebViewClient.java    From QPM with Apache License 2.0 4 votes vote down vote up
@Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);


//        (function() {
//            var script=document.createElement('script');
//            script.setAttribute('type','text/javascript');
//            script.setAttribute('src', 'https://www.gdky005.com/jm_collector.js');
//            document.head.appendChild(script);
//            console.log("WangQing_script_start");
//            script.onload = function() {
//                console.log("WangQing_BBB");
//            };
//            console.log("WangQing_script_end");
//        })();


        //TODO collector.js文件的地址,收集的功能主要在这里面实现
//        String injectJs = "http://your_url/collector.js";
//        String injectJsUrl = "//www.gdky005.com/jm_collector.js";
//        String injectJsUrl = "//h5.st.jumei.com/Test/utilTest";

        Uri uri = Uri.parse(url);
        String injectJsUrl = uri.buildUpon().path(JM_LOCAL_COLLECTOR_JS_PATH).toString();

//        String injectJsUrl = "http://h5.st.jumei.com" + JM_LOCAL_COLLECTOR_JS_PATH;

        String injectJs = ResourceUtils.readAssets2String("collector.js");

        if (!injectJs.equals("")) {
            String msg = "javascript:(function() {" +
                    "var script=document.createElement('script');" +
                    "script.setAttribute('type','text/javascript');" +
                    "script.setAttribute('src', '" + injectJsUrl +"');" +
//                    "script.setAttribute('text', '" + injectJs +"');" +
                    "document.head.appendChild(script);" +
                    "console.log(\"WangQing_script_start\");" +
                    "script.onload = function() {" +
                    "console.log(\"WangQing_Running!\");" +
                    "startWebViewMonitor();" +
                    "};" +
                    "console.log(\"WangQing_script_end\");" +
                    "})();";

            view.loadUrl(msg);
        }
    }