From f4a33a007c777eaacd6d55048346b2a4be850ee5 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 20 Oct 2015 17:41:07 +0200 Subject: open unknown files with wildcard intent --- .../conversations/ui/ConversationFragment.java | 2 +- .../conversations/ui/adapter/MessageAdapter.java | 23 +++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src/main/java/eu/siacs/conversations') diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index b8a1a7a88..05d6e5ee3 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -541,7 +541,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); String mime = message.getMimeType(); if (mime == null) { - mime = "image/webp"; + mime = "*/*"; } shareIntent.setType(mime); } diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index a31adf187..d9fea8170 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -603,7 +603,7 @@ public class MessageAdapter extends ArrayAdapter { Toast.LENGTH_SHORT).show(); } } else if (message.treatAsDownloadable() != Message.Decision.NEVER) { - activity.xmppConnectionService.getHttpConnectionManager().createNewDownloadConnection(message,true); + activity.xmppConnectionService.getHttpConnectionManager().createNewDownloadConnection(message, true); } } @@ -614,16 +614,21 @@ public class MessageAdapter extends ArrayAdapter { return; } Intent openIntent = new Intent(Intent.ACTION_VIEW); - openIntent.setDataAndType(Uri.fromFile(file), file.getMimeType()); + String mime = file.getMimeType(); + if (mime == null) { + mime = "*/*"; + } + openIntent.setDataAndType(Uri.fromFile(file), mime); PackageManager manager = activity.getPackageManager(); List infos = manager.queryIntentActivities(openIntent, 0); - if (infos.size() > 0) { - try { - getContext().startActivity(openIntent); - return; - } catch (ActivityNotFoundException e) { - //ignored - } + if (infos.size() == 0) { + openIntent.setDataAndType(Uri.fromFile(file),"*/*"); + } + try { + getContext().startActivity(openIntent); + return; + } catch (ActivityNotFoundException e) { + //ignored } Toast.makeText(activity,R.string.no_application_found_to_open_file,Toast.LENGTH_SHORT).show(); } -- cgit v1.2.3