MyWebView.java
2.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package xdycom.abao.myapplication;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.ValueCallback;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Toast;
/**
* Created by abao on 2017/3/30.
*/
public class MyWebView extends WebView {
private final static String URL="http://h5.test.3mang.com/web/";
public MyWebView(Context context) {
super(context);
// myWebView=new MyWebView(context);
// WebSettings webSettings=myWebView.getSettings();
// webSettings.setJavaScriptEnabled(true);
// myWebView.addJavascriptInterface(new MyJs(),"xdyAndroid");
//
// myWebView.loadUrl(URL);
}
public MyWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
class MyJs {
@JavascriptInterface
public String _js2native(String id,String parmp){
/* _native2js("接口名称","参数为JOSN字符串")*/
Log.e("js2native","id:"+id+" parmp:"+parmp);
return parmp;
}
@JavascriptInterface
public String _js2native(String parmp){
/* _native2js("接口名称","参数为JOSN字符串")*/
Log.e("js2native", " parmp:"+parmp);
return parmp;
}
}
/**
* 获取推流地址
* @return
*/
public String _native2js( String id, String parmp) {
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// myWebView.evaluateJavascript("javascript:_native2js('" + id + "','" + parmp + "')", new ValueCallback<String>() {
// @Override
// public void onReceiveValue(String value) {
// Log.e("MSG_evaluate","_native2js"+value);
// }
// });
// } else {
//
//// mWebView.loadUrl("javascript:imageVal('init')");
// }
return "";
}
}