【发布时间】:2011-08-13 19:39:29
【问题描述】:
我可以在 webview 中打开安卓相机吗?
【问题讨论】:
标签: android camera cordova android-webview android-camera
我可以在 webview 中打开安卓相机吗?
【问题讨论】:
标签: android camera cordova android-webview android-camera
使用 Webview 时拥有相机功能的最简单方法是使用 Intent。
如果您使用 API,您必须自己构建大量 UI。这取决于您在应用程序中需要做什么以及您需要对“拍照过程”进行多少控制。如果您只需要一种快速拍摄照片并在应用程序中使用的方法,Intent 就是您的最佳选择。
意图示例:
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.
}
}
我从另一个答案中借用了这个例子的一部分来最初构建这个。但是我没有网址了。
在我现在正在编写的应用程序中,我将此图像转换为 Base64,然后将其传递给 Javascript,然后将其发布到我的服务器。但是,这可能比您需要知道的要多。 :)
here 是让它在 webView 上工作的链接
【讨论】: