Я пытаюсь создать приложение для хранения, используя пример приложения для хранения Firebase, и когда я сделайте снимок, я всегда получаю RESUL_CANCELED в onActivityResult(..). Вот код:
@AfterPermissionGranted(RC_STORAGE_PERMS)
private void launchCamera() {
Log.d(LOG_TAG, "launchCamera");
// Check that we have permission to read images from external storage.
String perm = Manifest.permission.WRITE_EXTERNAL_STORAGE;
if (!EasyPermissions.hasPermissions(this, perm)) {
EasyPermissions.requestPermissions(this, getString(R.string.rationale_storage),
RC_STORAGE_PERMS, perm);
return;
}
// Choose file storage location, must be listed in res/xml/file_paths.xml
File externalDir = Environment.getExternalStorageDirectory();
File file = new File(externalDir, "photos/" + UUID.randomUUID().toString() + ".jpg");
// Create content:// URI for file, required since Android N
// See: https://developer.android.com/reference/android/support/v4/content/FileProvider.html
mFileUri = FileProvider.getUriForFile(this,
"com.google.firebase.quickstart.firebasestorage.fileprovider", file);
// Create and launch the intent
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mFileUri);
startActivityForResult(takePictureIntent, RC_TAKE_PICTURE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(LOG_TAG, "onActivityResult:" + requestCode + ":" + resultCode + ":" + data);
if (requestCode == RC_TAKE_PICTURE) {
if (resultCode == RESULT_OK) {
if (mFileUri != null) {
uploadFromUri(mFileUri);
} else {
Log.w(LOG_TAG, "File URI is null");
}
} else {
Toast.makeText(this, "Taking picture failed.", Toast.LENGTH_SHORT).show();
}
}
}
журналы: onActivityResult: 101: 0: Intent {}
ACTION_IMAGE_CAPTURE
реализации имеют историю ошибок. Кроме того, не забудьте поместитьmFileUri
в сохраненное состояние экземпляраBundle
, так как ваш процесс может быть завершен, пока приложение камеры находится на переднем плане. - person CommonsWare   schedule 10.07.2016