我正在尝试使用 onClickListener 启动 android 相机并拍摄一张照片,该照片保存到 sdcard 上的特定文件夹中,然后在 webview 中显示捕获的图像。继承人我的代码到目前为止。
private static final int CAMERA_REQUEST = 1888;
WebView WV;
Button capture;
Uri mCapturedImageURI;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.WV =(WebView) this.findViewById(R.id.webView1);
this.capture =(Button) findViewById(R.id.button1);
capture.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String fileName = "temp.jpg";
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
mCapturedImageURI = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent cameraIntent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(new File( "sdcard/image")));
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult( requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST) {
setContentView(R.id.webView1);
WV.getSettings().setAllowFileAccess(true);
WV.getSettings().setJavaScriptEnabled(true);
WV.getSettings().setBuiltInZoomControls(true);
String html = ("<html>" +
"<head>" +
"</head>" +
"<body>" +
"<img src=\"sdcard/temp.jpg\" alt=\"alternativo\" />" +
"</body>" +
"</html>"
);
WV.loadDataWithBaseURL("", html, "text/html", "utf-8", "");
}
}
}