android WebView控件开发 可点击上传图片

下面三段代码会根据安卓不同的版本进行调用,三个都写进去就对了。

webView.setWebChromeClient(new WebChromeClient() {
			 @SuppressWarnings("unused")
			public void openFileChooser(ValueCallback<Uri> uploadMsg,String acceptType,
					String capture){valueCallback = uploadMsg;
					Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
					intent.addCategory(Intent.CATEGORY_OPENABLE);
					intent.setType("image/*");
					startActivityForResult(
							Intent.createChooser(intent, "完成操作需要使用"),
							1);
					
			}
			 @SuppressWarnings("unused")
			 public void openFileChooser(ValueCallback<Uri> uploadMsg,
					 String acceptType){
			 valueCallback = uploadMsg;
			Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
			intent.addCategory(Intent.CATEGORY_OPENABLE);
			intent.setType("image/*");
			startActivityForResult(
					Intent.createChooser(intent, "完成操作需要使用"),1);
			}
			 
			 @SuppressWarnings("unused")
			public void openFileChooser(ValueCallback<Uri> uploadMsg) {
				 valueCallback= uploadMsg;
				 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
				 intent.addCategory(Intent.CATEGORY_OPENABLE);
				 intent.setType("image/*");
				 startActivityForResult(
						 Intent.createChooser(intent, "完成操作需要使用"),1);
			 }
			
			@Override
			public boolean onJsAlert(WebView view, String url, String message,
					final JsResult result) {
				AlertDialog.Builder b2 = new AlertDialog.Builder(
						IndexActivity.this)
						.setTitle("温馨提示")
						.setMessage(message)
						.setPositiveButton("确认",
								new AlertDialog.OnClickListener() {
									@Override
									public void onClick(DialogInterface dialog,
											int which) {
										result.confirm();
									}
								});
				b2.setCancelable(false);
				b2.create();
				b2.show();
				return true;
			}
		});


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。