本文介绍了Android版的onActivityResult(从MediaStore.ACTION_IMAGE_CAPTURE)没有得到银河S5数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发一个应用程序除其他外,使照片。拿我使用的图片:
I am developing an application which among other things makes pictures. To take the picture I use:
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camera, 1);
我的onActivityResult:
My onActivityResult:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Image_Selecting_Task(data);
if (requestCode == 1) {
Image_Selecting_Task(data);
} else if (requestCode == 2) {
Image_Selecting_Task(data);
}
}
public void Image_Selecting_Task(Intent data) {
try {
if (data.getData() != null) {
....
} else {
}
}
}
在银河S2,S3,TAB3,作品完美,但银河S5我无法获得数据。
但是,如果我从库中选择图像工作的。
In Galaxy s2, s3, tab3, works perfect, but Galaxy S5 I can not get the data.However if I select an image from the gallery this works.
推荐答案
请试试我的code:
public class GetPhotoActivity
{
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 50;
public static final int MEDIA_TYPE_IMAGE = 1;
private Uri _fileUri;
private void TakePictureIntent()
{
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
_fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, _fileUri);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
try {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
_imageView.setImageBitmap(DisplayRotatedPhoto(_fileUri));
}
else if (resultCode == RESULT_CANCELED)
{
Intent intent = new Intent(GetPhotoActivity.this, NewNoteActivity.class);
intent.putExtra("Project_ID", _projectID);
startActivity(intent);
finish();
}
else {
Toast.makeText(this, "An error has occurred...", Toast.LENGTH_LONG).show();
}
}
} catch (Exception e) {
Toast.makeText(this, "An error has occurred...", Toast.LENGTH_LONG).show();
}
}
private Bitmap DisplayRotatedPhoto(Uri path) {
String filePath = path.toString().substring(8);
Bitmap oriented = null;
BitmapFactory.Options bitmapFactoryOptions = new BitmapFactory.Options();
bitmapFactoryOptions.inJustDecodeBounds = true;
int REQUIRED_SIZE = 100;
int width_tmp = bitmapFactoryOptions.outWidth, height_tmp = bitmapFactoryOptions.outHeight;
int scale = 2;
while (true) {
if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE)
break;
width_tmp /= 2;
height_tmp /= 2;
scale++;
}
BitmapFactory.Options bitmapFactoryOptions2 = new BitmapFactory.Options();
bitmapFactoryOptions2.inSampleSize = scale;
Bitmap bmp = BitmapFactory.decodeFile(filePath, bitmapFactoryOptions2);
try {
ExifInterface exif = new ExifInterface(filePath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
Matrix m = new Matrix();
switch (orientation) {
case 2:
m.setScale(-1, 1);
break;
case 3:
m.setRotate(180);
break;
case 4:
m.setRotate(180);
m.setScale(-1, 1);
break;
case 5:
m.setRotate(90);
m.setScale(-1, 1);
break;
case 6:
m.setRotate(90);
break;
case 7:
m.setRotate(-90);
m.setScale(-1, 1);
break;
case 8:
m.setRotate(-90);
break;
default:
m.setScale(1, 1);
break;
}
oriented = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), m, true);
} catch (IOException e) {
Toast.makeText(this, "An error has occurred...", Toast.LENGTH_LONG).show();
} finally {
return oriented;
}
}
private Uri getOutputMediaFileUri(int type) {
return Uri.fromFile(getOutputMediaFile(type));
}
/**
* Create a File for saving an image or video
*/
private File getOutputMediaFile(int type) {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
if (type == MEDIA_TYPE_IMAGE) {
_mediaFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), File.separator + "IMG_" + timeStamp + ".jpg");
}
else {
return null;
}
return _mediaFile;
}
}
这篇关于Android版的onActivityResult(从MediaStore.ACTION_IMAGE_CAPTURE)没有得到银河S5数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!