카메라를 사용하는 앱을 쓰고 있습니다. 이상한 문제가 발생했습니다. "createImageFile()"API 16 가상 장치 내에서 파일을 성공적으로 만듭니다. 그러나 Sony Xperia Z3 (Android 6.0.1, API 23)에서 응용 프로그램을 실행할 때 파일이 만들어지지 않습니다. 나는 심지어 오류를 얻지 않는다. 나는 cameraChoosen()을 실행하는 버튼을 클릭하기 만하면 아무 일도 일어나지 않는다.사진이 작동하지 않는 경우 ImageFile 만들기
debbuging을 한 후 createImageFile()에 토스트 3 개를 만들었습니다.
모든 토스트 (16)
만 Toast1 내 엑스 페리아 Z3
public void cameraChoosen(){
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) {
Uri photoURI = FileProvider.getUriForFile(this, "com.example.karol.carendal", photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
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);
Toast.makeText(getBaseContext(), "Toast1", Toast.LENGTH_SHORT).show();
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
Toast.makeText(getBaseContext(), "Toast2", Toast.LENGTH_SHORT).show();
if (image.exists()){
Toast.makeText(getBaseContext(), "File created successfully", Toast.LENGTH_SHORT).show();
}
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
문제의 원인이 무엇인지 어떤 아이디어가 작동 가상 장치 API에 노력하고 있습니다?
감사합니다 :) 안드로이드 6
그 캐치 블록에도 건배를하십시오. 너는 그 붙잡음을 가지고있다. 예외는 logcat에도 표시됩니다. – greenapps
또한 캐치가 발생하면 토스트를 표시 할뿐만 아니라 리턴도 표시합니다. 그렇다면 코드를 계속 진행하는 것이 바람직하지 않습니다. 토스트에 e.getMessage를 표시합니다. – greenapps
File.createTempFile()을 사용하여 파일을 만들면 안되기 때문에 더 나쁜 코드입니다. 그것을 제거하십시오. 적합한 이미지 파일 경로 만 만들어야합니다. – greenapps