import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
+import android.provider.MediaStore;
import android.util.Log;
import android.widget.Toast;
"com.cyanogenmod.filemanager.category.EDITOR"; //$NON-NLS-1$
/**
+ * The package name of Gallery2.
+ */
+ public static final String GALLERY2_PACKAGE = "com.android.gallery3d";
+
+ /**
* Method that opens a {@link FileSystemObject} with the default registered application
* by the system, or ask the user for select a registered application.
*
}
intent.setAction(a);
} else {
- // Create a new stack for the activity
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ // Opening image files with Gallery2 will behave incorrectly when started
+ // as a new task. We want to be able to return to CMFM with the back button.
+ if (!(Intent.ACTION_VIEW.equals(intent.getAction())
+ && isGallery2(ri)
+ && intent.getData() != null
+ && MediaStore.AUTHORITY.equals(intent.getData().getAuthority()))) {
+ // Create a new stack for the activity
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ }
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
IntentsActionPolicy.CATEGORY_INTERNAL_VIEWER, false);
}
+ public static final boolean isGallery2(ResolveInfo ri) {
+ return GALLERY2_PACKAGE.equals(ri.activityInfo.packageName);
+ }
+
/**
* Method that retrieve the finds the preferred activity, if one exists. In case
* of multiple preferred activity exists the try to choose the better