我正在尝试使用onClickListener启动到Android摄像头并拍摄保存到SD卡上的特定文件夹的图片,然后在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", "");
}
}
}
答案 0 :(得分:0)
您只能使用putExtra()(String,int,float等)传递原始数据类型。
以下是可以帮助您的文档:
http://developer.android.com/reference/android/content/Intent.html
如果要传递其他数据,请使用Parcelable界面