I've already read a lot of posts, but none of them have a similar situation.
Context
The following code works fine for API 17 - 22, but not for API 23. The code below is inside the fragment.
private void takePicture() {
// identify if the device has camera to decide the next flow of action
PackageManager pm = mContext.getPackageManager();
if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
Toast.makeText(mContext, R.string.msgPleaseTakePicture2, Toast.LENGTH_LONG).show();
dispatchTakePictureIntent();
}else {
showErrorDialog(getString(R.string.msgErrorPicture));
}
}
private void dispatchTakePictureIntent() {
ContentValues values;
values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "Doarnf");
values.put(MediaStore.Images.Media.DESCRIPTION, "Doarnf");
imageUri = getActivity().getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
//on ActivityResult method
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
switch (requestCode)
{
case REQUEST_IMAGE_CAPTURE:
getPictureResults(resultCode, intent);
break;
}
}
private void getPictureResults(int resultCode, Intent intent) {
if (resultCode == Activity.RESULT_OK)
{
try {
mImageBitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), imageUri);
mImageBitmap = ImageHelper.scaleBitmapBasedOnHeight(mImageBitmap, 1296);
executeDonation();
} catch (Exception e) {
showErrorDialog(getString(R.string.msgErrorPicture));
}
}else {
showErrorDialog(getString(R.string.msgErrorPicture));
}
}
AndroidManifest.xml
<activity
android:name="br.com.cfb.doarnf.NavigationDrawerActivity"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/AppDrawer"
android:windowSoftInputMode="adjustPan"
android:screenOrientation="portrait">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="br.com.cfb.doarnf.MainActivity" />
</activity>
The Problem
The problem is:
Sometimes the onActivityResults is called back but the fragment variables are lost.
Sometimes the OnActivityResults is not called back. When the picture is taken the Android main screen shows up.
So I'm supposing that it is a bug from Android API 23.
Any idea?
Thank you in Advance.