Atitit.android webview h5运行环境总结
1. WebView 的使用
browExt.play();
实现模式是绑定一个可以自定义浏览器对象
转载请注明来源:
sendNSCommand('play',video);
4. code
package com.example.atiplat_vodcp;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URLEncoder;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.widget.Toast;
public class browExtObj {
public static String getTrace(Throwable t) {
StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter);
t.printStackTrace(writer);
StringBuffer buffer = stringWriter.getBuffer();
return buffer.toString();
}
MainActivity mainActivity;
public browExtObj(MainActivity mainActivity2) {
mainActivity = mainActivity2;
}
@JavascriptInterface //sdk17版本以上加上注解 solu click btn ma fein ..
public void play() {
try {
String mv = "smb://192.168.2.106/e/非蓝光/大头儿子小头爸爸/新大头儿子和小头爸爸之秘密计划.mp4";
Log.v("::::mv in html ", mv);
Toast.makeText(mainActivity,
"play in html,mv:" + new File(mv).exists(),
Toast.LENGTH_LONG).show();
String mv2 = Environment.getExternalStorageDirectory().getPath()
+ "/Test_Movie.m4v";
mv="http://127.0.0.1:7788/?file="+URLEncoder.encode(mv,"utf-8");
//Log.v("URI html:::::::::", uri.toString());
Uri uri = Uri.parse(mv);
// 调用系统自带的播放器
Intent intent = new Intent(Intent.ACTION_VIEW);
Log.v("URI html:::::::::", uri.toString());
// intent.setData(uri);
intent.setDataAndType(uri, "video/*");
mainActivity.startActivity(intent);
System.out.println("--form_load finish");
} catch (Throwable e) {
Log.i("::::::::::::exp", getTrace(e));
}
}
5. Webview codeWebView webView;
public static String getTrace(Throwable t) {
StringWriter stringWriter= new StringWriter();
PrintWriter writer= new PrintWriter(stringWriter);
t.printStackTrace(writer);
StringBuffer buffer= stringWriter.getBuffer();
return buffer.toString();
}
@SuppressLint("SetJavaScriptEnabled")
public void form_load() {
try {
new AlertDialog.Builder(this).setTitle(simple)
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://139.196.164.150:8080/lime/cmsWechat/list.html");
} catch (Throwable e) {
Log.i("exp", getTrace(e));
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// //加载需要显示的网页
// webview.loadUrl("http://www.51cto.com/");
//
setContentView(R.layout.activity_main);
form_load();
// setContentView(webView);
}