Wyświetlam wybór użytkownika, aby wybrać opcję Galeria lub Aparat, aby wybrać zdjęcie. Jeśli wybiorę opcję Aparat, to po załadowaniu aparatu wykonuję obrót, aby zrobić zdjęcie krajobrazu, zrobić zdjęcie i kliknąć Gotowe, aby wrócić do mojej aplikacji, ale zwracany obraz ma wartość zerową. Jeśli nie obrócę aparatu, obraz zostanie zwrócony prawidłowo. Czego mi brakuje? Wiem, że obrót powoduje przebudowę działania, ale dlaczego funkcja onActivityResult nie zawiera właściwych informacji? Oto moja openImage zamiar:Obraz z kamery ma wartość zerową, jeśli kamera jest obrócona
public void openImageIntent() {
// Determine Uri of camera image to save.
final File root = new File(Environment.getExternalStorageDirectory() + File.separator + "MyAppImages"
+ File.separator);
root.mkdirs();
SimpleDateFormat sdf = new SimpleDateFormat("ddMMyy-hhmmss");
final String fname = String.format("%s.jpg", sdf.format(new Date()));
final File sdImageMainDirectory = new File(root, fname);
outputFileUri = Uri.fromFile(sdImageMainDirectory);
// Camera.
final List<Intent> cameraIntents = new ArrayList<Intent>();
final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
final PackageManager packageManager = getPackageManager();
final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
for (ResolveInfo res : listCam) {
final String packageName = res.activityInfo.packageName;
final Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
intent.setPackage(packageName);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
cameraIntents.add(intent);
}
// Filesystem.
final Intent galleryIntent = new Intent();
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
// Chooser of filesystem options.
final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");
// Add the camera options.
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[] {}));
startActivityForResult(chooserIntent, SELECT_PICTURE_REQUEST);
}
A metoda onActivityResult:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE_REQUEST) {
final boolean isCamera;
if (data == null) {
isCamera = true;
} else {
final String action = data.getAction();
if (action == null) {
isCamera = false;
} else {
isCamera = true;
}
}
Uri selectedImageUri;
if (isCamera) {
selectedImageUri = outputFileUri;
} else {
selectedImageUri = data == null ? null : data.getData();
}
if (imageDelegate != null) {
Log.e(TAG, "imageDelegate not null: " + imageDelegate);
imageDelegate.gotNewImageUri(selectedImageUri);
imageDelegate = null;
} else if (getSupportFragmentManager().findFragmentByTag("addofferdialog") != null) {
imageDelegate = (AddOfferFragment) getSupportFragmentManager().findFragmentByTag("addofferdialog");
Log.e(TAG, "imageDelegate is null but found fragment: " + imageDelegate);
Log.e(TAG, "Activity image: " + selectedImageUri);
imageDelegate.gotNewImageUri(selectedImageUri);
imageDelegate = null;
} else {
Log.e(TAG, "cannot find imageDelegate!!!!");
}
Log.e(TAG, "selectedImageUri: " + selectedImageUri);
}
}
}
Wow, to było łatwe. Dzięki – Darren
Zaznacz to jako poprawną odpowiedź, jeśli działa :) – blganesh101
Musiałem czekać 10 minut, zanim mogłem. – Darren