我正在开发一款新应用。该应用程序使用相机和外部存储。 虽然在我的LG G3上应用程序工作得很好(以及在AVD模拟器上),当在三星S5上测试时,当我从相机获得结果时,在拍摄照片后(在onActivityResult方法中)看起来像没有结果。意图为空。我只是添加并说照片正在拍摄,并保存在指定位置,但由于某种原因我无法使用它。如上所述,同样精确的代码在我的G3上运行良好。
我还试图从头开始创建一个相机测试应用程序,它只能在G3和模拟器上运行。
代码:
static final int REQUEST_TAKE_PHOTO = 1;
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
String mCurrentPhotoPath;
Bitmap bitmapImg;
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
/*Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
mImageView.setImageBitmap(imageBitmap);*/
bitmapImg = BitmapFactory.decodeFile(mCurrentPhotoPath);
mImageView.setImageBitmap(bitmapImg);
}
}
@Override
public void onClick(View view) {
dispatchTakePictureIntent();
}
同样如上所述,数据Intent仅在三星手机上为空。 关于相机或者permmisions,S5有什么不同吗? 我很乐意得到一些帮助,这对我来说非常重要。 提前谢谢。
答案 0 :(得分:0)
对我来说,整个问题是:
android:launchMode="singleInstance"
在AndroidManifest中。删除它解决了它。