Andriod webview实现文件上传
来源:互联网 发布:令狐冲 不争取 知乎 编辑:程序博客网 时间:2024/05/29 12:04
在国外网站上看到的挺不错的 关于WebView的 http://stackoverflow.com/questions/5907369/file-upload-in-webview
public class MyWb extends Activity {/** Called when the activity is first created. */WebView web;ProgressBar progressBar;private ValueCallback<Uri> mUploadMessage; private final static int FILECHOOSER_RESULTCODE=1; @Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { if(requestCode==FILECHOOSER_RESULTCODE) { if (null == mUploadMessage) return; Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData(); mUploadMessage.onReceiveValue(result); mUploadMessage = null; } } @Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); web = (WebView) findViewById(R.id.webview01); progressBar = (ProgressBar) findViewById(R.id.progressBar1); web = new WebView(this); web.getSettings().setJavaScriptEnabled(true); web.loadUrl("http://www.script-tutorials.com/demos/199/index.html"); web.setWebViewClient(new myWebClient()); web.setWebChromeClient(new WebChromeClient() { //The undocumented magic method override //Eclipse will swear at you if you try to put @Override here // For Android 3.0+ public void openFileChooser(ValueCallback<Uri> uploadMsg) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); MyWb.this.startActivityForResult(Intent.createChooser(i,"File Chooser"), FILECHOOSER_RESULTCODE); } // For Android 3.0+ public void openFileChooser( ValueCallback uploadMsg, String acceptType ) { mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("*/*"); MyWb.this.startActivityForResult( Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE); } //For Android 4.1 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture){ mUploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); MyWb.this.startActivityForResult( Intent.createChooser( i, "File Chooser" ), MyWb.FILECHOOSER_RESULTCODE ); } }); setContentView(web); }public class myWebClient extends WebViewClient{ @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { // TODO Auto-generated method stub super.onPageStarted(view, url, favicon); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // TODO Auto-generated method stub view.loadUrl(url); return true; } @Override public void onPageFinished(WebView view, String url) { // TODO Auto-generated method stub super.onPageFinished(view, url); progressBar.setVisibility(View.GONE); }}//flipscreen not loading again@Overridepublic void onConfigurationChanged(Configuration newConfig){ super.onConfigurationChanged(newConfig);}// To handle "Back" key press event for WebView to go back to previous screen./*@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) { web.goBack(); return true; } return super.onKeyDown(keyCode, event);}*/
- Andriod webview实现文件上传
- Andriod webview实现文件上传
- Andriod webview实现文件上传
- Andriod webview实现文件上传
- android webview上传文件
- webview上传文件
- webview的文件上传
- Android WebView 文件上传
- android webview上传文件
- WebView上传文件
- WebView上传文件
- Webview上传文件
- Android Webview实现图片、文件上传及启动相机功能
- Android Webview实现图片、文件上传及启动相机功能
- android 支持WebView上传文件
- android WebView上传文件代码
- Android WebView上传文件(转)
- 如何实现webview上传图片
- vs2010下release版本调试设置
- HDU2112:HDU Today(Dijkstra)
- WinForm中窗体resize的时候对于控件位置的控制
- ORACLE官方文档地址
- 机器学习中的数学(4)-线性判别分析(LDA), 主成分分析(PCA)
- Andriod webview实现文件上传
- 本地测试用的帐号csv文件
- c#关于网页内容抓取,简单爬虫的实现。(包括动态,静态的)
- Android(Java):视频播放
- 比较全面的event对像在IE与FF中的区别 推荐
- Oracle 特殊符号'&'的处理
- Python入门教程
- Android开发之InstanceState详解
- 使用java快速生成word文档