Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-25849] Android: Always specify image mime-type #9918

Merged
merged 2 commits into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ public class MediaModule extends KrollModule implements Handler.Callback
private static String extension = ".jpg";
private TiTempFileHelper tempFileHelper;

private static final String MIME_IMAGE = "image/*";

private static class ApiLevel16
{
private ApiLevel16()
Expand Down Expand Up @@ -1002,7 +1004,7 @@ public void openPhotoGallery(KrollDict options)

TiIntentWrapper galleryIntent = new TiIntentWrapper(new Intent());
galleryIntent.getIntent().setAction(Intent.ACTION_GET_CONTENT);
galleryIntent.getIntent().setType("image/*");
galleryIntent.getIntent().setType(MIME_IMAGE);
galleryIntent.getIntent().addCategory(Intent.CATEGORY_DEFAULT);
galleryIntent.setWindowId(TiIntentWrapper.createActivityName("GALLERY"));

Expand Down Expand Up @@ -1111,6 +1113,7 @@ protected static KrollDict createDictForImage(String path)
{
String[] parts = { path };
TiBlob imageData;

// Workaround for TIMOB-19910. Image is in the Google Photos cloud and not on device.
if (path.startsWith("content://com.google.android.apps.photos.contentprovider")) {
ParcelFileDescriptor parcelFileDescriptor;
Expand Down Expand Up @@ -1190,7 +1193,7 @@ KrollDict createDictForImage(int width, int height, byte[] data)
cropRect.put("height", height);
d.put("cropRect", cropRect);
d.put("mediaType", mediaType);
d.put("media", TiBlob.blobFromData(data, "image/png"));
d.put("media", TiBlob.blobFromData(data, MIME_IMAGE));

return d;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ public String getNativePath()
return null;
}
if (this.type != TYPE_FILE) {
Log.w(TAG, "getNativePath not supported for non-file blob types.");
return null;
} else if (!(data instanceof TiBaseFile)) {
Log.w(TAG, "getNativePath unable to return value: underlying data is not file, rather "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

import java.util.HashMap;

import android.net.Uri;
import android.webkit.MimeTypeMap;

import org.appcelerator.titanium.TiApplication;

public class TiMimeTypeHelper
{
public static final String MIME_TYPE_JAVASCRIPT = "text/javascript";
Expand Down Expand Up @@ -54,6 +57,14 @@ public static String getFileExtensionFromUrl(String url)

public static String getMimeType(String url, String defaultType)
{
// attempt to obtain mime-type from content provider
if (url.startsWith("content://")) {
final String mimeType = TiApplication.getInstance().getContentResolver().getType(Uri.parse(url));
if (mimeType != null) {
return mimeType;
}
}

String extension = "";
int pos = url.lastIndexOf('.');
if (pos > 0) {
Expand Down