Я следовал официальным документам, чтобы выполнить намерение камеры в своем приложении. Он работает на устройствах 5.0+, но не в Jellybean.
В версиях от 4.1 (JB) до 4.4 (KK) родное приложение камеры показывает «К сожалению, ошибка остановки камеры» после захвата изображения. В моем приложении onActivityResult всегда возвращается результат RESULT.CANCEELLED. Что я делаю неправильно?
P.S. Намерение камеры работает правильно в JB, если я не использую файловый провайдер и не извлекаю uri с помощью Uri.fromFile(file).
Ниже приведен мой код
// MainActivity.java
File f = PhotoHelper.createImageFile(this);
photoPath = "file:" + f.getAbsolutePath();
Uri photoURI = FileProvider.getUriForFile(this, "com.myapp.fileprovider", f);
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, Constants.NEW_TOPIC_VIA_PHOTO);
// PhotoHelper.java
public static File createImageFile(Context context) throws IOException {
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
String imageFileName = JPEG_FILE_PREFIX + timeStamp + "_";
File storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
return File.createTempFile(imageFileName, JPEG_FILE_SUFFIX, storageDir);
}
// AndroidManifest.xml
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.myapp.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
// file_paths.xml
<paths>
<external-path
name="App_Images"
path="Android/data/com.myapp/files/Pictures"/>
</paths>