[英]Can I open camera in webview?
webview可以打開android攝像頭嗎?
使用 Webview 時擁有相機功能的最簡單方法是使用 Intent。
如果您使用 API,您必須自己構建很多 UI。 這取決於您在應用程序中需要做什么以及您需要對“拍照過程”進行多少控制。 如果您只需要一種快速拍攝照片並在應用程序中使用它的方法,Intent 就是 go 的方法。
意圖示例:
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.
}
}
我從另一個答案中借用了這個例子的一部分來最初構建它。 但我沒有 URL 了。
在我現在正在編寫的應用程序中,我將此圖像轉換為 Base64,然后將其傳遞給 Javascript,然后將其發布到我的服務器。 但是,這可能比您需要知道的要多。 :)
這是使它在 webView 上工作的鏈接
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.