Java Android ACTION_IMAGE_CAPTURE有时不调用ActivityResult
在我们的代码中,我们使用的getPhoto方法如下所示:Java Android ACTION_IMAGE_CAPTURE有时不调用ActivityResult,java,android,camera,android-camera,Java,Android,Camera,Android Camera,在我们的代码中,我们使用的getPhoto方法如下所示: public void getPhoto(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); captureFile = new File(getCaptureFilePath()); captureUri = Uri.fromFile(captureFile); intent.putExtra(MediaSt
public void getPhoto(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
captureFile = new File(getCaptureFilePath());
captureUri = Uri.fromFile(captureFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, captureUri);
startActivityForResult(intent, CAPTURE_IMAGE);
}
和onActivityResult:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.w(TAG, "Came");
if (resultCode == RESULT_OK) {
if (requestCode == CAPTURE_IMAGE) {
try {
captureFile = new File(getCaptureFilePath());
captureUri = Uri.fromFile(captureFile);
Bitmap scaledBitmap = decodeFileAndResize(captureFile);
saveResizedAndCompressedBitmap(scaledBitmap);
Bitmap rotatedBitmap = convertToRotatedBitmap(scaledBitmap);
driverPhoto.setImageBitmap(rotatedBitmap);
Log.w(TAG, "Before recycle");
if (rotatedBitmap != scaledBitmap) {
scaledBitmap.recycle();
scaledBitmap = null;
System.gc();
}
Log.w(TAG, "After recycle");
} catch (IOException e) {
BugSenseHandler.log(TAG, e);
}
}
}
}
有时,当我按下“Ok”键时,不会调用ActivityResult(come
not write)。我的代码有什么问题
编辑:
12-04 12:43:36.040:INFO/WindowManager(145):WIN DEATH:Window{4083990 com.skalar/com.skalar.activities.RegisterActivity paused=false}当未调用onActivityResult时,
出现在代码中。是否有可能您的活动被终止,这就是onActivityResult未被执行的原因?当相机意图返回时,通常会执行onActivityResult,然后执行onResume。在onPause和onResume方法中放入一条log语句,并检查执行顺序
I faced same problem , once check have you put any tag related to History ?
不要在清单中放置android:noHistory=“true”标记
如果在清单内的活动中使用android:noHistory=“true”,它将
停止后从堆栈中移除
注意:如果您使用的是tab活动,那么您也不应该使用android:noHistory=“true”
或者简单地将android:noHistory=“false”放在清单内的活动中
可能是我的解释错了,但我找到了解决办法。根据:
所以问题是
captureFile = new File(getCaptureFilePath());
intent.putExtra(MediaStore.EXTRA_OUTPUT, captureUri);
您可以通过将captureFile设置为此方法的返回值来解决此问题:
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File directory = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "your subdirectory for Picture directory");
if(!directory.exists() && !directory.mkdir())
return null;
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
directory /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
return image;
}
当摄像头显示(如预期)时,它暂停,然后调用WIN DEATH,然后调用Manifest中指定的my Starter Activity。查看stacktrace并查找导致WIN DEATH的代码将非常有用。看看这个有什么想法是的,它正在被杀死。现在如何克服它?请看
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File directory = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES), "your subdirectory for Picture directory");
if(!directory.exists() && !directory.mkdir())
return null;
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
directory /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
return image;
}