title: Letting HTML5 access Android's camera using KitKat
body: <p>I am using the following code which works with previous android versions to access the camera and phone files though a webview however it doesn't seem to work when I'm running it using KitKat. I also don't want to use phonegap to solve the problem. I'm not sure why this is happening if anyone can suggest a solution I would really appreciate it </p>
  
  <pre><code>public class Home extends Activity {
  
       //private Button button;
      private WebView webView;
      final Activity activity = this;
      public Uri imageUri;
  
      private static final int FILECHOOSER_RESULTCODE = 2888;
      private ValueCallback&lt;Uri&gt; mUploadMessage;
      private Uri mCapturedImageURI = null;
  
  
      public void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.home);
  
          //Get webview 
          webView = (WebView) findViewById(R.id.webView1);
  
          // Define url that will open in webview 
          String webViewUrl = "http://www.nutritics.com/test.html";
  
          webView.setWebViewClient(new WebViewClient(){
              @Override
              public void onReceivedSslError (WebView webView, SslErrorHandler handler, SslError error) {
                  handler.proceed();
              }
          });
  
          // Javascript inabled on webview  
          webView.getSettings().setJavaScriptEnabled(true);
  
          // Other webview options
          webView.getSettings().setLoadWithOverviewMode(true);
  
          //webView.getSettings().setUseWideViewPort(true);
  
          //Other webview settings
          webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
          webView.setScrollbarFadingEnabled(false);
          webView.getSettings().setBuiltInZoomControls(true);
          webView.getSettings().setPluginState(PluginState.ON);
          webView.getSettings().setAllowFileAccess(true);
          webView.getSettings().setSupportZoom(true); 
  
          //Load url in webview
          webView.loadUrl(webViewUrl);
  
          startWebView(); 
  
      }
  
      private void startWebView() {
  
          webView.setWebChromeClient(new WebChromeClient() {
  
              // openFileChooser for Android 3.0+
              public void openFileChooser(ValueCallback&lt;Uri&gt; uploadMsg, String acceptType){  
  
                  // Update message
                  mUploadMessage = uploadMsg;
  
                  try{    
  
                      // Create AndroidExampleFolder at sdcard
  
                      File imageStorageDir = new File(
                                             Environment.getExternalStoragePublicDirectory(
                                             Environment.DIRECTORY_PICTURES)
                                             , "AndroidExampleFolder");
  
                      if (!imageStorageDir.exists()) {
                          // Create AndroidExampleFolder at sdcard
                          imageStorageDir.mkdirs();
                      }
  
                      // Create camera captured image file path and name 
                      File file = new File(
                                      imageStorageDir + File.separator + "IMG_"
                                      + String.valueOf(System.currentTimeMillis()) 
                                      + ".jpg");
  
                      mCapturedImageURI = Uri.fromFile(file); 
  
                      // Camera capture image intent
                      final Intent captureIntent = new Intent(
                                                    android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
  
                      captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
  
                      Intent i = new Intent(Intent.ACTION_GET_CONTENT); 
                      i.addCategory(Intent.CATEGORY_OPENABLE);
                      i.setType("image/*");
  
                      // Create file chooser intent
                      Intent chooserIntent = Intent.createChooser(i, "Image Chooser");
  
                      // Set camera intent to file chooser 
                      chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS
                                             , new Parcelable[] { captureIntent });
  
                      // On select image call onActivityResult method of activity
                      startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);
  
                    }
                   catch(Exception e){
                       Toast.makeText(getBaseContext(), "Exception:"+e, 
                                  Toast.LENGTH_LONG).show();
                   }
  
              }
  
              // openFileChooser for Android &lt; 3.0
              public void openFileChooser(ValueCallback&lt;Uri&gt; uploadMsg){
                  openFileChooser(uploadMsg, "");
              }
  
              //openFileChooser for other Android versions
              public void openFileChooser(ValueCallback&lt;Uri&gt; uploadMsg, 
                                         String acceptType, 
                                         String capture) {
  
                  openFileChooser(uploadMsg, acceptType);
              }
  
              // The webPage has 2 filechoosers and will send a 
              // console message informing what action to perform, 
              // taking a photo or updating the file
  
              public boolean onConsoleMessage(ConsoleMessage cm) {  
  
                  onConsoleMessage(cm.message(), cm.lineNumber(), cm.sourceId());
                  return true;
              }
  
              public void onConsoleMessage(String message, int lineNumber, String sourceID) {
                  //Log.d("androidruntime", "Show console messages, Used for debugging: " + message);
  
              }
          });   // End setWebChromeClient
       }
  
      // Return here when file selected from camera or from SDcard
  
      @Override 
      protected void onActivityResult(int requestCode, int resultCode, Intent intent) { 
  
       if(requestCode==FILECHOOSER_RESULTCODE)  
       {  
  
              if (null == this.mUploadMessage) {
                  return;
  
              }
  
             Uri result=null;
  
             try{
                  if (resultCode != RESULT_OK) {
  
                      result = null;
  
                  } else {
  
                      // retrieve from the private variable if the intent is null
                      result = intent == null ? mCapturedImageURI : intent.getData(); 
                  } 
              }
              catch(Exception e)
              {
                  Toast.makeText(getApplicationContext(), "activity :"+e,
                   Toast.LENGTH_LONG).show();
              }
  
              mUploadMessage.onReceiveValue(result);
              mUploadMessage = null;
  
       }
  
      }
  
      // Open previous opened link from history on webview when back button pressed
  
      @Override
      // Detect when the back button is pressed
      public void onBackPressed() {
  
          if(webView.canGoBack()) {
  
              webView.goBack();
  
          } else {
              // Let the system handle the back button
              super.onBackPressed();
          }
      }
  
  }
  </code></pre>