mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-04-24 15:56:07 +00:00
Try to guess the MIME type if SAF doesn't provide it
This fixes a crash that would occur if SAF doesn't provide a MIME type
This commit is contained in:
parent
b6093c2bfa
commit
e2ddc8a80f
1 changed files with 20 additions and 2 deletions
|
@ -16,6 +16,7 @@ import android.view.ViewGroup;
|
|||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.view.animation.Animation;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.ImageView;
|
||||
|
@ -553,8 +554,8 @@ public class EditEntryActivity extends AegisActivity {
|
|||
@Override
|
||||
protected void onActivityResult(int requestCode, final int resultCode, Intent data) {
|
||||
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
|
||||
DocumentFile file = DocumentFile.fromSingleUri(this, data.getData());
|
||||
if (file.getType().equals(IconType.SVG.toMimeType())) {
|
||||
String fileType = getMimeType(data.getData());
|
||||
if (fileType != null && fileType.equals(IconType.SVG.toMimeType())) {
|
||||
ImportFileTask.Params params = new ImportFileTask.Params(data.getData(), "icon", null);
|
||||
ImportFileTask task = new ImportFileTask(this, result -> {
|
||||
if (result.getException() == null) {
|
||||
|
@ -573,6 +574,23 @@ public class EditEntryActivity extends AegisActivity {
|
|||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
private String getMimeType(Uri uri) {
|
||||
DocumentFile file = DocumentFile.fromSingleUri(this, uri);
|
||||
if (file != null) {
|
||||
String fileType = file.getType();
|
||||
if (fileType != null) {
|
||||
return fileType;
|
||||
}
|
||||
|
||||
String ext = MimeTypeMap.getFileExtensionFromUrl(uri.toString());
|
||||
if (ext != null) {
|
||||
return MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private int parsePeriod() throws ParseException {
|
||||
try {
|
||||
return Integer.parseInt(_textPeriodCounter.getText().toString());
|
||||
|
|
Loading…
Add table
Reference in a new issue