我正在使用以下代码在 Android 中捕获图像:
String fileName = "image.jpeg";
//create parameters for Intent with filename
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
values.put(MediaStore.Images.Media.DESCRIPTION,"Image captured by camera");
//imageUri is the current activity attribute, define and save it for later usage (also in onSaveInstanceState)
imageUri = getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
//create new Intent
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(intent, CAMERA_PIC_REQUEST);
捕获图像后,我使用以下代码获取图像:
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if( requestCode == CAMERA_PIC_REQUEST)
{
if(resultCode == Activity.RESULT_OK)
{
if(imageUri == null)
imageUri = data.getData();
String filePath = getPath(imageUri);
UploadContentToServer(filePath, "image.jpeg");
//getBytesFromFile(filePath);
}
}
}
它在横向模式下除了 HTC 之外的所有设备都可以正常工作。
我在我的应用程序中使用纵向模式。但是当我在 HTC 中以横向模式拍摄图像时,我的imageUri 为空。如何解决此问题,仅在 HTC 设备中。