aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java24
-rw-r--r--src/main/res/values/strings.xml1
2 files changed, 18 insertions, 7 deletions
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 bc706cda..6f536983 100644
--- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -11,6 +11,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
+import android.os.Build;
import android.support.v4.content.FileProvider;
import android.text.Spannable;
import android.text.SpannableString;
@@ -716,21 +717,30 @@ public class MessageAdapter extends ArrayAdapter<Message> {
if (mime == null) {
mime = "*/*";
}
- Uri uri = FileProvider.getUriForFile(activity,"eu.siacs.conversations.files",file);
+ Uri uri;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ try {
+ uri = FileProvider.getUriForFile(activity, "eu.siacs.conversations.files", file);
+ } catch (IllegalArgumentException e) {
+ Toast.makeText(activity,activity.getString(R.string.no_permission_to_access_x,file.getAbsolutePath()), Toast.LENGTH_SHORT).show();
+ return;
+ }
+ openIntent.setDataAndType(uri, mime);
+ openIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ } else {
+ uri = Uri.fromFile(file);
+ }
openIntent.setDataAndType(uri, mime);
- openIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
PackageManager manager = activity.getPackageManager();
- List<ResolveInfo> infos = manager.queryIntentActivities(openIntent, 0);
- if (infos.size() == 0) {
+ List<ResolveInfo> info = manager.queryIntentActivities(openIntent, 0);
+ if (info.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();
}
- Toast.makeText(activity,R.string.no_application_found_to_open_file,Toast.LENGTH_SHORT).show();
}
public void showLocation(Message message) {
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index c03efa16..13098716 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -679,4 +679,5 @@
<string name="me">Me</string>
<string name="contact_asks_for_presence_subscription">Contact asks for presence subscription</string>
<string name="allow">Allow</string>
+ <string name="no_permission_to_access_x">No permission to access %s</string>
</resources>