首页 > 代码库 > android WebView控件开发 可点击上传图片

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;
			}
		});


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