-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from tvbarthel/vb/fix-orientation-query
[Sample] Fix query orientation.
- Loading branch information
Showing
2 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
sample/src/main/java/fr/tvbarthel/intentsharesample/SharingFileProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package fr.tvbarthel.intentsharesample; | ||
|
||
import android.database.Cursor; | ||
import android.database.MatrixCursor; | ||
import android.net.Uri; | ||
import android.provider.MediaStore; | ||
import android.support.v4.content.FileProvider; | ||
|
||
/** | ||
* A simple {@link FileProvider} that solves a bug with the com.android.mms application. | ||
* <p/> | ||
* http://androidxref.com/5.1.1_r6/xref/packages/apps/Mms/src/com/android/mms/ui/UriImage.java#546 | ||
* <p/> | ||
* <p/> | ||
* When sharing an images with a content Uri, the com.android.mms application | ||
* tries to get the orientation of the image from the provider. | ||
* <p/> | ||
* This {@link FileProvider} is a very simple example that handle the query of {@link android.provider.MediaStore.Images.ImageColumns#ORIENTATION} | ||
* projection. | ||
* <p/> | ||
* <b>Note:</b> this {@link FileProvider} always returns '0' for the value of the orientation. | ||
* If your images do not have the same orientation, you should build your own logic. | ||
*/ | ||
public class SharingFileProvider extends FileProvider { | ||
|
||
@Override | ||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { | ||
if (isMediaStoreOrientationProjection(projection)) { | ||
return queryMediaStoreOrientation(); | ||
} | ||
|
||
return super.query(uri, projection, selection, selectionArgs, sortOrder); | ||
} | ||
|
||
/** | ||
* Check if a projection corresponds to a {@link android.provider.MediaStore.Images.ImageColumns#ORIENTATION} projection. | ||
* | ||
* @param projection the projection to check. | ||
* @return Returns true is the given projection corresponds to {@link android.provider.MediaStore.Images.ImageColumns#ORIENTATION}, false otherwise. | ||
*/ | ||
private boolean isMediaStoreOrientationProjection(String[] projection) { | ||
return projection != null && projection.length == 1 && MediaStore.Images.ImageColumns.ORIENTATION.equals(projection[0]); | ||
} | ||
|
||
/** | ||
* Query the {@link android.provider.MediaStore.Images.ImageColumns#ORIENTATION} | ||
* | ||
* @return Returns a {@link Cursor} with {@link android.provider.MediaStore.Images.ImageColumns#ORIENTATION} set to 0. | ||
*/ | ||
private Cursor queryMediaStoreOrientation() { | ||
String[] cols = new String[]{MediaStore.Images.ImageColumns.ORIENTATION}; | ||
Object[] values = new Object[]{0}; | ||
|
||
final MatrixCursor cursor = new MatrixCursor(cols, 1); | ||
cursor.addRow(values); | ||
return cursor; | ||
} | ||
} |