Special logic to try and guess mime types from things normally marked as octet streams

pull/14/head
Sam Bosley 13 years ago
parent 2645d542ad
commit b99454d07d

@ -863,4 +863,21 @@ public class AndroidUtilities {
}
}
/**
* Returns the final word characters after the last '.'
* @param file
* @return
*/
@SuppressWarnings("nls")
public static String getFileExtension(String file) {
int index = file.lastIndexOf('.');
String extension = "";
if (index > 0) {
extension = file.substring(index + 1);
if (!extension.matches("\\w+"))
extension = "";
}
return extension;
}
}

@ -20,6 +20,7 @@ import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.MimeTypeMap;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
@ -245,7 +246,20 @@ public class FilesControlSet extends PopupControlSet {
});
image.show();
} else {
showFromIntent(filePath, fileType);
String useType = fileType;
if (fileType.equals(FileMetadata.FILE_TYPE_OTHER)) {
String extension = AndroidUtilities.getFileExtension(filePath);
MimeTypeMap map = MimeTypeMap.getSingleton();
String guessedType = map.getMimeTypeFromExtension(extension);
if (!TextUtils.isEmpty(guessedType))
useType = guessedType;
if (useType != guessedType) {
m.setValue(FileMetadata.FILE_TYPE, useType);
metadataService.save(m);
}
}
showFromIntent(filePath, useType);
}
}
@ -260,7 +274,6 @@ public class FilesControlSet extends PopupControlSet {
}
private void handleActivityNotFound(String fileType) {
System.err.println("HANDLING FILE OF TYPE: " + fileType); //$NON-NLS-1$
if (fileType.startsWith(FileMetadata.FILE_TYPE_AUDIO)) {
searchMarket("com.clov4r.android.nil", R.string.search_market_audio_title, R.string.search_market_audio); //$NON-NLS-1$
} else if (fileType.equals(FileMetadata.FILE_TYPE_PDF)) {

@ -1059,10 +1059,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
String path = dst.getAbsolutePath();
String name = dst.getName();
String extension = "";
if (name.matches("\\w+.\\w+")) {
extension = name.substring(name.lastIndexOf('.') + 1);
}
String extension = AndroidUtilities.getFileExtension(name);
String type = FileMetadata.FILE_TYPE_OTHER;
if (!TextUtils.isEmpty(extension)) {

Loading…
Cancel
Save