You can interface android native code with javascript in order to capture the click on a button and have android code to send an intent to open the cammera, take the photo, and store it in some path.
Then, in onActivityResult you will take care of getting the photo from the path and uploading it to the webserver. To do this one way is to encode the bitmap in a base64 string and send it in a POST form using an android http client.
I will show how to do the interface between javscript and android (which is what the quesiton is about), all the rest regarding manipulating the foto has its own complexities and there are many tutorials about it.
Main Activity
public class MainActivity extends AppCompatActivity { private WebView webView; private Bitmap imageBitmap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); webView = (WebView) findViewById(R.id.webview); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webView.addJavascriptInterface(new WebAppInterface(this),"Android"); webView.loadData( "<Button id=\"btnTakePhoto\" onClick=\"takePhoto()\">TakePhoto</Button><div class=\"takePhoto\">\n" + "<script type=\"text/javascript\">" + "function takePhoto() {\n" + " Android.takePhoto();\n" + " }\n" + "</script>" + "</div>", "text/html","UTF-8"); } public class WebAppInterface { Context mContext; /** Instantiate the interface and set the context */ WebAppInterface(Context c) { mContext = c; } /** The android function calld from javascript */ @JavascriptInterface public void takePhoto() { dispatchTakePictureIntent(); } } /* This gests a Thumbnail only*/ static final int REQUEST_IMAGE_CAPTURE = 1; private void dispatchTakePictureIntent() { Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (takePictureIntent.resolveActivity(getPackageManager()) != null) { startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { Bundle extras = data.getExtras(); imageBitmap = (Bitmap) extras.get("data"); /* Encode bitmap as base64 and transmit to server */ } } }
NOTE: That this kind of interfacing is insecure on Andriod below 17.
EDIT 1
The html
<html> <body> <div class="takePhoto"> <Button onClick="takePhoto()">Take Photo </Button> </div> <script type="text/javascript"> function takePhoto(){ Android.takePhoto(); } </script> </body> </html>
EDIT 2
In the manifest I only added:
<uses-feature android:name="android.hardware.camera" android:required="true" />
For your app you also need INTERNET permission.
<input type="file" id="myinput" accept="image/*;capture=camera" capture>