Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I open camera in webview?

Can I open android camera in webview?

like image 339
Piyush Avatar asked Apr 27 '11 12:04

Piyush


People also ask

How do I open the camera in WebView flutter?

In order to be able to use camera, for example, for taking images through <input type="file" accept="image/*" capture> HTML tag, you need to ask camera permission. If you need to capture video and audio, you need to ask also microphone permission.

What can WebView do?

If you want to deliver a web application (or just a web page) as a part of a client application, you can do it using WebView . The WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout.

What browser is used in WebView?

The WebView app is based on Chromium, the same open source project that powers the Google Chrome web browser, but it doesn't include all the features present in the full version of Chrome.


2 Answers

The easiest way to have the camera functionality when using a Webview would be the use an Intent.

If you use the API you have to build a lot of the UI yourself. This is good or bad depending on what you need to do in your application and how much control you need over the "picture taking process". If you just need a quick way to snap a photo and use it in your application, Intent is the way to go.

Intent Example:

private Uri picUri;
private void picture()
{
     Intent cameraIntent = new Intent("android.media.action.IMAGE_CAPTURE");
     File photo = new File(Environment.getExternalStorageDirectory(), "pic.jpg");
     cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
     picUri = Uri.fromFile(photo);
     startActivityForResult(cameraIntent, TAKE_PICTURE);
}

public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
    switch(requestCode){
        case TAKE_PICTURE:
            if(resultCode == Activity.RESULT_OK){
                Uri mypic = picUri;
                //Do something with the image.
            }
}

I borrowed parts of this example from another answer to build this originally. But I don't have the URL anymore.

In the app I am writing now, I convert this image to Base64 and then pass it to Javascript which then posts it to my server. But, that's probably more than you needed to know. :)

here is the link to make it work on webView

like image 179
Jonathan Avatar answered Sep 22 '22 01:09

Jonathan


As far as I know this isn't built into the Android API directly. However, you can use PhoneGap, which provides Javascript hooks into native device functionality (i.e., the camera).

You can view a list of supported features here, and read their Camera API documentation here.

like image 26
Donut Avatar answered Sep 19 '22 01:09

Donut